Skip to content

Commit b48ad59

Browse files
thpiercejj22ee
authored andcommitted
feat: add self-validating workflow gate jobs (#1213)
Add gate jobs that fail if any workflow job fails OR if any job is missing from the gate's needs array. Prevents both job failures and configuration drift when adding new workflow jobs. Callout: I don't think it's possible to have one gate for both workflows, but it should not be the case that we add more over time. ### Testing: See: aws-observability/aws-otel-python-instrumentation#477 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3548cc8 commit b48ad59

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,38 @@ jobs:
6060

6161
- name: Perform CodeQL Analysis
6262
uses: github/codeql-action/analyze@16df4fbc19aea13d921737861d6c622bf3cefe23 #v3.30.3
63+
64+
all-codeql-checks-pass:
65+
runs-on: ubuntu-latest
66+
needs: [analyze]
67+
if: always()
68+
steps:
69+
- name: Checkout to get workflow file
70+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
71+
72+
- name: Check all jobs succeeded and none missing
73+
run: |
74+
# Check if all needed jobs succeeded
75+
results='${{ toJSON(needs) }}'
76+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
77+
echo "Some jobs failed"
78+
exit 1
79+
fi
80+
81+
# Extract all job names from workflow (excluding this gate job)
82+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/codeql.yml | grep -v "all-codeql-checks-pass" | sort)
83+
84+
# Extract job names from needs array
85+
needed_jobs='${{ toJSON(needs) }}'
86+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
87+
88+
# Check if any jobs are missing from needs
89+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
90+
if [ -n "$missing_jobs" ]; then
91+
echo "ERROR: Jobs missing from needs array in all-codeql-checks-pass:"
92+
echo "$missing_jobs"
93+
echo "Please add these jobs to the needs array of all-codeql-checks-pass"
94+
exit 1
95+
fi
96+
97+
echo "All CodeQL checks passed and no jobs missing from gate!"

.github/workflows/pr-build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,37 @@ jobs:
176176
working-directory: lambda-layer
177177
run: ./build-layer.sh
178178

179+
all-pr-checks-pass:
180+
runs-on: ubuntu-latest
181+
needs: [changelog-check, testpatch, build, build-lambda]
182+
if: always()
183+
steps:
184+
- name: Checkout to get workflow file
185+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
186+
187+
- name: Check all jobs succeeded and none missing
188+
run: |
189+
# Check if all needed jobs succeeded
190+
results='${{ toJSON(needs) }}'
191+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
192+
echo "Some jobs failed"
193+
exit 1
194+
fi
195+
196+
# Extract all job names from workflow (excluding this gate job)
197+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/pr-build.yml | grep -v "all-pr-checks-pass" | sort)
198+
199+
# Extract job names from needs array
200+
needed_jobs='${{ toJSON(needs) }}'
201+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
202+
203+
# Check if any jobs are missing from needs
204+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
205+
if [ -n "$missing_jobs" ]; then
206+
echo "ERROR: Jobs missing from needs array in all-pr-checks-pass:"
207+
echo "$missing_jobs"
208+
echo "Please add these jobs to the needs array of all-pr-checks-pass"
209+
exit 1
210+
fi
211+
212+
echo "All checks passed and no jobs missing from gate!"

0 commit comments

Comments
 (0)