Browse Source

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.
pull/122/head v0.0.13
煎饼果子卷鲨鱼辣椒 5 months ago
parent
commit
6fb415bfcb
  1. 17
      .github/workflows/auto-tag.yml

17
.github/workflows/auto-tag.yml

@ -25,7 +25,8 @@ jobs:
- name: Get latest tag - name: Get latest tag
id: get_latest_tag id: get_latest_tag
run: | run: |
git fetch --tags
set -e
git fetch --tags || exit 1
latest_tag=$(git tag -l 'v*' --sort=-v:refname | head -n 1) latest_tag=$(git tag -l 'v*' --sort=-v:refname | head -n 1)
if [ -z "$latest_tag" ]; then if [ -z "$latest_tag" ]; then
echo "version=v0.1.0" >> $GITHUB_OUTPUT echo "version=v0.1.0" >> $GITHUB_OUTPUT
@ -37,6 +38,14 @@ jobs:
echo "version=$major.$minor.$new_patch" >> $GITHUB_OUTPUT echo "version=$major.$minor.$new_patch" >> $GITHUB_OUTPUT
fi 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 - name: Create new tag
env: env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
@ -49,8 +58,10 @@ jobs:
release: release:
needs: auto-tag 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: with:
version: ${{ needs.auto-tag.outputs.new_tag }} version: ${{ needs.auto-tag.outputs.new_tag }}
secrets: inherit secrets: inherit
Loading…
Cancel
Save