Release #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| # Auto-create release when a tag is pushed manually | |
| push: | |
| tags: | |
| - 'v*' | |
| # Manual trigger from GitHub Actions UI | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: 'Version bump type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| jobs: | |
| # When triggered manually: calculate version, create tag, then release | |
| tag: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| name: Create Tag | |
| outputs: | |
| new_tag: ${{ steps.version.outputs.new_tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Calculate next version | |
| id: version | |
| run: | | |
| # Get the latest tag, default to v0.0.0 if none exists | |
| LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") | |
| echo "Latest tag: $LATEST_TAG" | |
| # Strip 'v' prefix and split into parts | |
| VERSION=${LATEST_TAG#v} | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" | |
| # Bump based on input | |
| case "${{ github.event.inputs.version_type }}" in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" | |
| echo "New tag: $NEW_TAG" | |
| echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Create and push tag | |
| run: | | |
| git tag ${{ steps.version.outputs.new_tag }} | |
| git push origin ${{ steps.version.outputs.new_tag }} | |
| release: | |
| runs-on: ubuntu-latest | |
| name: Create Release | |
| needs: [tag] | |
| # Run if: manual dispatch (after tag job) OR direct tag push | |
| if: always() && (needs.tag.result == 'success' || github.event_name == 'push') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.tag.outputs.new_tag || github.ref_name }} | |
| generate_release_notes: true |