Skip to content

Commit c3aec08

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 2107713 commit c3aec08

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
@@ -218,3 +218,37 @@ jobs:
218218
working-directory: lambda-layer
219219
run: ./build-layer.sh
220220

221+
all-pr-checks-pass:
222+
runs-on: ubuntu-latest
223+
needs: [changelog-check, testpatch, build, build-lambda]
224+
if: always()
225+
steps:
226+
- name: Checkout to get workflow file
227+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
228+
229+
- name: Check all jobs succeeded and none missing
230+
run: |
231+
# Check if all needed jobs succeeded
232+
results='${{ toJSON(needs) }}'
233+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
234+
echo "Some jobs failed"
235+
exit 1
236+
fi
237+
238+
# Extract all job names from workflow (excluding this gate job)
239+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/pr-build.yml | grep -v "all-pr-checks-pass" | sort)
240+
241+
# Extract job names from needs array
242+
needed_jobs='${{ toJSON(needs) }}'
243+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
244+
245+
# Check if any jobs are missing from needs
246+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
247+
if [ -n "$missing_jobs" ]; then
248+
echo "ERROR: Jobs missing from needs array in all-pr-checks-pass:"
249+
echo "$missing_jobs"
250+
echo "Please add these jobs to the needs array of all-pr-checks-pass"
251+
exit 1
252+
fi
253+
254+
echo "All checks passed and no jobs missing from gate!"

0 commit comments

Comments
 (0)