1
1
name : Auto Release
2
2
3
3
on :
4
+ workflow_dispatch :
5
+ inputs :
6
+ tag :
7
+ description : " Tag name for release (leave empty to use latest pushed tag)"
8
+ required : false
4
9
push :
5
10
tags :
6
- - " v*" # Listen to tags like v1.0.0
11
+ - " v*.*.*" # Match only version-like tags (e.g., v1.0.0, v2.1.3)
12
+
13
+ permissions :
14
+ contents : write # Required for GitHub release creation
7
15
8
16
jobs :
9
17
release :
@@ -12,16 +20,49 @@ jobs:
12
20
steps :
13
21
- name : Checkout repository
14
22
uses : actions/checkout@v4
23
+ with :
24
+ fetch-depth : 0 # Fetch full commit history and tags
25
+
26
+ - name : Determine Tag Name
27
+ id : get_tag
28
+ run : |
29
+ # If manually triggered, use the input tag; otherwise, use github.ref_name
30
+ if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.tag }}" ]]; then
31
+ TAG_NAME="${{ github.event.inputs.tag }}"
32
+ else
33
+ TAG_NAME="${{ github.ref_name }}"
34
+ fi
35
+
36
+ echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
37
+ echo "Resolved TAG_NAME: $TAG_NAME"
15
38
16
39
- name : Get Previous Tag
17
40
id : get_prev_tag
18
- run : echo "LAST_TAG=$(git describe --tags --abbrev=0 --exclude=${{ github.ref_name }})" >> $GITHUB_ENV
41
+ run : |
42
+ # Get the last tag before the new one, or empty if this is the first tag
43
+ LAST_TAG=$(git tag --sort=-creatordate | grep -v "$TAG_NAME" | head -n 1 || echo "")
44
+
45
+ # If no previous tag exists, use the root commit
46
+ if [[ -z "$LAST_TAG" ]]; then
47
+ LAST_TAG=$(git rev-list --max-parents=0 HEAD)
48
+ echo "First release detected, using root commit: $LAST_TAG"
49
+ fi
50
+
51
+ echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
52
+ echo "LAST_TAG=$LAST_TAG" >> $GITHUB_OUTPUT
53
+
54
+ - name : Skip Release if No Previous Tag
55
+ if : env.LAST_TAG == ''
56
+ run : |
57
+ echo "No previous tag found, skipping release..."
58
+ exit 0
19
59
20
60
- name : Generate GitHub Release
21
61
uses : softprops/action-gh-release@v2
62
+ if : startsWith(github.ref, 'refs/tags/') # Ensures release runs only on tag pushes
22
63
with :
23
- tag_name : ${{ github.ref_name }} # Tag Name
24
- name : ${{ github.ref_name }} # Release Name (same as Tag Name)
64
+ tag_name : ${{ env.TAG_NAME }} # Ensure correct tag name is used
65
+ name : ${{ env.TAG_NAME }} # Release Name
25
66
body : |
26
67
📢 **SuzuBlog new version released!** 🚀
27
68
新版本发布!请查看自动生成的 Release Notes 🔽
30
71
- Automatically generated Release Notes based on changes in this release.
31
72
32
73
## Full Changelog
33
- [View Full Changelog](https://github.com/ZL-Asica/SuzuBlog/compare/${{ github.event.before }}...${{ github.ref }})
74
+ [View Full Changelog](https://github.com/ZL-Asica/SuzuBlog/compare/${{ env.LAST_TAG }}...${{ env.TAG_NAME }})
34
75
35
76
## Contributors
36
77
🏆 Thank you to everyone who contributed to this release!
0 commit comments