From 92598e05a20409c9820d3cdded8b635fa3f0f1b7 Mon Sep 17 00:00:00 2001 From: yusing Date: Thu, 22 Jan 2026 16:12:01 +0800 Subject: [PATCH] feat(ci): enhance Docker image workflow to compute version based on Git tags and branches - Added a step to checkout the repository for accurate tag resolution. - Implemented logic to determine the build version based on the Git reference type, supporting tags and branch names. - Updated the Docker build arguments to use the computed version for better versioning in images. --- .github/workflows/docker-image.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4c01b798..1b9c39ff 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -45,11 +45,28 @@ jobs: attestations: write steps: + - name: Checkout (for tag resolution) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Prepare run: | platform=${{ matrix.platform }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Compute VERSION for build + run: | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then + version="${GITHUB_REF_NAME}" + elif [ "${GITHUB_REF_NAME}" = "main" ] || [ "${GITHUB_REF_NAME}" = "compat" ]; then + git fetch --tags origin main + version="$(git describe --tags --abbrev=0 origin/main 2>/dev/null || git describe --tags --abbrev=0 main 2>/dev/null || echo v0.0.0)" + else + version="v$(date -u +'%Y%m%d-%H%M')" + fi + echo "VERSION_FOR_BUILD=$version" >> $GITHUB_ENV + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -86,7 +103,7 @@ jobs: type=registry,ref=${{ env.REGISTRY }}/${{ inputs.image_name }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max # type=gha,scope=${{ github.workflow }}-${{ env.PLATFORM_PAIR }},mode=max build-args: | - VERSION=${{ github.ref_name }} + VERSION=${{ env.VERSION_FOR_BUILD }} MAKE_ARGS=${{ env.MAKE_ARGS }} - name: Generate artifact attestation