diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml index 246de92a..c83b698c 100644 --- a/.github/workflows/docker-build-publish.yml +++ b/.github/workflows/docker-build-publish.yml @@ -231,29 +231,34 @@ jobs: echo "bump=$bump" >> $GITHUB_ENV echo "new_tag=$next_version" >> $GITHUB_ENV - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - booklore/booklore - ghcr.io/booklore-app/booklore - tags: | - type=sha,enable=${{ github.ref != github.event.repository.default_branch }} - type=raw,value={{branch}}-{{sha_short}},enable=${{ github.ref_name == 'develop' }} - type=raw,value=${{ env.new_tag }},enable=${{ github.ref_name == 'master' }} - type=raw,value=latest,enable=${{ github.ref_name == 'master' }} + - name: Generate Image Tag + id: set_image_tag + run: | + branch="${GITHUB_REF#refs/heads/}" + if [[ "$branch" == "master" ]]; then + image_tag="${{ env.new_tag }}" + elif [[ "$branch" == "develop" ]]; then + short_sha=$(git rev-parse --short HEAD) + image_tag="${{ env.latest_tag }}-develop-${short_sha}" + else + short_sha=$(git rev-parse --short HEAD) + image_tag="${short_sha}" + fi + echo "image_tag=$image_tag" >> $GITHUB_ENV + echo "Image tag: $image_tag" - name: Build and push Docker image + if: github.event_name == 'push' uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name == 'push' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + push: true + tags: | + booklore/booklore:${{ env.image_tag }} + ghcr.io/booklore-app/booklore:${{ env.image_tag }} build-args: | - APP_VERSION=${{ steps.meta.outputs.version }} + APP_VERSION=${{ env.image_tag }} APP_REVISION=${{ github.sha }} cache-from: | type=gha @@ -262,6 +267,21 @@ jobs: type=gha,mode=max type=registry,ref=ghcr.io/booklore-app/booklore:buildcache,mode=max + - name: Push Latest Tag (Master Only) + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + booklore/booklore:latest + ghcr.io/booklore-app/booklore:latest + build-args: | + APP_VERSION=${{ env.new_tag }} + APP_REVISION=${{ github.sha }} + cache-from: type=gha + - name: Update GitHub Release Draft (Master Only) if: github.ref == 'refs/heads/master' uses: release-drafter/release-drafter@v6