ci: fix duplicate runs and combine fmt/clippy/test #4
Workflow file for this run
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: | ||
| push: | ||
| branches: | ||
| - main | ||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| # Only run if commit message matches release pattern | ||
| if: ${{ startsWith(github.event.head_commit.message, 'chore(release): prepare v') }} | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Extract version from commit message | ||
| id: version | ||
| run: | | ||
| # Extract version from commit message like "chore(release): prepare v0.1.0" | ||
| VERSION=$(echo "${{ github.event.head_commit.message }}" | grep -oP 'prepare v\K[0-9]+\.[0-9]+\.[0-9]+') | ||
| if [ -z "$VERSION" ]; then | ||
| echo "::error::Could not extract version from commit message" | ||
| exit 1 | ||
| fi | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Extracted version: $VERSION" | ||
| - name: Check if tag already exists | ||
| id: check_tag | ||
| run: | | ||
| if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then | ||
| echo "::error::Tag v${{ steps.version.outputs.version }} already exists" | ||
| exit 1 | ||
| fi | ||
| echo "Tag does not exist, proceeding..." | ||
| - name: Verify Cargo.toml version matches | ||
| run: | | ||
| CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') | ||
| if [ "$CARGO_VERSION" != "${{ steps.version.outputs.version }}" ]; then | ||
| echo "::error::Cargo.toml version ($CARGO_VERSION) does not match release version (${{ steps.version.outputs.version }})" | ||
| exit 1 | ||
| fi | ||
| echo "Cargo.toml version matches: $CARGO_VERSION" | ||
| - name: Extract release notes from CHANGELOG.md | ||
| id: changelog | ||
| run: | | ||
| VERSION="${{ steps.version.outputs.version }}" | ||
| # Extract the section for this version from CHANGELOG.md | ||
| # Matches from "## [X.Y.Z]" until the next "## [" or end of significant content | ||
| NOTES=$(awk -v ver="$VERSION" ' | ||
| /^## \[/ { | ||
| if (found) exit | ||
| if (index($0, "[" ver "]")) found=1 | ||
| next | ||
| } | ||
| found && /^## \[/ { exit } | ||
| found { print } | ||
| ' CHANGELOG.md) | ||
| if [ -z "$NOTES" ]; then | ||
| echo "::warning::No changelog entry found for version $VERSION" | ||
| NOTES="Release v$VERSION" | ||
| fi | ||
| # Write to file to preserve formatting | ||
| echo "$NOTES" > release_notes.md | ||
| echo "Release notes extracted:" | ||
| cat release_notes.md | ||
| - name: Create GitHub Release | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| gh release create "v${{ steps.version.outputs.version }}" \ | ||
| --title "v${{ steps.version.outputs.version }}" \ | ||
| --notes-file release_notes.md \ | ||
| --target "${{ github.sha }}" | ||
| echo "Created release v${{ steps.version.outputs.version }}" | ||