refactor: 统一并简化错误处理 #2
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: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| jobs: | |
| test: | |
| name: Test (${{ matrix.target }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # Windows targets | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| - target: i686-pc-windows-msvc | |
| os: windows-latest | |
| msvc_arch: x86 | |
| - target: aarch64-pc-windows-msvc | |
| os: windows-latest | |
| msvc_arch: amd64_arm64 | |
| check_only: true | |
| # macOS targets | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| # Linux targets | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| apt_packages: gcc-aarch64-linux-gnu libclang-dev | |
| check_only: true | |
| # Android targets | |
| - target: aarch64-linux-android | |
| os: ubuntu-latest | |
| cross: true | |
| - target: armv7-linux-androideabi | |
| os: ubuntu-latest | |
| cross: true | |
| - target: i686-linux-android | |
| os: ubuntu-latest | |
| cross: true | |
| - target: x86_64-linux-android | |
| os: ubuntu-latest | |
| cross: true | |
| # iOS target | |
| - target: aarch64-apple-ios | |
| os: macos-latest | |
| check_only: true | |
| # WASM target | |
| - target: wasm32-unknown-emscripten | |
| os: ubuntu-latest | |
| emscripten: true | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@nightly | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install Linux dependencies | |
| if: runner.os == 'Linux' && !matrix.cross | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libasound2-dev ${{ matrix.apt_packages }} | |
| - name: Setup MSVC Compiler | |
| if: runner.os == 'Windows' && matrix.msvc_arch | |
| uses: apoint123/msvc-dev-cmd@v1 | |
| with: | |
| arch: ${{ matrix.msvc_arch }} | |
| - name: Install cross | |
| if: matrix.cross | |
| uses: taiki-e/install-action@cross | |
| - name: Install Emscripten SDK | |
| if: matrix.emscripten | |
| uses: emscripten-core/setup-emsdk@v16 | |
| - name: Add Emscripten target | |
| if: matrix.emscripten | |
| run: rustup target add ${{ matrix.target }} | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Run cross check | |
| if: matrix.cross | |
| run: cross check --target ${{ matrix.target }} --workspace | |
| - name: Run cargo check | |
| if: "!matrix.cross && matrix.check_only" | |
| run: cargo check --target ${{ matrix.target }} --workspace | |
| - name: Run cargo test | |
| if: "!matrix.cross && !matrix.check_only" | |
| run: cargo test --target ${{ matrix.target }} --workspace | |
| clippy: | |
| name: Clippy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@nightly | |
| with: | |
| components: clippy | |
| - name: Run clippy | |
| run: cargo clippy --workspace -- -D warnings | |
| fmt: | |
| name: Format | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@nightly | |
| with: | |
| components: rustfmt | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check |