fix commands #2555
This file contains 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: Continuous integration 🦀 | |
on: | |
push: | |
branches: | |
- main | |
- doug/init-hugr-llvm-subtree # remove before merging | |
pull_request: | |
branches: | |
- main | |
merge_group: | |
types: [checks_requested] | |
workflow_dispatch: {} | |
env: | |
CARGO_TERM_COLOR: always | |
CARGO_INCREMENTAL: 0 | |
RUSTFLAGS: "--cfg=ci_run" | |
MIRIFLAGS: "-Zmiri-permissive-provenance" # Required due to warnings in bitvec 1.0.1 | |
CI: true # insta snapshots behave differently on ci | |
SCCACHE_GHA_ENABLED: "true" | |
RUSTC_WRAPPER: "sccache" | |
HUGR_TEST_SCHEMA: "1" | |
jobs: | |
# Check if changes were made to the relevant files. | |
# Always returns true if running on the default branch, to ensure all changes are thoroughly checked. | |
changes: | |
name: Check for changes | |
runs-on: ubuntu-latest | |
# Required permissions | |
permissions: | |
pull-requests: read | |
# Set job outputs to values from filter step | |
# These outputs are always true when running after a merge to main, or if the PR has a `run-ci-checks` label. | |
outputs: | |
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }} | |
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }} | |
llvm: ${{ steps.filter.outputs.llvm == 'true' || steps.override.outputs.out == 'true' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Override label | |
id: override | |
run: | | |
echo "Label contains run-ci-checks: $OVERRIDE_LABEL" | |
if [ "$OVERRIDE_LABEL" == "true" ]; then | |
echo "Overriding due to label 'run-ci-checks'" | |
echo "out=true" >> $GITHUB_OUTPUT | |
elif [ "$DEFAULT_BRANCH" == "true" ]; then | |
echo "Overriding due to running on the default branch" | |
echo "out=true" >> $GITHUB_OUTPUT | |
fi | |
env: | |
OVERRIDE_LABEL: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'run-ci-checks') }} | |
DEFAULT_BRANCH: ${{ github.ref_name == github.event.repository.default_branch }} | |
- uses: dorny/paths-filter@v3 | |
id: filter | |
with: | |
filters: .github/change-filters.yml | |
check: | |
needs: changes | |
if: ${{ needs.changes.outputs.rust == 'true' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
components: rustfmt, clippy | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Check formatting | |
run: cargo fmt -- --check | |
- name: Run clippy | |
run: cargo clippy --all-targets --all-features --workspace -- -D warnings | |
- name: Build docs | |
run: cargo doc --no-deps --all-features --workspace | |
env: | |
RUSTDOCFLAGS: "-Dwarnings" | |
benches: | |
name: Build benchmarks 🏋️ | |
needs: changes | |
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@stable | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Build benchmarks with no features | |
run: cargo bench --verbose --no-run --workspace --exclude hugr-llvm --no-default-features | |
- name: Build benchmarks with all features | |
run: cargo bench --verbose --no-run --workspace --exclude hugr-llvm --all-features | |
# Run tests on Rust stable | |
tests-stable-no-features: | |
needs: changes | |
if: ${{ needs.changes.outputs.rust == 'true' }} | |
runs-on: ubuntu-latest | |
name: tests (Rust stable, no features) | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- id: toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: "stable" | |
- name: Configure default rust toolchain | |
run: rustup override set ${{steps.toolchain.outputs.name}} | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Build with no features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --no-default-features --no-run | |
- name: Tests with no features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --no-default-features | |
# Run tests on Rust stable | |
tests-stable-all-features: | |
needs: changes | |
if: ${{ needs.changes.outputs.rust == 'true' }} | |
runs-on: ubuntu-latest | |
name: tests (Rust stable, all features) | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- id: toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: "stable" | |
- name: Configure default rust toolchain | |
run: rustup override set ${{steps.toolchain.outputs.name}} | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Build with all features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --all-features --no-run | |
- name: Tests with all features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --all-features | |
- name: Build HUGR binary | |
run: cargo build -p hugr-cli | |
- name: Upload the binary to the artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: hugr_binary | |
path: target/debug/hugr | |
# Run tests on other toolchains | |
tests-other: | |
needs: changes | |
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
# Stable is covered by `tests-stable-no-features` and `tests-stable-all-features` | |
# Nightly is covered by `tests-nightly-coverage` | |
rust: ["1.75", beta] | |
name: tests (Rust ${{ matrix.rust }}) | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- id: toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ matrix.rust }} | |
- name: Configure default rust toolchain | |
run: rustup override set ${{steps.toolchain.outputs.name}} | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Build with no features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --no-default-features --no-run | |
- name: Tests with no features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --no-default-features | |
- name: Build with all features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --all-features --no-run | |
- name: Tests with all features | |
run: cargo test --verbose --workspace --exclude hugr-llvm --all-features | |
# Ensure that serialized extensions match rust implementation | |
std-extensions: | |
needs: [changes, tests-stable-all-features] | |
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }} | |
name: Check standard extensions | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download the hugr binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: hugr_binary | |
path: ${{ github.workspace }}/target/debug | |
- name: Generate the updated definitions | |
run: | | |
chmod +x target/debug/hugr | |
./target/debug/hugr gen-extensions -o specification/std_extensions | |
- name: Check if the declarations are up to date | |
run: | | |
git diff --exit-code --name-only specification/std_extensions/ | |
if [ $? -ne 0 ]; then | |
echo "The serialized standard extensions are not up to date" | |
echo "Please run 'just gen-extensions' and commit the changes" | |
exit 1 | |
fi | |
tests-nightly-coverage: | |
needs: changes | |
# Run only if there are changes in the relevant files | |
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' }} | |
runs-on: ubuntu-latest | |
name: tests (Rust nightly, coverage) | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
# Nightly is required to count doctests coverage | |
toolchain: "nightly" | |
components: llvm-tools-preview | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@cargo-llvm-cov | |
- name: Run tests with coverage instrumentation | |
run: | | |
cargo llvm-cov clean --workspace | |
cargo llvm-cov --no-report --workspace --exclude hugr-llvm --no-default-features --doctests | |
cargo llvm-cov --no-report --workspace --exclude hugr-llvm --all-features --doctests | |
- name: Generate coverage report | |
run: cargo llvm-cov --all-features report --codecov --output-path coverage.json | |
- name: Upload coverage to codecov.io | |
uses: codecov/codecov-action@v4 | |
with: | |
files: coverage.json | |
name: rust | |
flags: rust | |
token: ${{ secrets.CODECOV_TOKEN }} | |
tests-stable-llvm: | |
needs: changes | |
if: ${{ needs.changes.outputs.llvm == 'true' && github.event_name == 'push'}} | |
runs-on: ubuntu-latest | |
name: tests hugr-llvm | |
strategy: | |
matrix: | |
llvm-version: | |
- ["14.0", "14-0"] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: mozilla-actions/sccache-action@v0.0.6 | |
- id: toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: "stable" | |
- name: Configure default rust toolchain | |
run: rustup override set ${{steps.toolchain.outputs.name}} | |
- name: Install CapnProto | |
run: sudo apt-get install -y capnproto | |
- name: Install LLVM and Clang | |
uses: KyleMayes/install-llvm-action@v2 | |
with: | |
version: ${{ matrix.llvm-version[0] }} | |
env: true | |
- name: Build | |
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }} --no-run | |
- name: Tests with no features | |
run: cargo test -p hugr-llvm --verbose --features llvm${{ matrix.llvm-version[1] }} | |
rs-semver-checks: | |
needs: [changes, check] | |
if: ${{ needs.changes.outputs.rust == 'true' && github.event_name == 'pull_request' }} | |
uses: CQCL/hugrverse-actions/.github/workflows/rs-semver-checks.yml@main | |
with: | |
apt-dependencies: capnproto | |
secrets: | |
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }} | |
# This is a meta job to mark successful completion of the required checks, | |
# even if they are skipped due to no changes in the relevant files. | |
required-checks: | |
name: Required checks 🦀 | |
needs: | |
[ | |
changes, | |
check, | |
tests-stable-no-features, | |
tests-stable-all-features, | |
std-extensions, | |
] | |
if: ${{ !cancelled() }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fail if required checks failed | |
# This condition should simply be `if: failure() || cancelled()`, | |
# but there seems to be a bug in the github workflow runner. | |
# | |
# See https://github.com/orgs/community/discussions/80788 | |
if: | | |
needs.changes.result == 'failure' || needs.changes.result == 'cancelled' || | |
needs.check.result == 'failure' || needs.check.result == 'cancelled' || | |
needs.tests-stable-no-features.result == 'failure' || needs.tests-stable-no-features.result == 'cancelled' || | |
needs.tests-stable-all-features.result == 'failure' || needs.tests-stable-all-features.result == 'cancelled' || | |
needs.std-extensions.result == 'failure' || needs.std-extensions.result == 'cancelled' | |
run: | | |
echo "Required checks failed" | |
echo "Please check the logs for more information" | |
exit 1 | |
- name: Pass if required checks passed | |
run: | | |
echo "All required checks passed" |