Refactor release workflow to improve tag validation and output

- Enhanced the release workflow to validate tag formats more robustly, ensuring compliance with semantic versioning.
- Added detailed error messages and guidance for users on creating valid tags.
- Updated the workflow to use a validated tag for release creation and announcements, improving consistency and clarity in the release process.
This commit is contained in:
scawful
2025-09-26 22:24:19 -04:00
parent 1743859d0a
commit d2470a9ed2

View File

@@ -21,22 +21,52 @@ jobs:
name: Create Release
runs-on: ubuntu-latest
outputs:
tag_name: ${{ github.ref_name || github.event.inputs.tag }}
tag_name: ${{ env.VALIDATED_TAG }}
steps:
- name: Validate tag format
run: |
TAG="${{ github.ref_name || github.event.inputs.tag }}"
# Debug information
echo "Event name: ${{ github.event_name }}"
echo "Ref: ${{ github.ref }}"
echo "Ref name: ${{ github.ref_name }}"
echo "Ref type: ${{ github.ref_type }}"
# Determine the tag based on trigger type
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref_type }}" != "tag" ]]; then
echo "❌ Error: Release workflow triggered by push to ${{ github.ref_type }} '${{ github.ref_name }}'"
echo "This workflow should only be triggered by pushing version tags (v1.2.3)"
echo "Use: git tag v0.3.0 && git push origin v0.3.0"
exit 1
fi
TAG="${{ github.ref_name }}"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="${{ github.event.inputs.tag }}"
if [[ -z "$TAG" ]]; then
echo "❌ Error: No tag specified for manual workflow dispatch"
exit 1
fi
else
echo "❌ Error: Unsupported event type: ${{ github.event_name }}"
exit 1
fi
echo "Validating tag: $TAG"
# Check if tag follows semantic versioning pattern
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
echo "❌ Error: Tag '$TAG' does not follow semantic versioning format (v1.2.3 or v1.2.3-beta)"
echo "Valid examples: v0.3.0, v1.0.0, v2.1.3-beta, v1.0.0-rc1"
echo ""
echo "To create a proper release:"
echo "1. Use the helper script: ./scripts/create_release.sh 0.3.0"
echo "2. Or manually: git tag v0.3.0 && git push origin v0.3.0"
exit 1
fi
echo "✅ Tag format is valid: $TAG"
echo "VALIDATED_TAG=$TAG" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v4
@@ -46,8 +76,8 @@ jobs:
- name: Generate release notes
id: release_notes
run: |
# Extract release version from tag
VERSION="${{ github.ref_name || github.event.inputs.tag }}"
# Extract release version from validated tag
VERSION="${VALIDATED_TAG}"
VERSION_NUM=$(echo "$VERSION" | sed 's/^v//')
# Generate release notes using the dedicated script
@@ -67,11 +97,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name || github.event.inputs.tag }}
name: Yaze ${{ github.ref_name || github.event.inputs.tag }}
tag_name: ${{ env.VALIDATED_TAG }}
name: Yaze ${{ env.VALIDATED_TAG }}
body_path: release_notes.md
draft: false
prerelease: ${{ contains(github.ref_name || github.event.inputs.tag, 'beta') || contains(github.ref_name || github.event.inputs.tag, 'alpha') || contains(github.ref_name || github.event.inputs.tag, 'rc') }}
prerelease: ${{ contains(env.VALIDATED_TAG, 'beta') || contains(env.VALIDATED_TAG, 'alpha') || contains(env.VALIDATED_TAG, 'rc') }}
generate_release_notes: true
build-release:
@@ -129,7 +159,7 @@ jobs:
cp LICENSE dmg_staging/
cp README.md dmg_staging/
cp -r docs dmg_staging/
hdiutil create -srcfolder dmg_staging -format UDZO -volname "Yaze ${{ github.ref_name || github.event.inputs.tag }}" yaze-macos.dmg
hdiutil create -srcfolder dmg_staging -format UDZO -volname "Yaze ${{ needs.create-release.outputs.tag_name }}" yaze-macos.dmg
- name: "Linux x64"
os: ubuntu-22.04
@@ -234,7 +264,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name || github.event.inputs.tag }}
tag_name: ${{ needs.create-release.outputs.tag_name }}
files: |
${{ matrix.artifact_name }}.*
@@ -252,6 +282,6 @@ jobs:
- name: Announce release
run: |
echo "🎉 Yaze ${{ github.ref_name || github.event.inputs.tag }} has been released!"
echo "🎉 Yaze ${{ needs.create-release.outputs.tag_name }} has been released!"
echo "📦 Packages are now available for download"
echo "🔗 Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name || github.event.inputs.tag }}"
echo "🔗 Release URL: https://github.com/${{ github.repository }}/releases/tag/${{ needs.create-release.outputs.tag_name }}"