Skip to content

Commit ead968a

Browse files
committed
Simplify taging logic to avoid repetition
1 parent b194110 commit ead968a

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ jobs:
4848
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4949
LATEST_RELEASE: "18-alpine"
5050
DOCKER_REPO: ${{ github.repository == 'Tecnativa/docker-postgres-autoconf' && 'tecnativa/postgres-autoconf' || github.repository }}
51-
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
51+
BASE_TAG: ${{ matrix.pg_version }}-alpine
52+
DOCKER_TAG: ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
5253
GIT_SHA1: ${{ github.sha }}
5354
PG_VERSION: ${{ matrix.pg_version }}
54-
IS_PR: ${{ github.event_name == 'pull_request' }}
5555
PUBLISH: ${{ github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
5656
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
5757
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -65,16 +65,6 @@ jobs:
6565
- run: ./hooks/build
6666
# Test
6767
- run: python -m unittest tests.test -v
68-
- name: Set Docker Tag
69-
run: |
70-
if [ "${{ env.IS_PR }}" = "true" ]; then
71-
echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV
72-
else
73-
echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
74-
fi
75-
- name: Tag Docker Image for PR
76-
if: env.IS_PR
77-
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
7868
- name: Set up QEMU
7969
if: env.PUBLISH
8070
uses: docker/setup-qemu-action@v4

hooks/build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from plumbum import FG, local
33
from plumbum.cmd import date, docker
44

55
# Check environment variables are present
6+
BASE_TAG = local.env["BASE_TAG"]
67
DOCKER_TAG = local.env["DOCKER_TAG"]
78
REPO = local.env["DOCKER_REPO"]
89
COMMIT = local.env.get("GIT_SHA1")
@@ -18,7 +19,7 @@ DATE = date("--rfc-3339", "ns")
1819
"--build-arg",
1920
"BUILD_DATE={}".format(DATE),
2021
"--build-arg",
21-
"BASE_TAG={}".format(DOCKER_TAG),
22+
"BASE_TAG={}".format(BASE_TAG),
2223
"--tag",
2324
"{}:{}".format(REPO, DOCKER_TAG),
2425
".",

0 commit comments

Comments
 (0)