Skip to content

Commit fe245aa

Browse files
authored
feat: selective versions.yml workflow triggering with guard jobs (#192)
feat: add selective versions.yml workflow triggering with guard jobs Add a check-version-keys composite action that gates expensive test jobs when versions.yml changes. The guard auto-detects which keys each workflow uses by parsing yq calls in the workflow file — no manual key list to maintain. Workflows only run their test job when a relevant key actually changed; unrelated versions.yml edits are skipped. Includes fixes for runtime-upgrades spec_version polling retries and polkadot_js_util_crypto version alignment.
1 parent 533a2e2 commit fe245aa

27 files changed

+482
-67
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: 'Check Version Keys'
2+
description: 'Check if specific versions.yml keys changed to decide whether a workflow should run. Keys are auto-detected from yq calls in the calling workflow file.'
3+
4+
inputs:
5+
base-sha:
6+
description: 'Base commit SHA for comparison'
7+
required: true
8+
head-sha:
9+
description: 'Head commit SHA for comparison'
10+
required: true
11+
event-name:
12+
description: 'GitHub event name (push, pull_request, workflow_dispatch)'
13+
required: true
14+
15+
outputs:
16+
should-run:
17+
description: '"true" if the workflow should run, "false" if it can be skipped'
18+
value: ${{ steps.check.outputs.should-run }}
19+
20+
runs:
21+
using: 'composite'
22+
steps:
23+
- id: check
24+
shell: bash
25+
run: |
26+
EVENT="${{ inputs.event-name }}"
27+
BASE_SHA="${{ inputs.base-sha }}"
28+
29+
# Always run on workflow_dispatch or if base SHA is missing
30+
if [ "$EVENT" = "workflow_dispatch" ] || [ -z "$BASE_SHA" ]; then
31+
echo "should-run=true" >> "$GITHUB_OUTPUT"
32+
echo "Always run: event=$EVENT base_sha=$BASE_SHA"
33+
exit 0
34+
fi
35+
36+
# Check if versions.yml is in the diff
37+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "${{ inputs.head-sha }}" 2>/dev/null || true)
38+
39+
if ! echo "$CHANGED_FILES" | grep -q '^versions\.yml$'; then
40+
# versions.yml not changed — triggered by harness file changes, always run
41+
echo "should-run=true" >> "$GITHUB_OUTPUT"
42+
echo "Always run: versions.yml not in diff"
43+
exit 0
44+
fi
45+
46+
# Auto-detect keys from the calling workflow file
47+
WORKFLOW_FILE=".github/workflows/$(echo "$GITHUB_WORKFLOW_REF" | sed -n 's|.*\.github/workflows/\(.*\)@.*|\1|p')"
48+
echo "Detected workflow file: $WORKFLOW_FILE"
49+
50+
if [ ! -f "$WORKFLOW_FILE" ]; then
51+
echo "should-run=true" >> "$GITHUB_OUTPUT"
52+
echo "Always run: could not locate workflow file"
53+
exit 0
54+
fi
55+
56+
KEYS=$(grep -oP "yq\s+'(\.[^']+)'\s+versions\.yml" "$WORKFLOW_FILE" | grep -oP "'\.[^']+'" | tr -d "'" | sort -u | tr '\n' ' ')
57+
echo "Auto-detected keys: $KEYS"
58+
59+
if [ -z "$KEYS" ]; then
60+
echo "should-run=true" >> "$GITHUB_OUTPUT"
61+
echo "Always run: no version keys detected in workflow"
62+
exit 0
63+
fi
64+
65+
# versions.yml changed — check if any of the specific keys changed
66+
git fetch origin "$BASE_SHA" --depth=1 2>/dev/null || true
67+
OLD_FILE=$(git show "$BASE_SHA":versions.yml 2>/dev/null || echo "")
68+
69+
if [ -z "$OLD_FILE" ]; then
70+
# Can't get old file (new file or shallow clone issue) — run to be safe
71+
echo "should-run=true" >> "$GITHUB_OUTPUT"
72+
echo "Always run: could not retrieve old versions.yml"
73+
exit 0
74+
fi
75+
76+
for KEY in $KEYS; do
77+
OLD_VAL=$(echo "$OLD_FILE" | yq "$KEY" 2>/dev/null || echo "")
78+
NEW_VAL=$(yq "$KEY" versions.yml 2>/dev/null || echo "")
79+
if [ "$OLD_VAL" != "$NEW_VAL" ]; then
80+
echo "should-run=true" >> "$GITHUB_OUTPUT"
81+
echo "Key changed: $KEY ($OLD_VAL -> $NEW_VAL)"
82+
exit 0
83+
fi
84+
echo "Key unchanged: $KEY ($OLD_VAL)"
85+
done
86+
87+
echo "should-run=false" >> "$GITHUB_OUTPUT"
88+
echo "No relevant keys changed, skipping"

.github/workflows/migration-revm-uniswap-v2-core.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ on:
1313
workflow_dispatch:
1414

1515
jobs:
16-
test:
16+
guard:
1717
if: github.repository == 'polkadot-developers/polkadot-cookbook'
1818
runs-on: ubuntu-latest
19+
outputs:
20+
should-run: ${{ steps.check.outputs.should-run }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
- id: check
24+
uses: ./.github/actions/check-version-keys
25+
with:
26+
event-name: ${{ github.event_name }}
27+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
28+
head-sha: ${{ github.sha }}
29+
30+
test:
31+
needs: guard
32+
if: needs.guard.outputs.should-run == 'true'
33+
runs-on: ubuntu-latest
1934

2035
steps:
2136
- uses: actions/checkout@v4

.github/workflows/migration-revm-uniswap-v2-periphery.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ on:
1313
workflow_dispatch:
1414

1515
jobs:
16-
test:
16+
guard:
1717
if: github.repository == 'polkadot-developers/polkadot-cookbook'
1818
runs-on: ubuntu-latest
19+
outputs:
20+
should-run: ${{ steps.check.outputs.should-run }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
- id: check
24+
uses: ./.github/actions/check-version-keys
25+
with:
26+
event-name: ${{ github.event_name }}
27+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
28+
head-sha: ${{ github.sha }}
29+
30+
test:
31+
needs: guard
32+
if: needs.guard.outputs.should-run == 'true'
33+
runs-on: ubuntu-latest
1934

2035
steps:
2136
- uses: actions/checkout@v4

.github/workflows/polkadot-docs-add-existing-pallets.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -99,8 +114,8 @@ jobs:
99114
timeout-minutes: 60
100115

101116
post-test:
102-
needs: test
103-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
117+
needs: [guard, test]
118+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
104119
uses: ./.github/workflows/post-cleanup.yml
105120
with:
106121
test_result: ${{ needs.test.result }}

.github/workflows/polkadot-docs-add-pallet-instances.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -100,8 +115,8 @@ jobs:
100115
timeout-minutes: 60
101116

102117
post-test:
103-
needs: test
104-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
118+
needs: [guard, test]
119+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
105120
uses: ./.github/workflows/post-cleanup.yml
106121
with:
107122
test_result: ${{ needs.test.result }}

.github/workflows/polkadot-docs-benchmark-pallet.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -80,8 +95,8 @@ jobs:
8095
timeout-minutes: 45
8196

8297
post-test:
83-
needs: test
84-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
98+
needs: [guard, test]
99+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
85100
uses: ./.github/workflows/post-cleanup.yml
86101
with:
87102
test_result: ${{ needs.test.result }}

.github/workflows/polkadot-docs-channels-between-parachains.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -127,8 +142,8 @@ jobs:
127142
pkill -f 'zombienet' 2>/dev/null || true
128143
129144
post-test:
130-
needs: test
131-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
145+
needs: [guard, test]
146+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
132147
uses: ./.github/workflows/post-cleanup.yml
133148
with:
134149
test_result: ${{ needs.test.result }}

.github/workflows/polkadot-docs-channels-with-system-parachains.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -128,8 +143,8 @@ jobs:
128143
pkill -f 'zombienet' 2>/dev/null || true
129144
130145
post-test:
131-
needs: test
132-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
146+
needs: [guard, test]
147+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
133148
uses: ./.github/workflows/post-cleanup.yml
134149
with:
135150
test_result: ${{ needs.test.result }}

.github/workflows/polkadot-docs-create-a-pallet.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,24 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18-
test:
18+
guard:
1919
if: github.repository == 'polkadot-developers/polkadot-cookbook'
2020
runs-on: ubuntu-latest
21+
outputs:
22+
should-run: ${{ steps.check.outputs.should-run }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
- id: check
26+
uses: ./.github/actions/check-version-keys
27+
with:
28+
event-name: ${{ github.event_name }}
29+
base-sha: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
30+
head-sha: ${{ github.sha }}
31+
32+
test:
33+
needs: guard
34+
if: needs.guard.outputs.should-run == 'true'
35+
runs-on: ubuntu-latest
2136

2237
steps:
2338
- uses: actions/checkout@v4
@@ -100,8 +115,8 @@ jobs:
100115
timeout-minutes: 60
101116

102117
post-test:
103-
needs: test
104-
if: github.repository == 'polkadot-developers/polkadot-cookbook' && always() && github.ref == 'refs/heads/master'
118+
needs: [guard, test]
119+
if: github.repository == 'polkadot-developers/polkadot-cookbook' && needs.guard.outputs.should-run == 'true' && always() && github.ref == 'refs/heads/master'
105120
uses: ./.github/workflows/post-cleanup.yml
106121
with:
107122
test_result: ${{ needs.test.result }}

0 commit comments

Comments
 (0)