Skip to content

Commit abfb4d5

Browse files
thpiercejj22ee
authored andcommitted
feat: add self-validating workflow gate jobs (aws-observability#477)
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: * Confirmed if even one subjob in a matrix fails, the job fails: [PASS](https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/17930014615/job/50985189015?pr=477) * lint(lint) passes, but lint (spellcheck) fails, and all-pr-checks-pass fails. * Confirmed if a job is missing, the job fails: [PASS](https://github.com/aws-observability/aws-otel-python-instrumentation/actions/runs/17930365916/job/50986188220?pr=477) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent fa9b8fd commit abfb4d5

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,38 @@ jobs:
9595
uses: github/codeql-action/analyze@16df4fbc19aea13d921737861d6c622bf3cefe23 #v2.23.0
9696
with:
9797
category: "/language:${{matrix.language}}"
98+
99+
all-codeql-checks-pass:
100+
runs-on: ubuntu-latest
101+
needs: [analyze]
102+
if: always()
103+
steps:
104+
- name: Checkout to get workflow file
105+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
106+
107+
- name: Check all jobs succeeded and none missing
108+
run: |
109+
# Check if all needed jobs succeeded
110+
results='${{ toJSON(needs) }}'
111+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
112+
echo "Some jobs failed"
113+
exit 1
114+
fi
115+
116+
# Extract all job names from workflow (excluding this gate job)
117+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/codeql.yml | grep -v "all-codeql-checks-pass" | sort)
118+
119+
# Extract job names from needs array
120+
needed_jobs='${{ toJSON(needs) }}'
121+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
122+
123+
# Check if any jobs are missing from needs
124+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
125+
if [ -n "$missing_jobs" ]; then
126+
echo "ERROR: Jobs missing from needs array in all-codeql-checks-pass:"
127+
echo "$missing_jobs"
128+
echo "Please add these jobs to the needs array of all-codeql-checks-pass"
129+
exit 1
130+
fi
131+
132+
echo "All CodeQL checks passed and no jobs missing from gate!"

.github/workflows/pr-build.yml

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

156156
- name: Build with Gradle
157157
run: cd performance-tests; ./gradlew spotlessCheck
158+
159+
all-pr-checks-pass:
160+
runs-on: ubuntu-latest
161+
needs: [static-code-checks, lint, spotless, build, build-lambda]
162+
if: always()
163+
steps:
164+
- name: Checkout to get workflow file
165+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
166+
167+
- name: Check all jobs succeeded and none missing
168+
run: |
169+
# Check if all needed jobs succeeded
170+
results='${{ toJSON(needs) }}'
171+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
172+
echo "Some jobs failed"
173+
exit 1
174+
fi
175+
176+
# Extract all job names from workflow (excluding this gate job)
177+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/pr-build.yml | grep -v "all-pr-checks-pass" | sort)
178+
179+
# Extract job names from needs array
180+
needed_jobs='${{ toJSON(needs) }}'
181+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
182+
183+
# Check if any jobs are missing from needs
184+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
185+
if [ -n "$missing_jobs" ]; then
186+
echo "ERROR: Jobs missing from needs array in all-pr-checks-pass:"
187+
echo "$missing_jobs"
188+
echo "Please add these jobs to the needs array of all-pr-checks-pass"
189+
exit 1
190+
fi
191+
192+
echo "All checks passed and no jobs missing from gate!"

0 commit comments

Comments
 (0)