Skip to content

Commit 646e5ac

Browse files
thpierceezhang6811
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 d7f000f commit 646e5ac

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@v3
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
@@ -100,3 +100,38 @@ jobs:
100100

101101
- name: Build with Gradle
102102
run: cd performance-tests; ./gradlew spotlessCheck
103+
104+
all-pr-checks-pass:
105+
runs-on: ubuntu-latest
106+
needs: [static-code-checks, lint, spotless, build, build-lambda]
107+
if: always()
108+
steps:
109+
- name: Checkout to get workflow file
110+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #5.0.0
111+
112+
- name: Check all jobs succeeded and none missing
113+
run: |
114+
# Check if all needed jobs succeeded
115+
results='${{ toJSON(needs) }}'
116+
if echo "$results" | jq -r '.[] | .result' | grep -v success; then
117+
echo "Some jobs failed"
118+
exit 1
119+
fi
120+
121+
# Extract all job names from workflow (excluding this gate job)
122+
all_jobs=$(yq eval '.jobs | keys | .[]' .github/workflows/pr-build.yml | grep -v "all-pr-checks-pass" | sort)
123+
124+
# Extract job names from needs array
125+
needed_jobs='${{ toJSON(needs) }}'
126+
needs_list=$(echo "$needed_jobs" | jq -r 'keys[]' | sort)
127+
128+
# Check if any jobs are missing from needs
129+
missing_jobs=$(comm -23 <(echo "$all_jobs") <(echo "$needs_list"))
130+
if [ -n "$missing_jobs" ]; then
131+
echo "ERROR: Jobs missing from needs array in all-pr-checks-pass:"
132+
echo "$missing_jobs"
133+
echo "Please add these jobs to the needs array of all-pr-checks-pass"
134+
exit 1
135+
fi
136+
137+
echo "All checks passed and no jobs missing from gate!"

0 commit comments

Comments
 (0)