From 9a63ff69e7d604167a34fdee27d78c7fa346a7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20M=C3=B6rling?= Date: Wed, 17 Jun 2026 15:00:27 +0200 Subject: [PATCH] Autofill deploy version from latest git tag instead of hardcoded v0.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deploy.yml workflow_dispatch input always defaulted to 'v0.1.0', requiring manual edit every time. Now the version defaults to 'auto', which fetches all tags, finds the latest v* tag via semver sort, bumps the patch component, and uses that as the deploy tag. Changes: - deploy.yml input: default changed to 'auto', required → false, description updated to explain both auto and manual modes - Added 'Resolve version' step: fetches tags, bumps latest semver tag by patch, validates output format, exports to $VERSION - 'Tag version' step: substituted ${{ github.event.inputs.version }} → ${{ env.VERSION }} to use the resolved/computed version - 'Print deploy status' step: same substitution - Semver validation guard rejects malformed tags (auto and manual) --- .forgejo/workflows/deploy.yml | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 4be9e8f..db3d51e 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -4,9 +4,9 @@ on: workflow_dispatch: inputs: version: - description: 'Git tag to create for this deploy (e.g. v0.1.2) — not the branch/tag above' - required: true - default: 'v0.1.0' + description: 'Leave as "auto" to bump from latest git tag, or enter a specific version (e.g. v0.1.2)' + required: false + default: 'auto' type: string jobs: @@ -21,12 +21,36 @@ jobs: git fetch --depth 1 origin ${GITHUB_SHA} git checkout FETCH_HEAD + - name: Resolve version + run: | + INPUT_VERSION="${{ github.event.inputs.version }}" + if [ -z "$INPUT_VERSION" ] || [ "$INPUT_VERSION" = "auto" ]; then + git fetch --tags origin + LATEST=$(git tag --list 'v*' --sort=-v:refname | head -1) + if [ -z "$LATEST" ]; then LATEST="v0.0.0"; fi + BASE="${LATEST#v}" + MAJOR=$(echo "$BASE" | cut -d. -f1) + MINOR=$(echo "$BASE" | cut -d. -f2) + PATCH=$(echo "$BASE" | cut -d. -f3) + PATCH=$(( ${PATCH:-0} + 1 )) + VERSION="v${MAJOR:-0}.${MINOR:-0}.${PATCH}" + echo "Latest tag: $LATEST → auto-bumped to $VERSION" + else + VERSION="$INPUT_VERSION" + echo "Using manual version: $VERSION" + fi + if ! echo "$VERSION" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "ERROR: resolved version '$VERSION' is not valid semver (expected vX.Y.Z)" + exit 1 + fi + echo "VERSION=$VERSION" >> "$GITHUB_ENV" + - name: Tag version run: | - git tag -d ${{ github.event.inputs.version }} 2>/dev/null || true - git push origin --delete ${{ github.event.inputs.version }} 2>/dev/null || true - git tag ${{ github.event.inputs.version }} - git push origin ${{ github.event.inputs.version }} + git tag -d ${{ env.VERSION }} 2>/dev/null || true + git push origin --delete ${{ env.VERSION }} 2>/dev/null || true + git tag ${{ env.VERSION }} + git push origin ${{ env.VERSION }} - name: Write production .env env: @@ -134,7 +158,7 @@ jobs: run: | echo "" echo "═══════════════════════════════════════════════════" - echo " Deployed ${{ github.event.inputs.version }} to production" + echo " Deployed ${{ env.VERSION }} to production" echo "═══════════════════════════════════════════════════" echo "" docker compose -p bilhej-prod -f docker-compose.prod.yml ps