Skip to content

Commit 76b2389

Browse files
Merge pull request #14 from hartmut-co-uk/github-actions-2
chore: cicd - clearer docker image tag names for master/prs
2 parents 45af551 + 0e7d141 commit 76b2389

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

.github/workflows/main.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
build-and-push:
6161
runs-on: ubuntu-latest
6262
needs: test
63-
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
63+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') || github.event_name == 'pull_request'
6464

6565
steps:
6666
- name: Checkout code
@@ -82,10 +82,16 @@ jobs:
8282
# For tags, use the tag name
8383
TAG=${GITHUB_REF#refs/tags/}
8484
echo "tags=hartmutcouk/pg-repack-docker:$TAG,hartmutcouk/pg-repack-docker:latest" >> $GITHUB_OUTPUT
85+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
86+
# For PRs, use PR number and short hash
87+
BRANCH_NAME="pr-${{ github.event.number }}"
88+
SHORT_HASH=$(echo ${{ github.sha }} | cut -c1-7)
89+
echo "tags=hartmutcouk/pg-repack-docker:${BRANCH_NAME}.${SHORT_HASH}" >> $GITHUB_OUTPUT
8590
else
86-
# For master/main branch, use snapshot with date
87-
DATE=$(date +%Y%m%d)
88-
echo "tags=hartmutcouk/pg-repack-docker:snapshot-$DATE" >> $GITHUB_OUTPUT
91+
# For master/main branch commits, normalize branch name and use short hash
92+
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]')
93+
SHORT_HASH=$(echo ${{ github.sha }} | cut -c1-7)
94+
echo "tags=hartmutcouk/pg-repack-docker:${BRANCH_NAME}.${SHORT_HASH}" >> $GITHUB_OUTPUT
8995
fi
9096
9197
- name: Build and push multi-platform image

0 commit comments

Comments
 (0)