Skip to content

Commit 0da1daf

Browse files
committed
Simplify taging logic to avoid repetition
1 parent 76945c3 commit 0da1daf

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
@@ -47,10 +47,10 @@ jobs:
4747
env:
4848
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4949
LATEST_RELEASE: "18-alpine"
50-
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
50+
BASE_TAG: ${{ matrix.pg_version }}-alpine
51+
DOCKER_TAG: ${{ github.event_name == 'pull_request' && format('{0}-test-pr{1}', matrix.pg_version, github.event.number) || format('{0}-alpine', matrix.pg_version) }}
5152
GIT_SHA1: ${{ github.sha }}
5253
PG_VERSION: ${{ matrix.pg_version }}
53-
IS_PR: ${{ github.event_name == 'pull_request' }}
5454
PUBLISH: ${{ github.ref == 'refs/heads/master' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
5555
# Github does not allow evaluating a secret in an if condition, so we need to set them as environment variables
5656
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -72,16 +72,6 @@ jobs:
7272
- run: ./hooks/build
7373
# Test
7474
- run: python -m unittest tests.test -v
75-
- name: Set Docker Tag
76-
run: |
77-
if [ "${{ env.IS_PR }}" = "true" ]; then
78-
echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV
79-
else
80-
echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
81-
fi
82-
- name: Tag Docker Image for PR
83-
if: env.IS_PR
84-
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
8575
- name: Set up QEMU
8676
if: env.PUBLISH
8777
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)