Skip to content

Commit 754b5f7

Browse files
Refactor manual .NET build workflow
Refactor manual .NET build workflow to improve matrix generation and artifact handling.
1 parent 4220b62 commit 754b5f7

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed
Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Manual .NET Build (Artifacts)
1+
name: Manual .NET Build
22

33
on:
44
workflow_dispatch:
55
inputs:
66
target_rids:
7-
description: 'Target RIDs (comma separated). E.g: linux-x64, win-x64, osx-arm64'
7+
description: 'Target RIDs (comma separated). E.g: linux-x64, win-x64'
88
required: true
99
default: 'linux-x64, win-x64'
1010
type: string
@@ -16,13 +16,13 @@ on:
1616
type: string
1717

1818
is_self_contained:
19-
description: 'Self Contained? (Includes .NET Runtime, larger size but no install required)'
19+
description: 'Self Contained?'
2020
required: true
2121
type: boolean
2222
default: true
2323

2424
is_single_file:
25-
description: 'Publish as Single File? (Cleaner output)'
25+
description: 'Publish as Single File?'
2626
required: true
2727
type: boolean
2828
default: false
@@ -32,11 +32,45 @@ env:
3232
DOTNET_VERSION: '10.0.x'
3333

3434
jobs:
35-
build-matrix:
35+
prepare-matrix:
3636
runs-on: ubuntu-latest
37-
permissions:
38-
contents: read
37+
outputs:
38+
matrix: ${{ steps.set-matrix.outputs.matrix }}
39+
steps:
40+
- id: set-matrix
41+
name: Generate Build Matrix
42+
shell: python
43+
run: |
44+
import json
45+
import os
46+
47+
rids_input = "${{ inputs.target_rids }}"
48+
configs_input = "${{ inputs.build_configs }}"
49+
50+
rids = [x.strip() for x in rids_input.split(',') if x.strip()]
51+
configs = [x.strip() for x in configs_input.split(',') if x.strip()]
52+
53+
include_list = []
54+
for r in rids:
55+
for c in configs:
56+
include_list.append({"rid": r, "config": c})
57+
58+
matrix_json = json.dumps({"include": include_list})
59+
60+
# 4. 输出到 GitHub Output
61+
print(f"Generated Matrix: {matrix_json}")
62+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
63+
f.write(f"matrix={matrix_json}")
3964
65+
build:
66+
needs: prepare-matrix
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
71+
72+
name: Build ${{ matrix.rid }} (${{ matrix.config }})
73+
4074
steps:
4175
- name: Checkout Release Branch
4276
uses: actions/checkout@v4
@@ -51,14 +85,8 @@ jobs:
5185
- name: Restore Dependencies
5286
run: dotnet restore ${{ env.PROJECT_PATH }}
5387

54-
# 核心逻辑:解析逗号分隔的输入,循环构建
55-
- name: Build and Publish Loop
56-
id: build_step
57-
shell: bash
88+
- name: Publish
5889
run: |
59-
IFS=',' read -ra RIDS <<< "${{ inputs.target_rids }}"
60-
IFS=',' read -ra CONFIGS <<< "${{ inputs.build_configs }}"
61-
6290
SELF_CONTAINED=""
6391
if [ "${{ inputs.is_self_contained }}" == "true" ]; then
6492
SELF_CONTAINED="--self-contained true"
@@ -71,39 +99,24 @@ jobs:
7199
SINGLE_FILE="-p:PublishSingleFile=true"
72100
fi
73101
74-
mkdir -p ./artifacts
102+
OUT_NAME="OpenBioCardServer-${{ matrix.rid }}-${{ matrix.config }}"
103+
OUT_DIR="./publish_output"
75104
76-
for rid in "${RIDS[@]}"; do
77-
rid=$(echo $rid | xargs)
78-
79-
for config in "${CONFIGS[@]}"; do
80-
config=$(echo $config | xargs)
81-
82-
echo "---------------------------------------------------"
83-
echo "🚀 Building for: RID=[$rid] | Config=[$config]"
84-
echo "---------------------------------------------------"
85-
86-
OUT_NAME="OpenBioCardServer-${rid}-${config}"
87-
OUT_DIR="./build_temp/${OUT_NAME}"
88-
89-
dotnet publish ${{ env.PROJECT_PATH }} \
90-
-c $config \
91-
-r $rid \
92-
$SELF_CONTAINED \
93-
$SINGLE_FILE \
94-
-o $OUT_DIR
95-
96-
cd ./build_temp
97-
zip -r "../artifacts/${OUT_NAME}.zip" "${OUT_NAME}"
98-
cd ..
99-
100-
echo "✅ Created: ./artifacts/${OUT_NAME}.zip"
101-
done
102-
done
105+
echo "🚀 Building: ${{ matrix.rid }} - ${{ matrix.config }}"
106+
107+
dotnet publish ${{ env.PROJECT_PATH }} \
108+
-c ${{ matrix.config }} \
109+
-r ${{ matrix.rid }} \
110+
$SELF_CONTAINED \
111+
$SINGLE_FILE \
112+
-o $OUT_DIR
103113
104-
- name: Upload Artifacts
114+
cd $OUT_DIR
115+
zip -r "../../${OUT_NAME}.zip" .
116+
117+
- name: Upload Artifact (Independent)
105118
uses: actions/upload-artifact@v4
106119
with:
107-
name: OpenBioCard-Builds
108-
path: ./artifacts/*.zip
120+
name: OpenBioCardServer-${{ matrix.rid }}-${{ matrix.config }}
121+
path: ./*.zip
109122
retention-days: 5

0 commit comments

Comments
 (0)