@@ -13,20 +13,29 @@ jobs:
1313 pre-commit :
1414 runs-on : ubuntu-latest
1515 steps :
16- - uses : actions/checkout@v4
16+ - uses : actions/checkout@v6
1717 - uses : actions/setup-python@v6
1818 - name : Set PY
1919 run : |
2020 echo "PY=$(python -c 'import hashlib,sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
21- - uses : actions/cache@v4
21+ - uses : actions/cache@v5
2222 with :
2323 path : ~/.cache/pre-commit
2424 key : pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
2525 - uses : pre-commit/action@v1.0.1
2626
2727 build-test-push :
28+ 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)
2829 runs-on : ubuntu-latest
2930 needs : pre-commit
31+ permissions :
32+ contents : read
33+ packages : write
34+ services :
35+ registry :
36+ image : registry:3
37+ ports :
38+ - 5000:5000
3039 strategy :
3140 fail-fast : false
3241 matrix :
@@ -42,43 +51,55 @@ jobs:
4251 - " 10"
4352 - " 9.6"
4453 env :
54+ DOCKER_PLATFORM : linux/amd64,linux/arm64
55+ LOCAL_REGISTRY : localhost:5000
4556 # Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4657 LATEST_RELEASE : " 18-alpine"
47- DOCKER_REPO : tecnativa/postgres-autoconf
48- DOCKER_TAG : ${{ matrix.pg_version }}-alpine
58+ DOCKER_REPO : ${{ github.repository == 'Tecnativa/docker-postgres-autoconf' && 'tecnativa/postgres-autoconf' || github.repository }}
59+ BASE_TAG : ${{ matrix.pg_version }}-alpine
60+ DOCKER_TAG : ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
4961 GIT_SHA1 : ${{ github.sha }}
50- IS_PR : ${{ github.event_name == 'pull_request' }}
62+ # Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
63+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
64+ DOCKERHUB_LOGIN : ${{ secrets.DOCKERHUB_LOGIN }}
5165 steps :
52- - uses : actions/checkout@v4
66+ # Image repo names have to be lowercase.
67+ - name : Lowercase image repository name
68+ run : |
69+ DOCKER_REPO=${DOCKER_REPO,,}
70+ echo "DOCKER_REPO=$DOCKER_REPO" >> "$GITHUB_ENV"
71+ - uses : actions/checkout@v6
5372 - uses : actions/setup-python@v6
5473 - run : pip install -r tests/ci-requirements.txt
5574
75+ - name : Set up QEMU
76+ uses : docker/setup-qemu-action@v4
77+ - name : Set up Docker Buildx
78+ uses : docker/setup-buildx-action@v4
79+ with :
80+ driver-opts : network=host
5681 # Build images
57- - run : ./hooks/build
82+ - name : Build images
83+ run : ./hooks/build
5884 # Test
59- - run : python -m unittest tests.test -v
60- - name : Set Docker Tag
85+ - name : Test each platform
6186 run : |
62- if [ "${{ env.IS_PR }}" = "true" ]; then
63- echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV
64- else
65- echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
66- fi
67- - name : Tag Docker Image for PR
68- if : env.IS_PR
69- run : docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
87+ IFS=',' read -ra PLATFORMS <<< "$DOCKER_PLATFORM"
88+ for platform in "${PLATFORMS[@]}"; do
89+ echo "Testing platform: $platform"
90+ TEST_PLATFORM="$platform" python -m unittest tests.test -v
91+ done
7092 # Push
7193 - name : Push Docker Image to Docker Hub
72- if : github.repository == 'Tecnativa/docker-postgres-autoconf' && (github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
94+ if : env.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
7395 env :
7496 REGISTRY_HOST : docker.io
75- REGISTRY_TOKEN : ${{ secrets .DOCKERHUB_TOKEN }}
76- REGISTRY_USERNAME : ${{ secrets .DOCKERHUB_LOGIN }}
97+ REGISTRY_TOKEN : ${{ env .DOCKERHUB_TOKEN }}
98+ REGISTRY_USERNAME : ${{ env .DOCKERHUB_LOGIN }}
7799 run : ./hooks/push
78100 - name : Push Docker Image to GitHub Registry
79- if : github.repository == 'Tecnativa/docker-postgres-autoconf' && (github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
80101 env :
81102 REGISTRY_HOST : ghcr.io
82- REGISTRY_TOKEN : ${{ secrets.BOT_TOKEN }}
83- REGISTRY_USERNAME : ${{ secrets.BOT_LOGIN }}
103+ REGISTRY_TOKEN : ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
104+ REGISTRY_USERNAME : ${{ secrets.BOT_LOGIN || github.repository_owner }}
84105 run : ./hooks/push
0 commit comments