From 6fb415bfcb3fc2280b97ce41ae7cba9be43ce49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=85=8E=E9=A5=BC=E6=9E=9C=E5=AD=90=E5=8D=B7=E9=B2=A8?= =?UTF-8?q?=E9=B1=BC=E8=BE=A3=E6=A4=92?= Date: Mon, 30 Dec 2024 18:39:38 +0800 Subject: [PATCH] chore: enhance auto-tag workflow with version validation and error handling - Added error handling for git fetch command to ensure workflow fails on tag fetch issues. - Introduced a validation step to check the format of the new version tag, ensuring it adheres to semantic versioning. - Updated the conditional execution for the release job to prevent running if no new tag is generated, improving workflow reliability. --- .github/workflows/auto-tag.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 386e155..f2794fd 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -25,7 +25,8 @@ jobs: - name: Get latest tag id: get_latest_tag run: | - git fetch --tags + set -e + git fetch --tags || exit 1 latest_tag=$(git tag -l 'v*' --sort=-v:refname | head -n 1) if [ -z "$latest_tag" ]; then echo "version=v0.1.0" >> $GITHUB_OUTPUT @@ -37,6 +38,14 @@ jobs: echo "version=$major.$minor.$new_patch" >> $GITHUB_OUTPUT fi + - name: Validate version + run: | + new_tag=${{ steps.get_latest_tag.outputs.version }} + if [[ ! $new_tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid version format: $new_tag" + exit 1 + fi + - name: Create new tag env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} @@ -49,8 +58,10 @@ jobs: release: needs: auto-tag - if: success() - uses: ./.github/workflows/release.yml@${{ github.sha }} + if: | + success() && + needs.auto-tag.outputs.new_tag != '' + uses: ./.github/workflows/release.yml with: version: ${{ needs.auto-tag.outputs.new_tag }} secrets: inherit