1+ name : Manual Release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : ' Release version (e.g., 1.0.0)'
8+ required : true
9+ type : string
10+ prerelease :
11+ description : ' Is this a pre-release?'
12+ required : false
13+ default : false
14+ type : boolean
15+ draft :
16+ description : ' Create as draft?'
17+ required : false
18+ default : false
19+ type : boolean
20+
21+ jobs :
22+ build-and-release :
23+ runs-on : ubuntu-latest
24+ permissions :
25+ contents : write
26+
27+ steps :
28+ - name : Checkout code
29+ uses : actions/checkout@v4
30+ with :
31+ fetch-depth : 0
32+
33+ - name : Setup JDK 8
34+ uses : actions/setup-java@v4
35+ with :
36+ java-version : ' 8'
37+ distribution : ' zulu'
38+
39+ - name : Setup Gradle
40+ uses : gradle/actions/setup-gradle@v3
41+
42+ - name : Build with Gradle
43+ run : ./gradlew shadowJar --no-daemon
44+
45+ - name : Get commit SHA
46+ id : commit
47+ run : echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
48+
49+ - name : Create Git tag
50+ run : |
51+ git config user.name "github-actions[bot]"
52+ git config user.email "github-actions[bot]@users.noreply.github.com"
53+ git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
54+ git push origin "v${{ inputs.version }}"
55+
56+ - name : Generate changelog
57+ id : changelog
58+ run : |
59+ # 获取上一个 tag
60+ PREV_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
61+
62+ if [ -z "$PREV_TAG" ]; then
63+ # 如果没有上一个 tag,获取所有提交
64+ CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges -20)
65+ else
66+ # 获取两个 tag 之间的提交
67+ CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges $PREV_TAG..HEAD)
68+ fi
69+
70+ # 保存到文件(多行内容)
71+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
72+ echo "$CHANGELOG" >> $GITHUB_OUTPUT
73+ echo "EOF" >> $GITHUB_OUTPUT
74+
75+ - name : Create Release
76+ uses : softprops/action-gh-release@v2
77+ with :
78+ tag_name : v${{ inputs.version }}
79+ name : Mcpatch v${{ inputs.version }}
80+ body : |
81+ ## Mcpatch v${{ inputs.version }}
82+
83+ **构建信息:**
84+ - 版本: ${{ inputs.version }}
85+ - 提交: ${{ steps.commit.outputs.sha }}
86+ - 构建时间: ${{ github.event.head_commit.timestamp }}
87+
88+ **更新内容:**
89+ ${{ steps.changelog.outputs.changelog }}
90+
91+ ---
92+
93+ **使用方法:**
94+ 下载 `Mcpatch-${{ inputs.version }}.jar` 文件,按照项目说明进行部署。
95+ files : build/libs/*.jar
96+ draft : ${{ inputs.draft }}
97+ prerelease : ${{ inputs.prerelease }}
98+ generate_release_notes : false
99+
100+ - name : Upload release artifact
101+ uses : actions/upload-artifact@v4
102+ with :
103+ name : Mcpatch-v${{ inputs.version }}
104+ path : build/libs/*.jar
105+ retention-days : 30
0 commit comments