Update docker-publish.yml

This commit is contained in:
Dries Peeters
2025-08-26 15:01:20 +02:00
committed by GitHub
parent 40315b745c
commit 889646656f

View File

@@ -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