Skip to content

Commit 2d55c62

Browse files
AndWeHaveAPlanhitchhooker
authored andcommitted
Conditional required checks (paritytech#4544)
Workaround for skipped but `required` github checks. The idea is to trigger the workflow but filter out unaffected jobs or steps. See [ci_cd 998](https://github.com/paritytech/ci_cd/issues/988) for details In `.github/workflows/check-changed-files.yml` there is a reusable workflow thad does all the checks and publishes results as outputs. Example usage: ``` jobs: changes: permissions: pull-requests: read uses: ./.github/workflows/check-changed-files.yml some-job: needs: changes if: ${{ needs.changes.outputs.rust }} ....... ```
1 parent 7543f8a commit 2d55c62

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Reusable workflow to perform checks and generate conditions for other workflows.
2+
# Currently it checks if any Rust (build-related) file is changed
3+
# and if the current (caller) workflow file is changed.
4+
# Example:
5+
#
6+
# jobs:
7+
# changes:
8+
# permissions:
9+
# pull-requests: read
10+
# uses: ./.github/workflows/check-changed-files.yml
11+
# some-job:
12+
# needs: changes
13+
# if: ${{ needs.changes.outputs.rust }}
14+
# .......
15+
16+
name: Check changes files
17+
18+
on:
19+
workflow_call:
20+
# Map the workflow outputs to job outputs
21+
outputs:
22+
rust:
23+
value: ${{ jobs.changes.outputs.rust }}
24+
description: 'true if any of the build-related OR current (caller) workflow files have changed'
25+
current-workflow:
26+
value: ${{ jobs.changes.outputs.current-workflow }}
27+
description: 'true if current (caller) workflow file has changed'
28+
29+
jobs:
30+
changes:
31+
runs-on: ubuntu-latest
32+
permissions:
33+
pull-requests: read
34+
outputs:
35+
# true if current workflow (caller) file is changed
36+
rust: ${{ steps.filter.outputs.rust == 'true' || steps.filter.outputs.current-workflow == 'true' }}
37+
current-workflow: ${{ steps.filter.outputs.current-workflow }}
38+
steps:
39+
- id: current-file
40+
run: echo "current-workflow-file=$(echo ${{ github.workflow_ref }} | sed -nE "s/.*(\.github\/workflows\/[a-zA-Z0-9_-]*\.y[a]?ml)@refs.*/\1/p")" >> $GITHUB_OUTPUT
41+
- run: echo "${{ steps.current-file.outputs.current-workflow-file }}"
42+
# For pull requests it's not necessary to checkout the code
43+
- id: filter
44+
uses: dorny/paths-filter@v3
45+
with:
46+
predicate-quantifier: 'every'
47+
# current-workflow - check if the current (caller) workflow file is changed
48+
# rust - check if any Rust (build-related) file is changed
49+
filters: |
50+
current-workflow:
51+
- '${{ steps.current-file.outputs.current-workflow-file }}'
52+
rust:
53+
- '**/*'
54+
- '!.github/**/*'
55+
- '!prdoc/**/*'
56+
- '!docs/**/*'
57+
#

.github/workflows/tests-linux-stable.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@ env:
2020
FORKLIFT_metrics_pushEndpoint: ${{ secrets.FORKLIFT_metrics_pushEndpoint }}
2121

2222
jobs:
23+
24+
changes:
25+
permissions:
26+
pull-requests: read
27+
uses: ./.github/workflows/check-changed-files.yml
28+
2329
set-image:
2430
# GitHub Actions allows using 'env' in a container context.
2531
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
2632
# This workaround sets the container image for each job using 'set-image' job output.
33+
needs: changes
34+
if: ${{ needs.changes.outputs.rust }}
2735
runs-on: ubuntu-latest
2836
outputs:
2937
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
@@ -32,10 +40,12 @@ jobs:
3240
uses: actions/checkout@v4
3341
- id: set_image
3442
run: cat .github/env >> $GITHUB_OUTPUT
43+
3544
test-linux-stable-int:
45+
needs: [set-image, changes]
46+
if: ${{ needs.changes.outputs.rust }}
3647
runs-on: arc-runners-polkadot-sdk-beefy
3748
timeout-minutes: 30
38-
needs: [set-image]
3949
container:
4050
image: ${{ needs.set-image.outputs.IMAGE }}
4151
env:
@@ -50,11 +60,13 @@ jobs:
5060
uses: actions/checkout@v4
5161
- name: script
5262
run: WASM_BUILD_NO_COLOR=1 time forklift cargo test -p staging-node-cli --release --locked -- --ignored
63+
5364
# https://github.com/paritytech/ci_cd/issues/864
5465
test-linux-stable-runtime-benchmarks:
66+
needs: [set-image, changes]
67+
if: ${{ needs.changes.outputs.rust }}
5568
runs-on: arc-runners-polkadot-sdk-beefy
5669
timeout-minutes: 30
57-
needs: [set-image]
5870
container:
5971
image: ${{ needs.set-image.outputs.IMAGE }}
6072
env:

.github/workflows/tests.yml

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ env:
1919
FORKLIFT_metrics_pushEndpoint: ${{ secrets.FORKLIFT_metrics_pushEndpoint }}
2020

2121
jobs:
22+
23+
changes:
24+
permissions:
25+
pull-requests: read
26+
uses: ./.github/workflows/check-changed-files.yml
27+
2228
set-image:
2329
# GitHub Actions allows using 'env' in a container context.
2430
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
@@ -31,10 +37,12 @@ jobs:
3137
uses: actions/checkout@v4
3238
- id: set_image
3339
run: cat .github/env >> $GITHUB_OUTPUT
40+
3441
quick-benchmarks:
42+
needs: [set-image, changes]
43+
if: ${{ needs.changes.outputs.rust }}
3544
runs-on: arc-runners-polkadot-sdk-beefy
3645
timeout-minutes: 30
37-
needs: [set-image]
3846
container:
3947
image: ${{ needs.set-image.outputs.IMAGE }}
4048
env:
@@ -47,11 +55,13 @@ jobs:
4755
uses: actions/checkout@v4
4856
- name: script
4957
run: time forklift cargo run --locked --release -p staging-node-cli --bin substrate-node --features runtime-benchmarks -- benchmark pallet --chain dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --quiet
58+
5059
# cf https://github.com/paritytech/polkadot-sdk/issues/1652
5160
test-syscalls:
61+
needs: [set-image, changes]
62+
if: ${{ needs.changes.outputs.rust }}
5263
runs-on: arc-runners-polkadot-sdk-beefy
5364
timeout-minutes: 30
54-
needs: [set-image]
5565
container:
5666
image: ${{ needs.set-image.outputs.IMAGE }}
5767
continue-on-error: true # this rarely triggers in practice
@@ -71,10 +81,12 @@ jobs:
7181
# - if [[ "$CI_JOB_STATUS" == "failed" ]]; then
7282
# printf "The x86_64 syscalls used by the worker binaries have changed. Please review if this is expected and update polkadot/scripts/list-syscalls/*-worker-syscalls as needed.\n";
7383
# fi
84+
7485
cargo-check-all-benches:
86+
needs: [set-image, changes]
87+
if: ${{ needs.changes.outputs.rust }}
7588
runs-on: arc-runners-polkadot-sdk-beefy
7689
timeout-minutes: 30
77-
needs: [set-image]
7890
container:
7991
image: ${{ needs.set-image.outputs.IMAGE }}
8092
env:

0 commit comments

Comments
 (0)