Merge rust-bitcoin/rust-bitcoin#2525: ci: skip CI for things that modify only markdown files

32f9b1a231 ci: gate coverage analysis on whether source code changed (Andrew Poelstra)
2203c02347 ci: gate fuzztesting on whether source code changed (Andrew Poelstra)
09f7fc3cff ci: gate CI workflow on source being changed (Andrew Poelstra)
9aca8a18c7 ci: introduce `classify-pr.sh` script which determines whether a PR should have CI run (Andrew Poelstra)

Pull request description:

  Fixes #2523

ACKs for top commit:
  tcharding:
    ACK 32f9b1a231

Tree-SHA512: 7d53365bdf4e8ae5480221e43b4c515d4b16048ec1a00cb62ab65b2d2b91a37f8945c39b619a82bfe4ca74f3508176d9879481b908bb8d3fe8d214b173d3bf18
This commit is contained in:
Andrew Poelstra 2024-03-20 13:44:07 +00:00
commit f495bd9681
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
4 changed files with 75 additions and 3 deletions

View File

@ -5,7 +5,20 @@ on:
name: Code coverage with llvm-cov name: Code coverage with llvm-cov
jobs: 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: Coveralls:
needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Code coverage - stable toolchain name: Code coverage - stable toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:

View File

@ -9,8 +9,20 @@ on:
pull_request: pull_request:
jobs: 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: fuzz:
if: ${{ !github.event.act }} needs: Prepare
if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
@ -64,7 +76,8 @@ jobs:
path: executed_${{ matrix.fuzz_target }} path: executed_${{ matrix.fuzz_target }}
verify-execution: verify-execution:
if: ${{ !github.event.act }} needs: Prepare
if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true'
needs: fuzz needs: fuzz
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@ -14,9 +14,13 @@ jobs:
crates: ${{ steps.get_matrix.outputs.crates }} crates: ${{ steps.get_matrix.outputs.crates }}
deps: ${{ steps.get_matrix.outputs.deps }} deps: ${{ steps.get_matrix.outputs.deps }}
nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }} nightly_version: ${{ steps.read_toolchain.outputs.nightly_version }}
pr_changed_source: ${{ steps.classify_pr.outputs.pr_changed_source }}
steps: steps:
- name: Checkout Crate - name: Checkout Crate
uses: actions/checkout@v4 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 - name: Read nightly version
id: read_toolchain id: read_toolchain
run: echo "nightly_version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT run: echo "nightly_version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
@ -26,6 +30,7 @@ jobs:
Stable: Stable:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Test - stable toolchain name: Test - stable toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -47,6 +52,7 @@ jobs:
Beta: Beta:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Test - beta toolchain name: Test - beta toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -67,6 +73,7 @@ jobs:
Nightly: Nightly:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Test - nightly toolchain name: Test - nightly toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -91,6 +98,7 @@ jobs:
MSRV: MSRV:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Test - 1.56.1 toolchain name: Test - 1.56.1 toolchain
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -112,6 +120,8 @@ jobs:
run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }} run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }}
Arch32bit: Arch32bit:
needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Test 32-bit version name: Test 32-bit version
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -129,8 +139,9 @@ jobs:
run: cargo test --target i686-unknown-linux-gnu run: cargo test --target i686-unknown-linux-gnu
Cross: Cross:
needs: Prepare
if: ${{ !github.event.act }} && needs.Prepare.outputs.pr_changed_source == 'true'
name: Cross test name: Cross test
if: ${{ !github.event.act }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Crate - name: Checkout Crate
@ -146,6 +157,7 @@ jobs:
Embedded: Embedded:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
RUSTFLAGS: "-C link-arg=-Tlink.x" RUSTFLAGS: "-C link-arg=-Tlink.x"
@ -171,6 +183,7 @@ jobs:
ASAN: ASAN:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Address sanitizer # hashes crate only. name: Address sanitizer # hashes crate only.
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -193,6 +206,7 @@ jobs:
WASM: WASM:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: WebAssembly Build # hashes crate only. name: WebAssembly Build # hashes crate only.
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -211,6 +225,7 @@ jobs:
Schemars: Schemars:
needs: Prepare needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
name: Schemars name: Schemars
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
@ -228,6 +243,8 @@ jobs:
run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }} run: ./contrib/run_task.sh ${{ matrix.crate }} ${{ matrix.task }}
Kani: Kani:
needs: Prepare
if: needs.Prepare.outputs.pr_changed_source == 'true'
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: 'Checkout your code.' - name: 'Checkout your code.'

29
contrib/classify-pr.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <tip of master> <tip of PR>"
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