From 889646656f7bb78cd807cf9df7fd5e776e8d893e Mon Sep 17 00:00:00 2001 From: Dries Peeters Date: Tue, 26 Aug 2025 15:01:20 +0200 Subject: [PATCH] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index de2d8d4..a280c41 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -72,13 +72,30 @@ jobs: - name: Build and push Docker image run: | - # Build the image using our created Dockerfile - docker build -f Dockerfile.simple -t ghcr.io/drytrix/timetracker:main . + IMAGE_ID=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # Push if not a PR - if [ "${{ github.event_name }}" != "pull_request" ]; then - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin - docker push ghcr.io/drytrix/timetracker:main + # Strip "refs/tags/" prefix if it's a tag event + VERSION=${GITHUB_REF#refs/tags/} + + # Fallback: if it's not a tag, use branch name + if [ -z "$VERSION" ]; then + VERSION=${GITHUB_REF#refs/heads/} fi + + echo "Image ID: $IMAGE_ID" + echo "Version: $VERSION" + # Build the Docker image + docker build -f Dockerfile.simple -t $IMAGE_ID:$VERSION . + # Always push versioned tag on releases/tags + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo ${{ secrets.GITHUB_TOKEN }} | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin + docker push $IMAGE_ID:$VERSION + + # If this is a release, also push as latest + if [ "${{ github.event_name }}" == "release" ]; then + docker tag $IMAGE_ID:$VERSION $IMAGE_ID:latest + docker push $IMAGE_ID:latest + fi + fi