|
5 | 5 | # which is located in the LICENSE file in the source tree's root directory. |
6 | 6 | # |
7 | 7 | # File: rust.yml |
8 | | -# Author: mingcheng ([email protected]) |
| 8 | +# Author: mingcheng <[email protected]> |
9 | 9 | # File Created: 2025-03-05 11:10:40 |
10 | 10 | # |
11 | | -# Modified By: mingcheng ([email protected]) |
12 | | -# Last Modified: 2025-03-17 18:29:18 |
| 11 | +# Modified By: mingcheng <[email protected]> |
| 12 | +# Last Modified: 2025-10-16 16:37:42 |
13 | 13 | ## |
14 | 14 |
|
15 | 15 | name: Cargo Build & Test |
16 | 16 |
|
17 | 17 | on: |
18 | 18 | push: |
| 19 | + branches: |
| 20 | + - main |
| 21 | + - master |
| 22 | + - develop |
| 23 | + - "feature/**" |
19 | 24 | pull_request: |
| 25 | + branches: |
| 26 | + - main |
| 27 | + - master |
| 28 | + - develop |
| 29 | + workflow_dispatch: |
20 | 30 |
|
21 | 31 | env: |
22 | 32 | CARGO_TERM_COLOR: always |
| 33 | + RUST_BACKTRACE: 1 |
23 | 34 |
|
24 | 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 code |
| 42 | + uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Setup Rust toolchain |
| 45 | + uses: dtolnay/rust-toolchain@stable |
| 46 | + with: |
| 47 | + components: clippy, rustfmt |
| 48 | + |
| 49 | + - name: Cache cargo registry |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: | |
| 53 | + ~/.cargo/bin/ |
| 54 | + ~/.cargo/registry/index/ |
| 55 | + ~/.cargo/registry/cache/ |
| 56 | + ~/.cargo/git/db/ |
| 57 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-cargo- |
| 60 | +
|
| 61 | + - name: Cache target directory |
| 62 | + uses: actions/cache@v4 |
| 63 | + with: |
| 64 | + path: target |
| 65 | + key: ${{ runner.os }}-target-lint-${{ hashFiles('**/Cargo.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-target-lint- |
| 68 | +
|
| 69 | + - name: Run cargo fmt check |
| 70 | + run: cargo fmt --all -- --check |
| 71 | + |
| 72 | + - name: Run cargo clippy |
| 73 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 74 | + |
| 75 | + # Security audit |
| 76 | + security_audit: |
| 77 | + name: Security Audit |
| 78 | + runs-on: ubuntu-latest |
| 79 | + steps: |
| 80 | + - name: Checkout code |
| 81 | + uses: actions/checkout@v4 |
| 82 | + |
| 83 | + - name: Setup Rust toolchain |
| 84 | + uses: dtolnay/rust-toolchain@stable |
| 85 | + |
| 86 | + - name: Install cargo-audit |
| 87 | + run: cargo install cargo-audit --locked |
| 88 | + |
| 89 | + - name: Run cargo audit |
| 90 | + run: cargo audit |
| 91 | + |
| 92 | + # Build and test on stable/beta/nightly |
25 | 93 | build_and_test: |
26 | | - name: Rust project - latest |
| 94 | + name: Build & Test (${{ matrix.toolchain }}) |
27 | 95 | runs-on: ubuntu-latest |
| 96 | + needs: [lint] |
28 | 97 | strategy: |
| 98 | + fail-fast: false |
29 | 99 | matrix: |
30 | 100 | toolchain: |
31 | 101 | - stable |
32 | 102 | - beta |
33 | 103 | - nightly |
| 104 | + continue-on-error: ${{ matrix.toolchain == 'nightly' }} |
34 | 105 | steps: |
35 | | - - uses: actions/checkout@v4 |
36 | | - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} |
37 | | - - run: rustup component add clippy --toolchain ${{ matrix.toolchain }} |
38 | | - - run: rustup component add rustfmt --toolchain ${{ matrix.toolchain }} |
39 | | - - run: cargo clippy -- -D warnings |
40 | | - - run: cargo fmt --all -- --check |
41 | | - - run: cargo build --verbose |
42 | | - - run: cargo test --verbose |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Setup Rust toolchain (${{ matrix.toolchain }}) |
| 110 | + uses: dtolnay/rust-toolchain@master |
| 111 | + with: |
| 112 | + toolchain: ${{ matrix.toolchain }} |
| 113 | + |
| 114 | + - name: Cache cargo registry |
| 115 | + uses: actions/cache@v4 |
| 116 | + with: |
| 117 | + path: | |
| 118 | + ~/.cargo/bin/ |
| 119 | + ~/.cargo/registry/index/ |
| 120 | + ~/.cargo/registry/cache/ |
| 121 | + ~/.cargo/git/db/ |
| 122 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 123 | + restore-keys: | |
| 124 | + ${{ runner.os }}-cargo- |
| 125 | +
|
| 126 | + - name: Cache target directory |
| 127 | + uses: actions/cache@v4 |
| 128 | + with: |
| 129 | + path: target |
| 130 | + key: ${{ runner.os }}-target-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }} |
| 131 | + restore-keys: | |
| 132 | + ${{ runner.os }}-target-${{ matrix.toolchain }}- |
| 133 | +
|
| 134 | + - name: Show Rust version |
| 135 | + run: | |
| 136 | + rustc --version |
| 137 | + cargo --version |
| 138 | +
|
| 139 | + - name: Build project |
| 140 | + run: cargo build --verbose --all-features |
| 141 | + |
| 142 | + - name: Run tests |
| 143 | + run: cargo test --verbose --all-features |
| 144 | + |
| 145 | + - name: Build release |
| 146 | + run: cargo build --release --verbose |
| 147 | + |
| 148 | + # Check documentation builds |
| 149 | + doc: |
| 150 | + name: Documentation |
| 151 | + runs-on: ubuntu-latest |
| 152 | + steps: |
| 153 | + - name: Checkout code |
| 154 | + uses: actions/checkout@v4 |
| 155 | + |
| 156 | + - name: Setup Rust toolchain |
| 157 | + uses: dtolnay/rust-toolchain@stable |
| 158 | + |
| 159 | + - name: Cache cargo registry |
| 160 | + uses: actions/cache@v4 |
| 161 | + with: |
| 162 | + path: | |
| 163 | + ~/.cargo/bin/ |
| 164 | + ~/.cargo/registry/index/ |
| 165 | + ~/.cargo/registry/cache/ |
| 166 | + ~/.cargo/git/db/ |
| 167 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 168 | + restore-keys: | |
| 169 | + ${{ runner.os }}-cargo- |
| 170 | +
|
| 171 | + - name: Build documentation |
| 172 | + run: cargo doc --no-deps --all-features |
| 173 | + env: |
| 174 | + RUSTDOCFLAGS: -D warnings |
0 commit comments