ci: shorten PR workflow critical path #849
Workflow file for this run
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 test / linting | |
| permissions: | |
| contents: read | |
| env: | |
| TRIGGER_ON_PR_PUSH: true # Set to true to enable triggers on PR pushes | |
| RUSTFLAGS: -C debuginfo=0 | |
| RUST_BACKTRACE: 1 | |
| LLVM_VERSION: "14.0.6" | |
| on: | |
| push: | |
| branches: [ "main", "master", "development", "dev" ] | |
| paths: | |
| - 'crates/**' | |
| - 'exp/**' | |
| - 'examples/**' | |
| - 'julia/pecos-julia-ffi/**' | |
| - 'python/pecos-rslib-cuda/**' | |
| - 'python/pecos-rslib/**' | |
| - 'python/pecos-rslib-llvm/**' | |
| - 'Cargo.toml' | |
| - 'Cargo.lock' | |
| - 'Justfile' | |
| - 'scripts/ci/**' | |
| - 'scripts/win-msvc-bootstrap.ps1' | |
| - '.github/workflows/rust-test.yml' | |
| - '.pre-commit-config.yaml' | |
| pull_request: | |
| branches: [ "main", "master", "development", "dev" ] | |
| paths: | |
| - 'crates/**' | |
| - 'exp/**' | |
| - 'examples/**' | |
| - 'julia/pecos-julia-ffi/**' | |
| - 'python/pecos-rslib-cuda/**' | |
| - 'python/pecos-rslib/**' | |
| - 'python/pecos-rslib-llvm/**' | |
| - 'Cargo.toml' | |
| - 'Cargo.lock' | |
| - 'Justfile' | |
| - 'scripts/ci/**' | |
| - 'scripts/win-msvc-bootstrap.ps1' | |
| - '.github/workflows/rust-test.yml' | |
| - '.pre-commit-config.yaml' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| rust-lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (egress audit) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Free disk space | |
| run: | | |
| sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc | |
| sudo apt-get clean | |
| - name: Set up Rust | |
| run: | | |
| bash scripts/ci/ensure-rust.sh stable minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| rustup override set stable | |
| rustup show | |
| - name: Install just | |
| uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4 | |
| - name: Cache Rust | |
| uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 | |
| with: | |
| cache-bin: false | |
| prefix-key: v1-rust-no-bin | |
| save-if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev') }} | |
| - name: Install CUDA Toolkit | |
| uses: Jimver/cuda-toolkit@3d45d157f327c09c04b50ee6ccdea2d9d017ec76 # v0.2.35 | |
| id: cuda-toolkit | |
| with: | |
| cuda: '12.6.3' | |
| method: 'network' | |
| sub-packages: '["nvcc", "cudart-dev"]' | |
| non-cuda-sub-packages: '["libcublas", "libcublas-dev"]' | |
| - name: Cache LLVM ${{ env.LLVM_VERSION }} | |
| id: cache-llvm | |
| uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 | |
| with: | |
| path: ~/.pecos/deps/llvm-14 | |
| key: llvm-${{ env.LLVM_VERSION }}-${{ runner.os }}-${{ runner.arch }}-v2 | |
| - name: Ensure LLVM ${{ env.LLVM_VERSION }} | |
| run: just ci-env | |
| - name: Save LLVM ${{ env.LLVM_VERSION }} cache | |
| if: steps.cache-llvm.outputs.cache-hit != 'true' && github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev') | |
| uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 | |
| with: | |
| path: ~/.pecos/deps/llvm-14 | |
| key: ${{ steps.cache-llvm.outputs.cache-primary-key }} | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy | |
| run: cargo clippy --locked --workspace --all-targets --all-features -- -D warnings | |
| rust-lint-no-llvm: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (egress audit) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Rust | |
| run: | | |
| bash scripts/ci/ensure-rust.sh stable minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| rustup override set stable | |
| rustup show | |
| - name: Cache Rust | |
| uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 | |
| with: | |
| cache-bin: false | |
| prefix-key: v1-rust-no-bin | |
| save-if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev') }} | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| - name: Run clippy without LLVM features | |
| run: | | |
| for crate in pecos-core pecos-engines pecos-simulators pecos-programs pecos-random pecos-qasm pecos-phir-json pecos-qis-ffi-types; do | |
| echo "Testing $crate..." | |
| cd "crates/$crate" && cargo clippy --locked --all-targets -- -D warnings && cd ../.. | |
| done | |
| echo "Testing pecos without default features..." | |
| cd crates/pecos && cargo clippy --locked --all-targets --no-default-features -- -D warnings && cd ../.. | |
| pre-commit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (egress audit) | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 | |
| with: | |
| python-version: '3.x' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7 | |
| with: | |
| version: "0.11.14" | |
| - name: Install integrity check tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ripgrep | |
| - name: Install pre-commit | |
| run: pip install pre-commit | |
| - name: Run pre-commit | |
| run: pre-commit run --all-files --show-diff-on-failure | |
| rust-test: | |
| needs: [pre-commit, rust-lint] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: ${{ github.event_name == 'pull_request' && fromJSON('["ubuntu-latest"]') || fromJSON('["ubuntu-latest", "macos-latest", "windows-2022"]') }} | |
| steps: | |
| - name: Harden the runner (egress audit) | |
| if: runner.os == 'Linux' | |
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | |
| with: | |
| egress-policy: audit | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| persist-credentials: false | |
| - name: Free disk space (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc | |
| sudo apt-get clean | |
| - name: Set up Rust (Windows) | |
| if: runner.os == 'Windows' && (github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest') | |
| run: | | |
| rustup set default-host x86_64-pc-windows-msvc | |
| rustup toolchain install stable --profile minimal | |
| rustup default stable | |
| echo "$HOME\.cargo\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
| $env:Path += ";$HOME\.cargo\bin" | |
| rustup show | |
| - name: Set up Rust (Unix) | |
| if: runner.os != 'Windows' && (github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest') | |
| run: | | |
| bash scripts/ci/ensure-rust.sh stable minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| rustup show | |
| - name: Install just | |
| if: github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest' | |
| uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4 | |
| - name: Cache Rust | |
| if: github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest' | |
| uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 | |
| with: | |
| cache-bin: false | |
| prefix-key: v1-rust-no-bin | |
| save-if: ${{ github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev') }} | |
| - name: Cache LLVM ${{ env.LLVM_VERSION }} | |
| if: github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest' | |
| id: cache-llvm | |
| uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 | |
| with: | |
| path: ~/.pecos/deps/llvm-14 | |
| key: llvm-${{ env.LLVM_VERSION }}-${{ runner.os }}-${{ runner.arch }}-v2 | |
| - name: Bootstrap MSVC for the Cargo build path (Windows) | |
| if: runner.os == 'Windows' && (github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest') | |
| shell: pwsh | |
| # Single mechanism: writes the linker + LIB/INCLUDE into | |
| # .cargo/config.toml (read by cargo after it spawns). Sets no env pin, | |
| # so `just ci-env` and the direct `cargo build` steps below both work, | |
| # identically to a local Windows build. | |
| run: ./scripts/win-msvc-bootstrap.ps1 | |
| - name: Ensure LLVM ${{ env.LLVM_VERSION }} | |
| if: github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest' | |
| run: just ci-env | |
| - name: Save LLVM ${{ env.LLVM_VERSION }} cache | |
| if: (github.event_name != 'pull_request' || matrix.os == 'ubuntu-latest') && steps.cache-llvm.outputs.cache-hit != 'true' && github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'master' || github.ref_name == 'development' || github.ref_name == 'dev') | |
| uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 | |
| with: | |
| path: ~/.pecos/deps/llvm-14 | |
| key: ${{ steps.cache-llvm.outputs.cache-primary-key }} | |
| - name: Install CUDA Toolkit (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| uses: Jimver/cuda-toolkit@3d45d157f327c09c04b50ee6ccdea2d9d017ec76 # v0.2.35 | |
| id: cuda-toolkit-test | |
| with: | |
| cuda: '12.6.3' | |
| method: 'network' | |
| sub-packages: '["nvcc", "cudart-dev"]' | |
| non-cuda-sub-packages: '["libcublas", "libcublas-dev"]' | |
| - name: Compile tests (macOS) | |
| if: matrix.os == 'macos-latest' && github.event_name != 'pull_request' | |
| run: cargo build --locked -p pecos-cli --release | |
| - name: Compile tests (Linux) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| # Use `pecos rust test` for runtime hardware detection (cuQuantum, GPU) | |
| # Dry-run: just compile, the run step below does the actual test | |
| cargo build --locked -p pecos-cli --release | |
| - name: Compile tests (Windows) | |
| if: runner.os == 'Windows' && github.event_name != 'pull_request' | |
| run: cargo build --locked -p pecos-cli --release | |
| - name: Run tests (macOS) | |
| if: matrix.os == 'macos-latest' && github.event_name != 'pull_request' | |
| env: | |
| # Prevent Homebrew/system library paths from interfering with linking | |
| LIBRARY_PATH: /usr/lib | |
| run: | | |
| unset LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH PKG_CONFIG_PATH | |
| ./target/release/pecos rust test | |
| - name: Run tests (Linux) | |
| if: matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' | |
| run: | | |
| ./target/release/pecos rust test | |
| - name: Run tests (Linux PR smoke path) | |
| if: matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' | |
| run: | | |
| ./target/release/pecos rust test --help | |
| - name: Run tests (Windows) | |
| if: runner.os == 'Windows' && github.event_name != 'pull_request' | |
| run: .\target\release\pecos.exe rust test |