1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - " v*.*.*"
7+ workflow_dispatch : {}
8+
9+ jobs :
10+ # 创建 Github Releases
11+ create-release :
12+ if : startsWith(github.ref, 'refs/tags/')
13+ runs-on : ubuntu-latest
14+ steps :
15+ - uses : actions/checkout@v4
16+ # https://github.com/taiki-e/create-gh-release-action
17+ - uses : taiki-e/create-gh-release-action@v1
18+ with :
19+ # (optional) Path to changelog.
20+ # changelog: CHANGELOG.md
21+ # (required) GitHub token for creating GitHub Releases.
22+ token : ${{ secrets.GITHUB_TOKEN }}
23+
24+ # 自动构建跨平台 Rust 二进制文件并上传到 GitHub Release
25+ upload-assets :
26+ needs : create-release
27+ runs-on : ${{ matrix.os }}
28+ strategy :
29+ fail-fast : false
30+ matrix :
31+ include :
32+ # 非本机三元组, 由 corss 通过容器提供交叉编译支持: https://github.com/cross-rs/cross?#supported-targets
33+ # cross 具有与 Cargo 完全相同的 CLI, 但依赖于 Docker 或 Podman
34+ - target : x86_64-unknown-linux-musl
35+ os : ubuntu-latest
36+ - target : aarch64-unknown-linux-musl
37+ os : ubuntu-latest
38+ # 本机三元组, cargo 直接编译
39+ - target : aarch64-apple-darwin
40+ os : macos-latest
41+ - target : x86_64-pc-windows-msvc
42+ os : windows-latest
43+ steps :
44+ - uses : actions/checkout@v4
45+
46+ # 安装交叉编译工具链: https://github.com/taiki-e/setup-cross-toolchain-action
47+ # 如果安装 target 对应的工具链, 则下一步不会再安装并调用 cross 创建容器来编译, 可大幅缩短构建时间
48+ - name : Install cross-compilation tools
49+ continue-on-error : true
50+ uses : taiki-e/setup-cross-toolchain-action@v1
51+ with :
52+ target : ${{ matrix.target }}
53+
54+ # 构建并发布 Rust 程序: https://github.com/taiki-e/upload-rust-binary-action
55+ - uses : taiki-e/upload-rust-binary-action@v1
56+ with :
57+ # (required) Comma-separated list of binary names (non-extension portion of filename) to build and upload.
58+ bin : ${{ github.event.repository.name }}
59+ # (optional) Target triple, default is host triple.
60+ target : ${{ matrix.target }}
61+ # (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)
62+ # build-tool: cargo-zigbuild # 使用 zig 作为链接器编译 Cargo 项目, 以便于交叉编译, 仅 Linux 平台支持性较好
63+ # (optional) Archive name (non-extension portion of filename) to be uploaded.
64+ # When multiple binary names are specified, default archive name or $bin variable cannot be used.
65+ archive : ${{ github.event.repository.name }}-$tag-$target
66+ # (optional) On which platform to distribute the `.tar.gz` file.
67+ tar : unix
68+ # (optional) On which platform to distribute the `.zip` file.
69+ zip : windows
70+ # (required) GitHub token for uploading assets to GitHub Releases.
71+ token : ${{ secrets.GITHUB_TOKEN }}
72+
73+ permissions :
74+ contents : write
0 commit comments