|
1 | | -name: Tag and Release |
2 | | - |
3 | 1 | on: |
4 | 2 | push: |
5 | 3 | branches: |
6 | 4 | - main |
7 | 5 |
|
8 | 6 | jobs: |
9 | | - tag-and-release: |
| 7 | + release-on-push: |
10 | 8 | runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
11 | 11 |
|
12 | 12 | steps: |
13 | | - - name: Checkout code |
14 | | - uses: actions/checkout@v4 |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - id: release |
| 15 | + uses: rymndhng/release-on-push-action@master |
15 | 16 | with: |
16 | | - fetch-depth: 0 |
| 17 | + bump_version_scheme: minor |
| 18 | + tag_prefix: v |
17 | 19 |
|
18 | | - - name: Set up Git user |
19 | | - run: | |
20 | | - git config user.name "GitHub Actions" |
21 | | - git config user.email "actions@github.com" |
| 20 | + # Step 2: Generate Changelog using git-cliff-action |
| 21 | + - name: Generate Changelog with GitCliff |
| 22 | + uses: orhun/git-cliff-action@v1 |
| 23 | + with: |
| 24 | + args: "-o CHANGELOG.md" |
| 25 | + config: 'cliff.toml' |
| 26 | + env: |
| 27 | + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
22 | 28 |
|
23 | | - - name: Get latest tag |
24 | | - id: get_tag |
| 29 | + # Step 4: Check Output Parameters (optional, for debugging) |
| 30 | + - name: Check Output Parameters |
25 | 31 | run: | |
26 | | - latest_tag=$(git describe --tags --abbrev=0 || echo "v0.0.0") |
27 | | - echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT |
| 32 | + echo "Got tag name ${{ steps.release.outputs.tag_name }}" |
| 33 | + echo "Got release version ${{ steps.release.outputs.version }}" |
| 34 | + echo "Upload release artifacts to ${{ steps.release.outputs.upload_url }}" |
28 | 35 |
|
29 | | - - name: Bump version and create new tag |
30 | | - id: new_tag |
| 36 | + # Step 5: Set release body with changelog |
| 37 | + - name: Set release body with changelog |
| 38 | + id: release_body |
31 | 39 | run: | |
32 | | - latest="${{ steps.get_tag.outputs.latest_tag }}" |
33 | | - version="${latest#v}" |
34 | | - IFS='.' read -r major minor patch <<< "$version" |
35 | | - new_tag="v$major.$minor.$((patch + 1))" |
36 | | - git tag "$new_tag" |
37 | | - git push origin "$new_tag" |
38 | | - echo "new_tag=$new_tag" >> $GITHUB_OUTPUT |
39 | | -
|
40 | | - - name: Generate changelog with git-cliff |
41 | | - uses: orhun/git-cliff-action@v2 |
42 | | - with: |
43 | | - config: cliff.toml |
44 | | - args: -t ${{ steps.new_tag.outputs.new_tag }} -o CHANGELOG.md |
45 | | - |
46 | | - - name: Create GitHub Release |
| 40 | + ls -l # List files to check if CHANGELOG.md exists |
| 41 | + if [ -f CHANGELOG.md ]; then |
| 42 | + echo "CHANGELOG.md exists" |
| 43 | + echo "body<<EOF" >> $GITHUB_ENV |
| 44 | + cat CHANGELOG.md >> $GITHUB_ENV |
| 45 | + echo "EOF" >> $GITHUB_ENV |
| 46 | + else |
| 47 | + echo "CHANGELOG.md does not exist" |
| 48 | + echo "body=No changelog available" >> $GITHUB_ENV |
| 49 | + fi |
| 50 | +
|
| 51 | + # Step 6: Create GitHub Release with Changelog in Release Notes |
| 52 | + - name: Create Release |
47 | 53 | uses: softprops/action-gh-release@v1 |
48 | 54 | with: |
49 | | - tag_name: ${{ steps.new_tag.outputs.new_tag }} |
50 | | - name: Release ${{ steps.new_tag.outputs.new_tag }} |
51 | | - body_path: CHANGELOG.md |
| 55 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 56 | + files: ./artifacts/* |
| 57 | + body: ${{ steps.release_body.outputs.body }} |
52 | 58 | env: |
53 | 59 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |
0 commit comments