2525 - uses : pre-commit/action@v1.0.1
2626
2727 build-test-push :
28+ if : github.ref == 'refs/heads/master' || (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
3034 strategy :
3135 fail-fast : false
3236 matrix :
@@ -42,43 +46,49 @@ jobs:
4246 - " 10"
4347 - " 9.6"
4448 env :
49+ DOCKER_PLATFORM : linux/amd64,linux/arm64
4550 # Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4651 LATEST_RELEASE : " 18-alpine"
47- DOCKER_REPO : tecnativa/postgres-autoconf
48- DOCKER_TAG : ${{ matrix.pg_version }}-alpine
52+ DOCKER_REPO : " " # Set in the next step
53+ BASE_TAG : ${{ matrix.pg_version }}-alpine
54+ DOCKER_TAG : ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
4955 GIT_SHA1 : ${{ github.sha }}
50- IS_PR : ${{ github.event_name == 'pull_request' }}
56+ PG_VERSION : ${{ matrix.pg_version }}
57+ # Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
58+ DOCKERHUB_TOKEN : ${{ secrets.DOCKERHUB_TOKEN }}
59+ DOCKERHUB_LOGIN : ${{ secrets.DOCKERHUB_LOGIN }}
5160 steps :
61+ # Image repo names have to be lowercase.
62+ - name : Set image repository name
63+ run : |
64+ if [ "$GITHUB_REPOSITORY" = "Tecnativa/docker-postgres-autoconf" ]; then
65+ echo "DOCKER_REPO=tecnativa/postgres-autoconf" >> "$GITHUB_ENV"
66+ else
67+ echo "DOCKER_REPO=${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
68+ fi
5269 - uses : actions/checkout@v4
5370 - uses : actions/setup-python@v6
5471 - run : pip install -r tests/ci-requirements.txt
5572
73+ - name : Set up QEMU
74+ uses : docker/setup-qemu-action@v4
75+ - name : Set up Docker Buildx
76+ uses : docker/setup-buildx-action@v4
5677 # Build images
5778 - run : ./hooks/build
5879 # Test
5980 - run : python -m unittest tests.test -v
60- - name : Set Docker Tag
61- 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 }}
7081 # Push
7182 - 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))
83+ if : env.DOCKERHUB_TOKEN && env.DOCKERHUB_LOGIN
7384 env :
7485 REGISTRY_HOST : docker.io
75- REGISTRY_TOKEN : ${{ secrets .DOCKERHUB_TOKEN }}
76- REGISTRY_USERNAME : ${{ secrets .DOCKERHUB_LOGIN }}
86+ REGISTRY_TOKEN : ${{ env .DOCKERHUB_TOKEN }}
87+ REGISTRY_USERNAME : ${{ env .DOCKERHUB_LOGIN }}
7788 run : ./hooks/push
7889 - 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))
8090 env :
8191 REGISTRY_HOST : ghcr.io
82- REGISTRY_TOKEN : ${{ secrets.BOT_TOKEN }}
83- REGISTRY_USERNAME : ${{ secrets.BOT_LOGIN }}
92+ REGISTRY_TOKEN : ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}
93+ REGISTRY_USERNAME : ${{ secrets.BOT_LOGIN || github.repository_owner }}
8494 run : ./hooks/push
0 commit comments