From a935a0b2e1b184cc2de757cf17ecf576d677eea9 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Tue, 19 Mar 2024 10:59:46 +0000 Subject: [PATCH] Add a meta "required-checks" job that succeeds if things are skipped --- .github/workflows/ci-py.yml | 21 +++++++++++- .github/workflows/ci-rs.yml | 64 ++++++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-py.yml b/.github/workflows/ci-py.yml index 1f8f4baeb..eaee6ee84 100644 --- a/.github/workflows/ci-py.yml +++ b/.github/workflows/ci-py.yml @@ -74,9 +74,28 @@ jobs: - name: Run tests run: poetry run pytest + # 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: [check] + if: always() + runs-on: ubuntu-latest + steps: + - name: Fail if required checks failed + if: (failure() || 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" + coverage: needs: [changes, check] - if: ${{ needs.changes.outputs.python == 'true' }} && github.event_name != 'merge_group' + # Run only if there are changes in the relevant files and the check job passed or was skipped + if: always() && !failure() && !cancelled() && needs.changes.outputs.python == 'true' && github.event_name != 'merge_group' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/ci-rs.yml b/.github/workflows/ci-rs.yml index 1048a795c..38368baf1 100644 --- a/.github/workflows/ci-rs.yml +++ b/.github/workflows/ci-rs.yml @@ -77,24 +77,39 @@ jobs: - name: Build benchmarks with all features run: cargo bench --verbose --no-run --workspace --all-features - tests: + # Run tests on Rust stable + tests-stable: needs: changes if: ${{ needs.changes.outputs.rust == 'true' }} runs-on: ubuntu-latest + name: tests (Rust stable) + steps: + - uses: actions/checkout@v4 + - uses: mozilla-actions/sccache-action@v0.0.4 + - id: toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 'stable' + - name: Configure default rust toolchain + run: rustup override set ${{steps.toolchain.outputs.name}} + - name: Build with no features + run: cargo test --verbose --workspace --no-default-features --no-run + - name: Tests with no features + run: cargo test --verbose --workspace --no-default-features + - name: Build with all features + run: cargo test --verbose --workspace --all-features --no-run + - name: Tests with all features + run: cargo test --verbose --workspace --all-features + + # 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: - rust: ['1.75', stable, beta, nightly] - # workaround to ignore non-stable tests when running the merge queue checks - # see: https://github.community/t/how-to-conditionally-include-exclude-items-in-matrix-eg-based-on-branch/16853/6 - isMerge: - - ${{ github.event_name == 'merge_group' }} - exclude: - - rust: '1.75' - isMerge: true - - rust: beta - isMerge: true - - rust: nightly - isMerge: true + rust: ['1.75', beta, nightly] name: tests (Rust ${{ matrix.rust }}) steps: - uses: actions/checkout@v4 @@ -114,9 +129,28 @@ jobs: - name: Tests with all features run: cargo test --verbose --workspace --all-features + # 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: [check, tests-stable] + if: always() + runs-on: ubuntu-latest + steps: + - name: Fail if required checks failed + if: (failure() || 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" + coverage: - needs: [changes, tests, check] - if: ${{ needs.changes.outputs.rust == 'true' }} && github.event_name != 'merge_group' + needs: [changes, tests-stable, tests-other, check] + # Run only if there are changes in the relevant files and the check job passed or was skipped + if: always() && !failure() && !cancelled() && needs.changes.outputs.rust == 'true' && github.event_name != 'merge_group' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4