Skip to content

Commit 4590524

Browse files
committed
ci: update CI workflows for Rust project
- add new Cargo Build & Test workflow with lint, security audit, and multi-toolchain build/test jobs - add new Release Crates workflow for automated publishing to crates.io on tags and GitHub releases - remove outdated rust.yml and release.yml workflows to consolidate CI configurations - update ghcr.yml to use checkout action v5 for compatibility - align all workflows with current best practices for CI/CD automation Signed-off-by: mingcheng <[email protected]>
1 parent 2ed1884 commit 4590524

File tree

4 files changed

+126
-196
lines changed

4 files changed

+126
-196
lines changed

.github/workflows/cargo.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!#
2+
# Copyright (c) 2025 Hangzhou Guanwaii Technology Co., Ltd.
3+
#
4+
# This source code is licensed under the MIT License,
5+
# which is located in the LICENSE file in the source tree's root directory.
6+
#
7+
# File: rust.yml
8+
# Author: mingcheng <[email protected]>
9+
# File Created: 2025-03-05 11:10:40
10+
#
11+
# Modified By: mingcheng <[email protected]>
12+
# Last Modified: 2025-10-22 00:33:40
13+
##
14+
15+
name: Cargo Build & Test
16+
17+
on:
18+
push:
19+
branches:
20+
- main
21+
- master
22+
- develop
23+
- "feature/**"
24+
pull_request:
25+
branches:
26+
- main
27+
- master
28+
- develop
29+
workflow_dispatch:
30+
31+
env:
32+
CARGO_TERM_COLOR: always
33+
RUST_BACKTRACE: 1
34+
35+
jobs:
36+
# Code quality checks (clippy and rustfmt)
37+
lint:
38+
name: Lint (clippy & rustfmt)
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v5
43+
44+
- name: Install Rust
45+
uses: dtolnay/rust-toolchain@stable
46+
with:
47+
toolchain: stable
48+
49+
- name: Rust cache
50+
uses: Swatinem/rust-cache@v2
51+
with:
52+
cache-on-failure: true
53+
54+
- name: Run cargo fmt check
55+
run: cargo fmt --all -- --check
56+
57+
- name: Run cargo clippy
58+
run: cargo clippy --all-targets --all-features -- -D warnings
59+
60+
# Security audit
61+
security_audit:
62+
name: Security Audit
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v5
67+
68+
- name: Install Rust
69+
uses: dtolnay/rust-toolchain@stable
70+
with:
71+
toolchain: stable
72+
73+
- name: Rust cache
74+
uses: Swatinem/rust-cache@v2
75+
with:
76+
cache-on-failure: true
77+
78+
- name: Install cargo-audit
79+
run: cargo install cargo-audit --locked
80+
81+
- name: Run cargo audit
82+
run: cargo audit
83+
84+
# Build and test on stable/beta/nightly
85+
build_and_test:
86+
name: Build & Test (${{ matrix.toolchain }})
87+
runs-on: ubuntu-latest
88+
needs:
89+
- lint
90+
- security_audit
91+
strategy:
92+
fail-fast: false
93+
matrix:
94+
toolchain:
95+
- stable
96+
- beta
97+
- nightly
98+
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
99+
steps:
100+
- name: Checkout code
101+
uses: actions/checkout@v5
102+
103+
- name: Setup Rust toolchain (${{ matrix.toolchain }})
104+
uses: dtolnay/rust-toolchain@stable
105+
with:
106+
toolchain: ${{ matrix.toolchain }}
107+
108+
- name: Rust cache
109+
uses: Swatinem/rust-cache@v2
110+
with:
111+
cache-on-failure: true
112+
113+
- name: Show Rust version
114+
run: |
115+
rustc --version
116+
cargo --version
117+
118+
- name: Run tests
119+
run: cargo test --all --locked
120+
121+
- name: Verify package can be built
122+
run: cargo package --locked --allow-dirty

.github/workflows/release.yml renamed to .github/workflows/crates.yml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,10 @@ jobs:
2525
with:
2626
toolchain: stable
2727

28-
- name: Cache Cargo dependencies
29-
uses: actions/cache@v4
28+
- name: Rust cache
29+
uses: Swatinem/rust-cache@v2
3030
with:
31-
path: |
32-
~/.cargo/registry
33-
~/.cargo/git
34-
target
35-
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
36-
restore-keys: |
37-
${{ runner.os }}-cargo-release-
38-
${{ runner.os }}-cargo-
39-
40-
- name: Verify version matches tag
41-
if: github.event_name == 'push'
42-
run: |
43-
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
44-
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)".*/\1/')
45-
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
46-
echo "❌ Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
47-
exit 1
48-
fi
49-
echo "✅ Version check passed: $TAG_VERSION"
31+
cache-on-failure: true
5032

5133
- name: Run tests
5234
run: cargo test --all --locked

.github/workflows/ghcr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
id-token: write
2727
steps:
2828
- name: Checkout repository
29-
uses: actions/checkout@v4
29+
uses: actions/checkout@v5
3030

3131
- name: Set up QEMU
3232
uses: docker/setup-qemu-action@v3

.github/workflows/rust.yml

Lines changed: 0 additions & 174 deletions
This file was deleted.

0 commit comments

Comments
 (0)