|
1 | 1 | name: Create Release |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_dispatch: |
| 4 | + workflow_dispatch: |
5 | 5 |
|
6 | 6 | permissions: |
7 | | - contents: write |
| 7 | + contents: write |
8 | 8 |
|
9 | 9 | jobs: |
10 | | - release: |
11 | | - runs-on: ubuntu-latest |
12 | | - if: github.ref == 'refs/heads/master' |
13 | | - |
14 | | - steps: |
15 | | - - name: Checkout code |
16 | | - uses: actions/checkout@v5 |
17 | | - |
18 | | - - name: Extract version and notes from CHANGELOG |
19 | | - id: changelog |
20 | | - run: | |
21 | | - # Extract version from first ## [x.x.x] header |
22 | | - VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md) |
23 | | - echo "version=$VERSION" >> $GITHUB_OUTPUT |
24 | | -
|
25 | | - # Extract release notes (content between first and second ## headers) |
26 | | - NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md) |
27 | | -
|
28 | | - # Handle multiline output |
29 | | - { |
30 | | - echo "notes<<EOF" |
31 | | - echo "$NOTES" |
32 | | - echo "EOF" |
33 | | - } >> $GITHUB_OUTPUT |
34 | | -
|
35 | | - - name: Check if tag already exists |
36 | | - id: check_tag |
37 | | - run: | |
38 | | - if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then |
39 | | - echo "exists=true" >> $GITHUB_OUTPUT |
40 | | - else |
41 | | - echo "exists=false" >> $GITHUB_OUTPUT |
42 | | - fi |
43 | | -
|
44 | | - - name: Create Release |
45 | | - if: steps.check_tag.outputs.exists == 'false' |
46 | | - uses: softprops/action-gh-release@v2 |
47 | | - with: |
48 | | - tag_name: ${{ steps.changelog.outputs.version }} |
49 | | - name: v${{ steps.changelog.outputs.version }} |
50 | | - body: ${{ steps.changelog.outputs.notes }} |
51 | | - draft: false |
52 | | - prerelease: false |
53 | | - |
54 | | - - name: Skip release (tag exists) |
55 | | - if: steps.check_tag.outputs.exists == 'true' |
56 | | - run: | |
57 | | - echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation." |
58 | | - exit 1 |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.ref == 'refs/heads/master' |
| 13 | + outputs: |
| 14 | + version: ${{ steps.changelog.outputs.version }} |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v5 |
| 19 | + |
| 20 | + - name: Extract version and notes from CHANGELOG |
| 21 | + id: changelog |
| 22 | + run: | |
| 23 | + # Extract version from first ## [x.x.x] header |
| 24 | + VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md) |
| 25 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + # Extract release notes (content between first and second ## headers) |
| 28 | + NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md) |
| 29 | +
|
| 30 | + # Handle multiline output |
| 31 | + { |
| 32 | + echo "notes<<EOF" |
| 33 | + echo "$NOTES" |
| 34 | + echo "EOF" |
| 35 | + } >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Check if tag already exists |
| 38 | + id: check_tag |
| 39 | + run: | |
| 40 | + if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then |
| 41 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Create Release |
| 47 | + if: steps.check_tag.outputs.exists == 'false' |
| 48 | + uses: softprops/action-gh-release@v2 |
| 49 | + with: |
| 50 | + tag_name: ${{ steps.changelog.outputs.version }} |
| 51 | + name: v${{ steps.changelog.outputs.version }} |
| 52 | + body: ${{ steps.changelog.outputs.notes }} |
| 53 | + draft: false |
| 54 | + prerelease: false |
| 55 | + |
| 56 | + - name: Skip release (tag exists) |
| 57 | + if: steps.check_tag.outputs.exists == 'true' |
| 58 | + run: | |
| 59 | + echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation." |
| 60 | + exit 1 |
| 61 | +
|
| 62 | + publish: |
| 63 | + needs: release |
| 64 | + uses: ./.github/workflows/publish.yml |
| 65 | + with: |
| 66 | + version: ${{ needs.release.outputs.version }} |
| 67 | + secrets: inherit |
0 commit comments