chore: add conditional execution logic to Docker build workflow jobs and improve tagging logic for better handling of version tags

This commit is contained in:
Anish Sarkar 2026-03-05 13:55:05 +05:30
parent 1b2ac1bd17
commit 110502609b

View file

@ -26,6 +26,7 @@ permissions:
jobs: jobs:
tag_release: tag_release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'workflow_dispatch'
outputs: outputs:
new_tag: ${{ steps.tag_version.outputs.next_version }} new_tag: ${{ steps.tag_version.outputs.next_version }}
steps: steps:
@ -86,6 +87,7 @@ jobs:
build: build:
needs: tag_release needs: tag_release
if: always() && (needs.tag_release.result == 'success' || needs.tag_release.result == 'skipped')
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
permissions: permissions:
packages: write packages: write
@ -183,6 +185,7 @@ jobs:
create_manifest: create_manifest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [tag_release, build] needs: [tag_release, build]
if: always() && needs.build.result == 'success'
permissions: permissions:
packages: write packages: write
contents: read contents: read
@ -228,7 +231,11 @@ jobs:
id: appver id: appver
run: | run: |
VERSION_TAG="${{ needs.tag_release.outputs.new_tag }}" VERSION_TAG="${{ needs.tag_release.outputs.new_tag }}"
APP_VERSION=$(echo "$VERSION_TAG" | rev | cut -d. -f2- | rev) if [ -n "$VERSION_TAG" ]; then
APP_VERSION=$(echo "$VERSION_TAG" | rev | cut -d. -f2- | rev)
else
APP_VERSION=""
fi
echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT
- name: Docker meta - name: Docker meta
@ -237,9 +244,10 @@ jobs:
with: with:
images: ${{ steps.image.outputs.name }} images: ${{ steps.image.outputs.name }}
tags: | tags: |
type=raw,value=${{ needs.tag_release.outputs.new_tag }} type=raw,value=${{ needs.tag_release.outputs.new_tag }},enable=${{ needs.tag_release.outputs.new_tag != '' }}
type=raw,value=${{ steps.appver.outputs.app_version }},enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch }} type=raw,value=${{ steps.appver.outputs.app_version }},enable=${{ needs.tag_release.outputs.new_tag != '' && (github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch) }}
type=ref,event=branch type=ref,event=branch
type=sha,prefix=git-
flavor: | flavor: |
latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch }} latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event.inputs.branch == github.event.repository.default_branch }}
@ -249,7 +257,6 @@ jobs:
docker buildx imagetools create \ docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ steps.image.outputs.name }}@sha256:%s ' *) $(printf '${{ steps.image.outputs.name }}@sha256:%s ' *)
- name: Inspect image - name: Inspect image
run: | run: |
docker buildx imagetools inspect ${{ steps.image.outputs.name }}:${{ steps.meta.outputs.version }} docker buildx imagetools inspect ${{ steps.image.outputs.name }}:${{ steps.meta.outputs.version }}