|
| 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 |
0 commit comments