Skip to content

Commit e2e83ca

Browse files
authored
ci(pr): add a finalizer to monitor for success (#5)
1 parent cccdf97 commit e2e83ca

File tree

2 files changed

+51
-0
lines changed
  • .github/workflows
  • {{cookiecutter.project_name|replace(" ", "")}}/.github/workflows

2 files changed

+51
-0
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: "CI"
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:
@@ -35,6 +38,8 @@ jobs:
3538
test:
3639
name: Test
3740
runs-on: ubuntu-24.04
41+
permissions:
42+
contents: write
3843
steps:
3944
- name: Checkout the repository
4045
uses: actions/checkout@v4
@@ -91,3 +96,23 @@ jobs:
9196
name: vuln-scan-results
9297
path: vulns.json
9398
if-no-files-found: error
99+
finalizer:
100+
# This gives us something to set as required in the repo settings. Some projects use dynamic fan-outs using matrix strategies and the fromJSON function, so
101+
# you can't hard-code what _should_ run vs not. Having a finalizer simplifies that so you can just check that the finalizer succeeded, and if so, your
102+
# requirements have been met
103+
# Example: https://x.com/JonZeolla/status/1877344137713766516
104+
name: Finalize the pipeline
105+
runs-on: ubuntu-24.04
106+
# Keep this aligned with the above jobs
107+
needs: [lint, test]
108+
if: always() # Ensure it runs even if "needs" fails or is cancelled
109+
steps:
110+
- name: Check for failed or cancelled jobs
111+
run: |
112+
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ||
113+
"${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
114+
echo "One or more required jobs failed or was cancelled. Marking finalizer as failed."
115+
exit 1
116+
fi
117+
- name: Finalize
118+
run: echo "Pipeline complete!"

{{cookiecutter.project_name|replace(" ", "")}}/.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: CI
33

4+
permissions:
5+
contents: read
6+
47
on:
58
pull_request:
69
branches: [main]
@@ -16,6 +19,8 @@ jobs:
1619
test:
1720
name: Test
1821
runs-on: ubuntu-24.04
22+
permissions:
23+
contents: write
1924
steps:
2025
- name: Checkout the repository
2126
uses: actions/checkout@v4
@@ -116,3 +121,24 @@ jobs:
116121
name: vulns-${{ "{{ env.SANITIZED_PLATFORM }}" }}
117122
path: vulns.*.json
118123
if-no-files-found: error
124+
finalizer:
125+
# This gives us something to set as required in the repo settings. Some projects use dynamic fan-outs using matrix strategies and the fromJSON function, so
126+
# you can't hard-code what _should_ run vs not. Having a finalizer simplifies that so you can just check that the finalizer succeeded, and if so, your
127+
# requirements have been met
128+
# Example: https://x.com/JonZeolla/status/1877344137713766516
129+
name: Finalize the pipeline
130+
runs-on: ubuntu-24.04
131+
# Keep this aligned with the above jobs
132+
needs: [lint, test, build]
133+
if: always() # Ensure it runs even if "needs" fails or is cancelled
134+
steps:
135+
- name: Check for failed or cancelled jobs
136+
run: |
137+
# Use contains() to check for any failure or cancellation
138+
if [[ "{% raw %}${{ contains(needs.*.result, 'failure') }}{% endraw %}" == "true" ||
139+
"{% raw %}${{ contains(needs.*.result, 'cancelled') }}{% endraw %}" == "true" ]]; then
140+
echo "One or more required jobs failed or was cancelled. Marking finalizer as failed."
141+
exit 1
142+
fi
143+
- name: Finalize
144+
run: echo "Pipeline complete!"

0 commit comments

Comments
 (0)