11name : 构建CodeNothing库文件
22
33on :
4- # 默认只能手动触发,避免每次提交都构建
4+ # 手动触发
55 workflow_dispatch :
66 inputs :
77 libraries :
88 description : ' 要构建的库列表 (all 表示全部, 或用逗号分隔的名称列表如 io,example)'
99 required : true
1010 default : ' all'
11+ # 发布版本时自动触发
12+ release :
13+ types : [created]
14+ # 标签推送时自动触发
15+ push :
16+ tags :
17+ - ' v*'
1118
1219env :
1320 CARGO_TERM_COLOR : always
@@ -24,12 +31,13 @@ jobs:
2431 - id : set-matrix
2532 name : 准备库矩阵
2633 run : |
27- if [[ "${{ github.event.inputs.libraries }}" == "all" ]]; then
28- # 自动查找所有以library_开头的目录
29- LIBRARIES=$(find . -maxdepth 1 -type d -name "library_*" | sed 's|./library_||g' | jq -R . | jq -cs .)
30- else
34+ # 如果是手动触发并指定了库,则使用指定的库
35+ if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.libraries }}" != "all" ]]; then
3136 # 使用提供的库列表
3237 LIBRARIES=$(echo "${{ github.event.inputs.libraries }}" | tr ',' '\n' | jq -R . | jq -cs .)
38+ else
39+ # 否则构建所有库
40+ LIBRARIES=$(find . -maxdepth 1 -type d -name "library_*" | sed 's|./library_||g' | jq -R . | jq -cs .)
3341 fi
3442 echo "matrix=${LIBRARIES}" >> $GITHUB_OUTPUT
3543 shell : bash
@@ -146,10 +154,11 @@ jobs:
146154 path : ${{ matrix.library }}-${{ matrix.os }}.${{ matrix.archive_format }}
147155
148156 - name : 创建发布
149- if : steps.check_dir.outputs.exists == 'true' && startsWith(github.ref, 'refs/tags/')
157+ if : steps.check_dir.outputs.exists == 'true' && ( startsWith(github.ref, 'refs/tags/') || github.event_name == 'release ')
150158 uses : softprops/action-gh-release@v1
151159 with :
152160 files : ${{ matrix.library }}-${{ matrix.os }}.${{ matrix.archive_format }}
161+ tag_name : ${{ github.ref_name }}
153162 env :
154163 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
155164
@@ -158,7 +167,8 @@ jobs:
158167 name : 打包所有库
159168 needs : build
160169 runs-on : ${{ matrix.os }}
161- if : ${{ github.event.inputs.libraries == 'all' }}
170+ # 在手动触发并指定'all'或发布版本时打包所有库
171+ if : ${{ github.event.inputs.libraries == 'all' || github.event_name == 'release' || startsWith(github.ref, 'refs/tags/') }}
162172 strategy :
163173 matrix :
164174 os : [windows-latest, ubuntu-latest, macos-latest]
@@ -222,9 +232,10 @@ jobs:
222232 path : codenothing-all-libraries-${{ matrix.os }}.${{ matrix.archive_format }}
223233
224234 - name : 创建发布
225- if : startsWith(github.ref, 'refs/tags/')
235+ if : startsWith(github.ref, 'refs/tags/') || github.event_name == 'release'
226236 uses : softprops/action-gh-release@v1
227237 with :
228238 files : codenothing-all-libraries-${{ matrix.os }}.${{ matrix.archive_format }}
239+ tag_name : ${{ github.ref_name }}
229240 env :
230241 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments