|
1 | | -name: Tag After Merge |
| 1 | +name: Tag and Release After Merge |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: write |
2 | 5 |
|
3 | 6 | on: |
4 | 7 | push: |
5 | 8 | branches: |
6 | 9 | - main |
7 | 10 |
|
8 | 11 | jobs: |
9 | | - create-tag: |
| 12 | + create-tag-and-release: |
10 | 13 | runs-on: ubuntu-latest |
11 | 14 | steps: |
12 | 15 | - name: Checkout code |
|
22 | 25 | - name: Get last tag (if exists) |
23 | 26 | run: | |
24 | 27 | LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
25 | | - # strip leading "v" if present |
26 | 28 | LAST_TAG_STRIPPED=${LAST_TAG#v} |
27 | 29 | echo "last_tag=$LAST_TAG_STRIPPED" >> $GITHUB_ENV |
28 | 30 |
|
|
49 | 51 |
|
50 | 52 | - name: Skip if patch |
51 | 53 | if: env.release_type == 'patch' |
52 | | - run: echo "Patch release detected → no tag will be created." |
| 54 | + run: echo "Patch release detected → no tag or release will be created." |
53 | 55 |
|
54 | 56 | - name: Create and push git tag |
55 | 57 | if: env.release_type != 'patch' |
|
58 | 60 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
59 | 61 | git tag v${{ env.version }} |
60 | 62 | git push origin v${{ env.version }} |
| 63 | +
|
| 64 | + - name: Extract release notes from CHANGELOG |
| 65 | + if: env.release_type != 'patch' |
| 66 | + id: changelog |
| 67 | + run: | |
| 68 | + # Match lines starting with "## vX.Y.Z " until the next "## " |
| 69 | + awk "/^## v${{ env.version }}[[:space:]]/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md > RELEASE_NOTES.md |
| 70 | + |
| 71 | + echo "notes<<EOF" >> $GITHUB_ENV |
| 72 | + if [ "${{ env.release_type }}" = "major" ]; then |
| 73 | + echo "## 🚀 Major Release" >> $GITHUB_ENV |
| 74 | + elif [ "${{ env.release_type }}" = "minor" ]; then |
| 75 | + echo "## ✨ Minor Release" >> $GITHUB_ENV |
| 76 | + fi |
| 77 | + echo "" >> $GITHUB_ENV |
| 78 | + cat RELEASE_NOTES.md >> $GITHUB_ENV |
| 79 | + echo "EOF" >> $GITHUB_ENV |
| 80 | +
|
| 81 | + - name: Create GitHub Release |
| 82 | + if: env.release_type != 'patch' |
| 83 | + uses: softprops/action-gh-release@v2 |
| 84 | + with: |
| 85 | + tag_name: v${{ env.version }} |
| 86 | + name: "Release v${{ env.version }}" |
| 87 | + body: ${{ env.notes }} |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments