@@ -2,16 +2,19 @@ name: Build and Release
22
33on :
44 push :
5+ branches :
6+ - " rebuild-develop" # develop分支
7+ - " rebuild-release" # release 分支
58 tags :
6- - ' build*' # 当推送以 build:开头的 tag 时触发,比如 buildXXXX
9+ - ' build- *' # 打 tag 时跑 build + release
710 workflow_dispatch : # 允许手动触发
811
912jobs :
1013 build :
1114 runs-on : ubuntu-latest
1215
1316 steps :
14- - name : Checkout repository # 在 GitHub Actions 的虚拟机上,把仓库里的代码拉下来
17+ - name : Checkout repository
1518 uses : actions/checkout@v3
1619
1720 - name : Set up JDK 17
@@ -26,23 +29,39 @@ jobs:
2629 - name : Build with Gradle
2730 run : ./gradlew clean build
2831
29- - name : Upload build artifacts
30- uses : actions/upload-artifact@v3
32+ - name : Upload common jar
33+ uses : actions/upload-artifact@v4
3134 with :
32- name : my-build
33- path : ' **/build/libs/*.jar'
35+ name : Common
36+ path : Common/build/libs/*.jar
37+
38+ - name : Upload common api jar
39+ uses : actions/upload-artifact@v4
40+ with :
41+ name : CommonApi
42+ path : CommonApi/build/libs/*.jar
3443
3544 release :
36- needs : build # 这个 job 依赖于上一个 job build 完成。
45+ needs : build
3746 runs-on : ubuntu-latest
47+ if : startsWith(github.ref, 'refs/tags/build-') # 只有打 tag 才执行 release
3848 steps :
39- - name : Download build artifact # 把上一个 job 上传的构建产物下载到当前 job 的 runner 上。
40- uses : actions/download-artifact@v3
49+ # 下载 Common JAR
50+ - name : Download Common artifact
51+ uses : actions/download-artifact@v4
52+ with :
53+ name : Common
54+ path : ./build-artifacts/Common
55+
56+ # 下载 CommonApi JAR
57+ - name : Download CommonApi artifact
58+ uses : actions/download-artifact@v4
4159 with :
42- name : my-build
43- path : ./build-artifacts
60+ name : CommonApi
61+ path : ./build-artifacts/CommonApi
4462
45- - name : Create GitHub Release # 在 GitHub 上创建一个新的 Release(版本发布)
63+ # 创建 Release
64+ - name : Create GitHub Release
4665 id : create_release
4766 uses : softprops/action-gh-release@v1
4867 with :
5372 env :
5473 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5574
56- - name : Upload artifact to Release # 上传构建产物到 Release
57- uses : softprops/action-gh-release@v1
58- with :
59- files : ./build-artifacts/**/*.jar
75+ # 上传各子项目 JAR 到 Release
76+ - name : Upload jars to Release separately
77+ run : |
78+ for file in ./build-artifacts/**/*.jar; do
79+ echo "Uploading $file"
80+ gh release upload "${GITHUB_REF_NAME}" "$file" --repo "${GITHUB_REPOSITORY}" --clobber
81+ done
6082 env :
6183 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments