From 77c45e7eaca38e9f0cdbe78c6eb49a74af1f38b6 Mon Sep 17 00:00:00 2001 From: Deploy Debbie Date: Thu, 19 Mar 2026 23:56:05 +0000 Subject: [PATCH] ci: add CalVer tagging to build-and-push workflow Tag container images with YYYY.MM.DD CalVer format on merge to main, with build number suffix for same-day collisions. Creates matching git tags (vYYYY.MM.DD). Retains latest tag as convenience alias. GitHub issue: cartsnitch/infra#24 Co-Authored-By: Paperclip --- .github/workflows/ci.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1667309..fcb6479 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true permissions: - contents: read + contents: write packages: write env: @@ -50,6 +50,25 @@ jobs: needs: [lint, test] steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate CalVer tag + id: calver + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: | + DATE_TAG=$(date -u +%Y.%m.%d) + EXISTING=$(git tag -l "v${DATE_TAG}*" | sort -V | tail -1) + if [ -z "$EXISTING" ]; then + VERSION="$DATE_TAG" + elif [ "$EXISTING" = "v${DATE_TAG}" ]; then + VERSION="${DATE_TAG}.2" + else + BUILD_NUM=$(echo "$EXISTING" | sed "s/v${DATE_TAG}\.//") + VERSION="${DATE_TAG}.$((BUILD_NUM + 1))" + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "CalVer tag: $VERSION" - name: Log in to GHCR if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -66,6 +85,7 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=sha,prefix=sha- + type=raw,value=${{ steps.calver.outputs.version }},enable=${{ github.ref == 'refs/heads/main' }} type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} - name: Build and push Docker image @@ -76,3 +96,9 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} target: prod + + - name: Create git tag + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: | + git tag "v${{ steps.calver.outputs.version }}" + git push origin "v${{ steps.calver.outputs.version }}"