update workflows #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rust CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # 任务一:专门在 Docker 容器中检查 Linux | |
| check-linux: | |
| name: Check on Linux | |
| runs-on: ubuntu-latest | |
| # 使用官方 Rust Docker 容器,保证环境绝对干净 | |
| container: | |
| image: rust:stable # 你也可以用 rust:1.79.0 等具体版本 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| # 容器中已包含 Rust,无需安装。直接进行检查。 | |
| - name: Cache Cargo dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| /usr/local/cargo/registry/index/ | |
| /usr/local/cargo/registry/cache/ | |
| /usr/local/cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run Clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run tests | |
| run: cargo test --verbose --all-features | |
| - name: Build release | |
| run: cargo build --release --all-features | |
| - name: Check packaging | |
| run: cargo package --all-features | |
| # 任务二:检查 Windows 和 macOS | |
| check-windows-macos: | |
| name: Check on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [windows-latest, macos-latest] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| override: true # 在这些平台上,override 应该能正常工作 | |
| components: clippy, fmt | |
| - name: Cache Cargo dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run Clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run tests | |
| run: cargo test --verbose --all-features | |
| - name: Build release | |
| run: cargo build --release --all-features | |
| - name: Check packaging | |
| run: cargo package --all-features | |
| # (可选) 如果你需要在发布前确保所有检查都通过 | |
| # publish: | |
| # name: Publish to Crates.io | |
| # runs-on: ubuntu-latest | |
| # needs: [check-linux, check-windows-macos] # 依赖于上面两个任务 | |
| # if: startsWith(github.ref, 'refs/tags/') | |
| # # ... publish steps ... |