Skip to content

Commit 0788932

Browse files
committed
feat(ci): 支持通过workflow_dispatch自定义构建选项
- 添加workflow_dispatch触发方式,允许手动指定构建参数 - 支持通过输入参数选择启用的features(如sqlite-bundled,mysql-bundled等) - 支持选择目标平台(linux,windows,macos等)进行构建 - 添加build_cli和build_webapi布尔选项控制是否构建对应二进制文件 - 在各个构建步骤中集成FEATURES环境变量支持 - 根据build_cli和build_webapi选项控制CLI和WebAPI构件的上传 - 更新Android、Linux、Windows和macOS各平台构建逻辑以支持新特性 - 优化构建脚本以适应不同的feature组合和平台配置
1 parent f76fda6 commit 0788932

File tree

1 file changed

+113
-11
lines changed

1 file changed

+113
-11
lines changed

.github/workflows/rust.yml

Lines changed: 113 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ on:
66
tags: [ "v*" ]
77
pull_request:
88
branches: [ "main", "master", "rust_new" ]
9+
workflow_dispatch:
10+
inputs:
11+
features:
12+
description: 'Features to enable (comma-separated, e.g. sqlite-bundled,mysql-bundled,postgres-bundled,sqlite,mysql,postgres)'
13+
required: false
14+
default: 'sqlite-bundled'
15+
target_platforms:
16+
description: 'Target platforms to build (comma-separated, e.g. linux,windows,macos)'
17+
required: false
18+
default: 'linux,windows,macos'
19+
build_cli:
20+
description: 'Build CLI binary'
21+
type: boolean
22+
default: true
23+
build_webapi:
24+
description: 'Build WebAPI binary'
25+
type: boolean
26+
default: true
927

1028
env:
1129
CARGO_TERM_COLOR: always
@@ -140,32 +158,56 @@ jobs:
140158
run: |
141159
sudo apt-get update
142160
sudo apt-get install -y libsqlite3-dev
161+
- name: Prepare features
162+
run: |
163+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
164+
FEATURES="${{ github.event.inputs.features }}"
165+
else
166+
FEATURES="sqlite-bundled"
167+
fi
168+
echo "FEATURES=$FEATURES" >> $GITHUB_ENV
143169
- name: Build for Android
170+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
144171
run: |
145-
cargo build --target aarch64-linux-android --release --bin file_classification_cli --verbose
172+
if [ -n "$FEATURES" ]; then
173+
cargo build --target aarch64-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose
174+
else
175+
cargo build --target aarch64-linux-android --release --bin file_classification_cli --verbose
176+
fi
146177
- name: Build for other Android targets
178+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
147179
run: |
148-
cargo build --target armv7-linux-androideabi --release --bin file_classification_cli --verbose
149-
cargo build --target x86_64-linux-android --release --bin file_classification_cli --verbose
150-
cargo build --target i686-linux-android --release --bin file_classification_cli --verbose
180+
if [ -n "$FEATURES" ]; then
181+
cargo build --target armv7-linux-androideabi --release --bin file_classification_cli --features "$FEATURES" --verbose
182+
cargo build --target x86_64-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose
183+
cargo build --target i686-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose
184+
else
185+
cargo build --target armv7-linux-androideabi --release --bin file_classification_cli --verbose
186+
cargo build --target x86_64-linux-android --release --bin file_classification_cli --verbose
187+
cargo build --target i686-linux-android --release --bin file_classification_cli --verbose
188+
fi
151189
- name: Set Android binary name
152190
run: echo "ANDROID_BINARY_NAME=file_classification_cli" >> $GITHUB_ENV
153191
- name: Upload Android artifacts
192+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
154193
uses: actions/upload-artifact@v4
155194
with:
156195
name: file_classification_cli-android-aarch64
157196
path: target/aarch64-linux-android/release/file_classification_cli
158197
- name: Upload other Android artifacts
198+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
159199
uses: actions/upload-artifact@v4
160200
with:
161201
name: file_classification_cli-android-armv7
162202
path: target/armv7-linux-androideabi/release/file_classification_cli
163203
- name: Upload other Android artifacts
204+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
164205
uses: actions/upload-artifact@v4
165206
with:
166207
name: file_classification_cli-android-x86_64
167208
path: target/x86_64-linux-android/release/file_classification_cli
168209
- name: Upload other Android artifacts
210+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
169211
uses: actions/upload-artifact@v4
170212
with:
171213
name: file_classification_cli-android-i686
@@ -224,20 +266,40 @@ jobs:
224266
echo '' >> .cargo/config.toml
225267
echo '[target.riscv64gc-unknown-linux-gnu]' >> .cargo/config.toml
226268
echo 'linker = "riscv64-linux-gnu-gcc"' >> .cargo/config.toml
269+
- name: Prepare features
270+
run: |
271+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
272+
FEATURES="${{ github.event.inputs.features }}"
273+
else
274+
FEATURES="sqlite-bundled"
275+
fi
276+
echo "FEATURES=$FEATURES" >> $GITHUB_ENV
227277
- name: Build CLI release binary
278+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
228279
run: |
229-
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
280+
if [ -n "$FEATURES" ]; then
281+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "$FEATURES" --verbose
282+
else
283+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
284+
fi
230285
- name: Build WebAPI release binary
286+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
231287
run: |
232-
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
288+
if [ -n "$FEATURES" ]; then
289+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "$FEATURES" --verbose
290+
else
291+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
292+
fi
233293
- name: Set binary name
234294
run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV
235295
- name: Upload CLI artifacts
296+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
236297
uses: actions/upload-artifact@v4
237298
with:
238299
name: file_classification_cli-${{ matrix.target }}
239300
path: target/${{ matrix.target }}/release/file_classification_cli
240301
- name: Upload WebAPI artifacts
302+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
241303
uses: actions/upload-artifact@v4
242304
with:
243305
name: file_classification_webapi-${{ matrix.target }}
@@ -283,20 +345,40 @@ jobs:
283345
echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV
284346
echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\lib" >> $env:GITHUB_PATH
285347
echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" >> $env:GITHUB_PATH
348+
- name: Prepare features
349+
run: |
350+
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
351+
$env:FEATURES="${{ github.event.inputs.features }}"
352+
} else {
353+
$env:FEATURES="sqlite-bundled"
354+
}
355+
echo "FEATURES=$env:FEATURES" >> $env:GITHUB_ENV
286356
- name: Build CLI release binary
357+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
287358
run: |
288-
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
359+
if ( "${env:FEATURES}" -ne "" ) {
360+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "${env:FEATURES}" --verbose
361+
} else {
362+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
363+
}
289364
- name: Build WebAPI release binary
365+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
290366
run: |
291-
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
367+
if ( "${env:FEATURES}" -ne "" ) {
368+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "${env:FEATURES}" --verbose
369+
} else {
370+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
371+
}
292372
- name: Set binary name
293-
run: echo "BINARY_NAME=file_classification_cli.exe" >> $GITHUB_ENV
373+
run: echo "BINARY_NAME=file_classification_cli.exe" >> $env:GITHUB_ENV
294374
- name: Upload CLI artifacts
375+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
295376
uses: actions/upload-artifact@v4
296377
with:
297378
name: file_classification_cli-${{ matrix.target }}
298379
path: target/${{ matrix.target }}/release/file_classification_cli.exe
299380
- name: Upload WebAPI artifacts
381+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
300382
uses: actions/upload-artifact@v4
301383
with:
302384
name: file_classification_webapi-${{ matrix.target }}
@@ -330,20 +412,40 @@ jobs:
330412
- name: Install dependencies (macOS)
331413
run: |
332414
brew install sqlite3
415+
- name: Prepare features
416+
run: |
417+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
418+
FEATURES="${{ github.event.inputs.features }}"
419+
else
420+
FEATURES="sqlite-bundled"
421+
fi
422+
echo "FEATURES=$FEATURES" >> $GITHUB_ENV
333423
- name: Build CLI release binary
424+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
334425
run: |
335-
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
426+
if [ -n "$FEATURES" ]; then
427+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "$FEATURES" --verbose
428+
else
429+
cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose
430+
fi
336431
- name: Build WebAPI release binary
432+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
337433
run: |
338-
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
434+
if [ -n "$FEATURES" ]; then
435+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "$FEATURES" --verbose
436+
else
437+
cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose
438+
fi
339439
- name: Set binary name
340440
run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV
341441
- name: Upload CLI artifacts
442+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }}
342443
uses: actions/upload-artifact@v4
343444
with:
344445
name: file_classification_cli-${{ matrix.target }}
345446
path: target/${{ matrix.target }}/release/file_classification_cli
346447
- name: Upload WebAPI artifacts
448+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }}
347449
uses: actions/upload-artifact@v4
348450
with:
349451
name: file_classification_webapi-${{ matrix.target }}

0 commit comments

Comments
 (0)