forked from Tecnativa/docker-postgres-autoconf
-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (101 loc) · 3.56 KB
/
Copy pathci.yaml
File metadata and controls
105 lines (101 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: ci
on:
pull_request:
push:
branches:
- master
schedule:
# See https://crontab.guru/weekly
- cron: 0 0 * * 0
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- name: Set PY
run: |
echo "PY=$(python -c 'import hashlib,sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
- uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/action@v1.0.1
build-test-push:
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ubuntu-latest
needs: pre-commit
permissions:
contents: read
packages: write
services:
registry:
image: registry:3
ports:
- 5000:5000
strategy:
fail-fast: false
matrix:
pg_version:
- "18"
- "17"
- "16"
- "15"
- "14"
- "13"
- "12"
- "11"
- "10"
- "9.6"
env:
DOCKER_PLATFORM: linux/amd64,linux/arm64
LOCAL_REGISTRY: localhost:5000
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
LATEST_RELEASE: "18-alpine"
DOCKER_REPO: ${{ github.repository == 'Tecnativa/docker-postgres-autoconf' && 'tecnativa/postgres-autoconf' || github.repository }}
BASE_TAG: ${{ matrix.pg_version }}-alpine
DOCKER_TAG: ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
GIT_SHA1: ${{ github.sha }}
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DOCKERHUB_LOGIN: ${{ secrets.DOCKERHUB_LOGIN }}
steps:
# Image repo names have to be lowercase.
- name: Lowercase image repository name
run: |
DOCKER_REPO=${DOCKER_REPO,,}
echo "DOCKER_REPO=$DOCKER_REPO" >> "$GITHUB_ENV"
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
- run: pip install -r tests/ci-requirements.txt
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
driver-opts: network=host
# Build images
- name: Build images
run: ./hooks/build
# Test
- name: Test each platform
run: |
IFS=',' read -ra PLATFORMS <<< "$DOCKER_PLATFORM"
for platform in "${PLATFORMS[@]}"; do
echo "Testing platform: $platform"
TEST_PLATFORM="$platform" python -m unittest tests.test -v
done
# Push
- name: Push Docker Image to Docker Hub
if: env.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
env:
REGISTRY_HOST: docker.io
REGISTRY_TOKEN: ${{ env.DOCKERHUB_TOKEN }}
REGISTRY_USERNAME: ${{ env.DOCKERHUB_LOGIN }}
run: ./hooks/push
- name: Push Docker Image to GitHub Registry
env:
REGISTRY_HOST: ghcr.io
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
REGISTRY_USERNAME: ${{ secrets.BOT_LOGIN || github.repository_owner }}
run: ./hooks/push