diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml index a3d37cd3..25d98c28 100644 --- a/.github/workflows/coveralls.yml +++ b/.github/workflows/coveralls.yml @@ -5,7 +5,20 @@ on: name: Code coverage with llvm-cov jobs: + Prepare: + runs-on: ubuntu-latest + outputs: + pr_changed_source: ${{ steps.classify_pr.outputs.pr_changed_source }} + steps: + - name: Checkout Crate + uses: actions/checkout@v4 + - name: Determine what files the PR changes. + id: classify_pr + run: contrib/classify-pr.sh ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }} + Coveralls: + needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Code coverage - stable toolchain runs-on: ubuntu-latest strategy: diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml index 3a0e4d1a..232d8812 100644 --- a/.github/workflows/fuzz.yml +++ b/.github/workflows/fuzz.yml @@ -9,8 +9,20 @@ on: pull_request: jobs: + Prepare: + runs-on: ubuntu-latest + outputs: + pr_changed_source: ${{ steps.classify_pr.outputs.pr_changed_source }} + steps: + - name: Checkout Crate + uses: actions/checkout@v4 + - name: Determine what files the PR changes. + id: classify_pr + run: contrib/classify-pr.sh ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }} + fuzz: - if: ${{ !github.event.act }} + needs: Prepare + if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true' runs-on: ubuntu-latest strategy: fail-fast: false @@ -64,7 +76,8 @@ jobs: path: executed_${{ matrix.fuzz_target }} verify-execution: - if: ${{ !github.event.act }} + needs: Prepare + if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true' needs: fuzz runs-on: ubuntu-latest steps: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 169e2e5f..6081d431 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,9 +14,13 @@ jobs: crates: ${{ steps.get_matrix.outputs.crates }} deps: ${{ steps.get_matrix.outputs.deps }} nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }} + pr_changed_source: ${{ steps.classify_pr.outputs.pr_changed_source }} steps: - name: Checkout Crate uses: actions/checkout@v4 + - name: Determine what files the PR changes. + id: classify_pr + run: contrib/classify-pr.sh ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }} - name: Read nightly version id: read_toolchain run: echo "nightly_version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT @@ -26,6 +30,7 @@ jobs: Stable: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Test - stable toolchain runs-on: ubuntu-latest strategy: @@ -47,6 +52,7 @@ jobs: Beta: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Test - beta toolchain runs-on: ubuntu-latest strategy: @@ -67,6 +73,7 @@ jobs: Nightly: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Test - nightly toolchain runs-on: ubuntu-latest strategy: @@ -91,6 +98,7 @@ jobs: MSRV: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Test - 1.56.1 toolchain runs-on: ubuntu-latest strategy: @@ -112,6 +120,8 @@ jobs: run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }} Arch32bit: + needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Test 32-bit version runs-on: ubuntu-latest steps: @@ -129,8 +139,9 @@ jobs: run: cargo test --target i686-unknown-linux-gnu Cross: + needs: Prepare + if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true' name: Cross test - if: ${{ !github.event.act }} runs-on: ubuntu-latest steps: - name: Checkout Crate @@ -146,6 +157,7 @@ jobs: Embedded: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' runs-on: ubuntu-latest env: RUSTFLAGS: "-C link-arg=-Tlink.x" @@ -171,6 +183,7 @@ jobs: ASAN: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Address sanitizer # hashes crate only. runs-on: ubuntu-latest strategy: @@ -193,6 +206,7 @@ jobs: WASM: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: WebAssembly Build # hashes crate only. runs-on: ubuntu-latest strategy: @@ -211,6 +225,7 @@ jobs: Schemars: needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' name: Schemars runs-on: ubuntu-latest strategy: @@ -228,6 +243,8 @@ jobs: run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }} Kani: + needs: Prepare + if: needs.Prepare.outputs.pr_changed_source == 'true' runs-on: ubuntu-20.04 steps: - name: 'Checkout your code.' diff --git a/contrib/classify-pr.sh b/contrib/classify-pr.sh new file mode 100755 index 00000000..e72fba5d --- /dev/null +++ b/contrib/classify-pr.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +pr_tip=$1 +master_tip=$2 + +# When called on `pull_request`, GA fails to pull down master by default. +# When called on `push`, GA fails to pull down the PR by default, only its merge commit. +# The simplest way to deal with this is to just pull both explicitly. +git fetch origin "$master_tip":master_tip +git fetch origin "$pr_tip":pr_tip + +pr_base=$(git merge-base master_tip pr_tip) + +echo "Using master $master_tip" +echo "Using PR tip $pr_tip" +echo "Using PR base $pr_base" + +# If something modifies any non-markdown file, it's considered a source code change. +if git diff --name-only "$pr_base" "$pr_tip" | grep -qv "^.md$"; then + echo "pr_changed_source=true" >> "$GITHUB_OUTPUT" +else + echo "pr_changed_source=false" >> "$GITHUB_OUTPUT" +fi +