1414 matrix :
1515 os :
1616 - windows-latest
17- - ubuntu-latest
17+ - ubuntu-latest # target: x86_64-unknown-linux-musl
1818 - macos-latest
1919 file :
2020 - ${{ github.event.repository.name }}
2323 run :
2424 shell : bash
2525 env :
26- # 构建文件路径, Windows 平台有 .exe 后缀
27- NAME : ${{ format('target/release/{0}{1}', matrix.file, startsWith(matrix.os, 'windows') && '.exe' || '') }}
26+ # 不同构建目标对应的 release 目录
27+ TARGET : ${{ matrix.os == 'ubuntu-latest' && 'target/x86_64-unknown-linux-musl/release' || 'target/release' }}
28+ # 构建文件名, Windows 平台有 .exe 后缀
29+ NAME : ${{ format('{0}{1}', matrix.file, startsWith(matrix.os, 'windows') && '.exe' || '') }}
2830 # 上传制品文件名
2931 ARTIFACT_NAME : Binary-${{ matrix.file }}-${{ matrix.os }}
3032 steps :
@@ -42,38 +44,54 @@ jobs:
4244 ./target
4345 key : ${{ runner.os }}-${{ matrix.file }}-cache
4446
47+ - name : musl-tools
48+ if : matrix.os == 'ubuntu-latest'
49+ run : |
50+ sudo apt install -y musl-tools
51+
52+ - name : Rustup
53+ if : steps.cache.outputs.cache-hit != 'true' && matrix.os == 'ubuntu-latest'
54+ run : |
55+ rustup target add x86_64-unknown-linux-musl
56+
4557 - name : Build
4658 env :
4759 CARGO_TERM_COLOR : always
48- run : cargo build --release --verbose
60+ run : |
61+ cargo build --release --verbose \
62+ ${{ matrix.os == 'ubuntu-latest' && '--target x86_64-unknown-linux-musl' || '--' }}
4963
50- - name : Naming ${{ env.NEW_NAME }}
64+ - name : Naming ${{ env.NAMING }}
5165 id : naming
5266 env :
53- NEW_NAME : >-
54- ${{ format('target/release/{0}-{1}-{2}-{3}{4}',
55- matrix.file, github.ref_name, runner.os, runner.arch, startsWith(matrix.os, 'windows') && '.exe' || '') }}
67+ NAMING : >-
68+ ${{
69+ format('{0}-{1}-{2}-{3}{4}',
70+ matrix.file, github.ref_name, runner.os, runner.arch,
71+ startsWith(matrix.os, 'windows') && '.exe' || ''
72+ )
73+ }}
5674 run : |
57- export NAME ="$( echo ${{ env.NEW_NAME }} | tr [:upper:] [:lower:] )"
58- echo "FILENAME=$NAME " >> $GITHUB_OUTPUT
75+ export NAMING ="$( echo ${{ env.NAMING }} | tr [:upper:] [:lower:] )"
76+ echo "FILEPATH=$TARGET/$NAMING " >> $GITHUB_OUTPUT
5977
6078 - name : Rename file
6179 run : |
62- mv $ NAME ${{ steps.naming.outputs.FILENAME }}
80+ mv "$TARGET/$ NAME" ${{ steps.naming.outputs.FILEPATH }}
6381
6482 - name : Upload
6583 uses : actions/upload-artifact@master
6684 id : artifact-upload-step
6785 with :
6886 name : ${{ env.ARTIFACT_NAME }}
69- path : ${{ steps.naming.outputs.FILENAME }}
87+ path : ${{ steps.naming.outputs.FILEPATH }}
7088
7189 - name : GH Release on ${{ matrix.os }}
7290 uses : softprops/action-gh-release@v2.0.2
7391 if : startsWith(github.ref, 'refs/tags/')
7492 with :
7593 token : ${{ secrets.GITHUB_TOKEN }}
76- files : ${{ steps.naming.outputs.FILENAME }}
94+ files : ${{ steps.naming.outputs.FILEPATH }}
7795
7896 - name : Done
7997 if : startsWith(github.ref, 'refs/tags/')
0 commit comments