|
| 1 | +name: rust-ci |
| 2 | +on: |
| 3 | + pull_request: {} |
| 4 | + push: |
| 5 | + branches: [main, dev] |
| 6 | + |
| 7 | +jobs: |
| 8 | + checks: |
| 9 | + name: ${{ matrix.name }} |
| 10 | + runs-on: ${{ matrix.runner }} |
| 11 | + timeout-minutes: 20 |
| 12 | + defaults: |
| 13 | + run: |
| 14 | + working-directory: codex-rs |
| 15 | + env: |
| 16 | + CARGO_INCREMENTAL: "0" |
| 17 | + SCCACHE_CACHE_SIZE: 10G |
| 18 | + |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - runner: ubuntu-24.04 |
| 24 | + target: x86_64-unknown-linux-gnu |
| 25 | + name: Linux checks |
| 26 | + - runner: macos-14 |
| 27 | + target: aarch64-apple-darwin |
| 28 | + name: macOS checks |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v5 |
| 32 | + |
| 33 | + - uses: dtolnay/rust-toolchain@1.90 |
| 34 | + with: |
| 35 | + targets: ${{ matrix.target }} |
| 36 | + components: rustfmt, clippy |
| 37 | + |
| 38 | + # sccache setup |
| 39 | + - name: Install sccache |
| 40 | + uses: taiki-e/install-action@44c6d64aa62cd779e873306675c7a58e86d6d532 # v2 |
| 41 | + with: |
| 42 | + tool: sccache |
| 43 | + version: 0.7.5 |
| 44 | + |
| 45 | + - name: Configure sccache backend |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + if [[ -n "${ACTIONS_CACHE_URL:-}" && -n "${ACTIONS_RUNTIME_TOKEN:-}" ]]; then |
| 50 | + echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV" |
| 51 | + echo "Using sccache GitHub backend" |
| 52 | + else |
| 53 | + echo "SCCACHE_GHA_ENABLED=false" >> "$GITHUB_ENV" |
| 54 | + echo "SCCACHE_DIR=${{ github.workspace }}/.sccache" >> "$GITHUB_ENV" |
| 55 | + echo "Using sccache local disk fallback" |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Enable sccache wrapper |
| 59 | + shell: bash |
| 60 | + run: echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV" |
| 61 | + |
| 62 | + - name: Restore sccache cache (fallback) |
| 63 | + if: ${{ env.SCCACHE_GHA_ENABLED != 'true' }} |
| 64 | + uses: actions/cache/restore@v4 |
| 65 | + with: |
| 66 | + path: ${{ github.workspace }}/.sccache/ |
| 67 | + key: sccache-${{ matrix.runner }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-${{ github.run_id }} |
| 68 | + restore-keys: | |
| 69 | + sccache-${{ matrix.runner }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}- |
| 70 | + sccache-${{ matrix.runner }}-${{ matrix.target }}- |
| 71 | +
|
| 72 | + # CI checks |
| 73 | + - name: cargo check |
| 74 | + run: cargo check --target ${{ matrix.target }} --all-features |
| 75 | + |
| 76 | + - name: cargo fmt |
| 77 | + run: cargo fmt -- --check |
| 78 | + |
| 79 | + - name: cargo clippy |
| 80 | + run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings |
| 81 | + |
| 82 | + - name: cargo test |
| 83 | + run: cargo test --target ${{ matrix.target }} --all-features |
| 84 | + |
| 85 | + # Save sccache |
| 86 | + - name: Save sccache cache (fallback) |
| 87 | + if: always() && !cancelled() && env.SCCACHE_GHA_ENABLED != 'true' |
| 88 | + continue-on-error: true |
| 89 | + uses: actions/cache/save@v4 |
| 90 | + with: |
| 91 | + path: ${{ github.workspace }}/.sccache/ |
| 92 | + key: sccache-${{ matrix.runner }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}-${{ github.run_id }} |
| 93 | + |
| 94 | + - name: sccache stats |
| 95 | + if: always() |
| 96 | + continue-on-error: true |
| 97 | + run: sccache --show-stats || true |
0 commit comments