|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + actions: write |
7 | 12 |
|
8 | 13 | jobs: |
9 | 14 | release: |
| 15 | + name: Create Release |
10 | 16 | runs-on: ubuntu-latest |
11 | | - # Only run if commit message matches release pattern |
12 | | - if: ${{ startsWith(github.event.head_commit.message, 'chore(release): prepare v') }} |
13 | | - |
14 | | - permissions: |
15 | | - contents: write |
| 17 | + if: "${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.head_commit.message, 'chore(release): prepare v') }}" |
16 | 18 |
|
17 | 19 | steps: |
18 | 20 | - name: Checkout |
19 | 21 | uses: actions/checkout@v4 |
20 | | - with: |
21 | | - fetch-depth: 0 |
22 | 22 |
|
23 | | - - name: Extract version from commit message |
| 23 | + - name: Extract version |
24 | 24 | id: version |
25 | 25 | run: | |
26 | | - # Extract version from commit message like "chore(release): prepare v0.1.0" |
27 | | - VERSION=$(echo "${{ github.event.head_commit.message }}" | grep -oP 'prepare v\K[0-9]+\.[0-9]+\.[0-9]+') |
| 26 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 27 | + VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') |
| 28 | + else |
| 29 | + COMMIT_MSG="${{ github.event.head_commit.message }}" |
| 30 | + VERSION=$(echo "$COMMIT_MSG" | sed -n 's/.*prepare v\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p') |
| 31 | + fi |
28 | 32 | if [ -z "$VERSION" ]; then |
29 | | - echo "::error::Could not extract version from commit message" |
| 33 | + echo "Error: Could not determine version" |
30 | 34 | exit 1 |
31 | 35 | fi |
32 | 36 | echo "version=$VERSION" >> $GITHUB_OUTPUT |
33 | 37 | echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
34 | | - echo "Extracted version: $VERSION" |
35 | | -
|
36 | | - - name: Check if tag already exists |
37 | | - id: check_tag |
38 | | - run: | |
39 | | - if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
40 | | - echo "::error::Tag v${{ steps.version.outputs.version }} already exists" |
41 | | - exit 1 |
42 | | - fi |
43 | | - echo "Tag does not exist, proceeding..." |
44 | 38 |
|
45 | | - - name: Verify Cargo.toml version matches |
| 39 | + - name: Verify version matches Cargo.toml |
46 | 40 | run: | |
47 | | - CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
48 | | - if [ "$CARGO_VERSION" != "${{ steps.version.outputs.version }}" ]; then |
49 | | - echo "::error::Cargo.toml version ($CARGO_VERSION) does not match release version (${{ steps.version.outputs.version }})" |
| 41 | + CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') |
| 42 | + if [ "${{ steps.version.outputs.version }}" != "$CARGO_VERSION" ]; then |
| 43 | + echo "Error: Commit version does not match Cargo.toml version" |
50 | 44 | exit 1 |
51 | 45 | fi |
52 | | - echo "Cargo.toml version matches: $CARGO_VERSION" |
53 | 46 |
|
54 | | - - name: Extract release notes from CHANGELOG.md |
| 47 | + - name: Extract release notes from CHANGELOG |
55 | 48 | id: changelog |
56 | 49 | run: | |
57 | 50 | VERSION="${{ steps.version.outputs.version }}" |
58 | | -
|
59 | | - # Extract the section for this version from CHANGELOG.md |
60 | | - # Matches from "## [X.Y.Z]" until the next "## [" or end of significant content |
61 | | - NOTES=$(awk -v ver="$VERSION" ' |
62 | | - /^## \[/ { |
63 | | - if (found) exit |
64 | | - if (index($0, "[" ver "]")) found=1 |
65 | | - next |
66 | | - } |
67 | | - found && /^## \[/ { exit } |
68 | | - found { print } |
69 | | - ' CHANGELOG.md) |
70 | | -
|
71 | | - if [ -z "$NOTES" ]; then |
72 | | - echo "::warning::No changelog entry found for version $VERSION" |
73 | | - NOTES="Release v$VERSION" |
74 | | - fi |
75 | | -
|
76 | | - # Write to file to preserve formatting |
| 51 | + NOTES=$(awk "/^## \[$VERSION\]/{found=1; next} /^## \[/{if(found) exit} found{print}" CHANGELOG.md) |
77 | 52 | echo "$NOTES" > release_notes.md |
78 | | - echo "Release notes extracted:" |
79 | | - cat release_notes.md |
80 | 53 |
|
81 | 54 | - name: Create GitHub Release |
| 55 | + uses: softprops/action-gh-release@v2 |
| 56 | + with: |
| 57 | + tag_name: ${{ steps.version.outputs.tag }} |
| 58 | + name: Release ${{ steps.version.outputs.tag }} |
| 59 | + body_path: release_notes.md |
| 60 | + draft: false |
| 61 | + prerelease: false |
| 62 | + |
| 63 | + - name: Trigger publish workflow |
| 64 | + run: gh workflow run publish.yml |
82 | 65 | env: |
83 | 66 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
84 | | - run: | |
85 | | - gh release create "v${{ steps.version.outputs.version }}" \ |
86 | | - --title "v${{ steps.version.outputs.version }}" \ |
87 | | - --notes-file release_notes.md \ |
88 | | - --target "${{ github.sha }}" |
89 | | -
|
90 | | - echo "Created release v${{ steps.version.outputs.version }}" |
0 commit comments