Skip to content

Commit 72d31df

Browse files
committed
add: github action release.
1 parent 05ee418 commit 72d31df

File tree

1 file changed

+53
-24
lines changed

1 file changed

+53
-24
lines changed

.github/workflows/rust.yml

+53-24
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,69 @@
1-
name: Rust CI
1+
name: Rust CI and Release
22

33
on:
44
push:
55
branches:
66
- main
7-
- dev # 在 push 到 main 或 dev 分支时触发
7+
- dev
88
pull_request:
99
branches:
1010
- main
11-
- dev # 在拉取请求到 main 或 dev 分支时触发
11+
- dev
12+
release:
13+
types: [created]
1214

1315
env:
1416
CARGO_TERM_COLOR: always
1517

1618
jobs:
17-
build:
18-
19+
build_and_test:
20+
if: github.event_name != 'release' # 仅在推送或拉取请求时运行
1921
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Set up Rust
25+
uses: actions-rs/toolchain@v1
26+
with:
27+
toolchain: stable
28+
- name: Install Cargo Tarpaulin
29+
run: cargo install cargo-tarpaulin
30+
- name: Build
31+
run: cargo build --verbose
32+
- name: Run tests
33+
run: cargo test --verbose
34+
- name: Run cargo-tarpaulin
35+
run: cargo tarpaulin --out Xml
36+
- name: Run cargo-audit
37+
run: cargo install cargo-audit && cargo audit
38+
- name: Upload coverage to Codecov
39+
uses: codecov/codecov-action@v4.0.1
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
2042

43+
release:
44+
if: github.event_name == 'release' # 仅在创建 Release 时运行
45+
name: release ${{ matrix.target }}
46+
runs-on: ubuntu-latest
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
- target: x86_64-pc-windows-gnu
52+
archive: zip
53+
- target: x86_64-unknown-linux-musl
54+
archive: tar.gz tar.xz tar.zst
55+
- target: x86_64-apple-darwin
56+
archive: zip
2157
steps:
22-
- uses: actions/checkout@v4
23-
- name: Set up Rust
24-
uses: actions-rs/toolchain@v1
25-
with:
26-
toolchain: stable
27-
- name: Install Cargo Tarpaulin
28-
run: cargo install cargo-tarpaulin
29-
- name: Build
30-
run: cargo build --verbose
31-
- name: Run tests
32-
run: cargo test --verbose
33-
- name: Run cargo-tarpaulin
34-
run: cargo tarpaulin --out Xml
35-
- name: Run cargo-audit
36-
run: cargo install cargo-audit && cargo-audit audit
37-
- name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@v4.0.1
39-
with:
40-
token: ${{ secrets.CODECOV_TOKEN }}
58+
- uses: actions/checkout@v4
59+
- name: Set up Rust
60+
uses: actions-rs/toolchain@v1
61+
with:
62+
toolchain: stable
63+
- name: Compile and release
64+
uses: rust-build/rust-build.action@v1.4.5
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
RUSTTARGET: ${{ matrix.target }}
69+
ARCHIVE_TYPES: ${{ matrix.archive }}

0 commit comments

Comments
 (0)