Skip to content

Commit feb04f5

Browse files
authored
Require alerting on push and issue workflows (#45345)
1 parent 9100179 commit feb04f5

9 files changed

+32
-8
lines changed

.github/workflows/codeql.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ name: CodeQL analysis
55
# **Who does it impact**: Docs engineering.
66

77
on:
8-
push:
9-
branches:
10-
- main
118
pull_request:
129
branches:
1310
- main

.github/workflows/content-changes-table-comment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
4747
filterContentDir:
4848
needs: PR-Preview-Links
49-
if: ${{ needs.PR-Preview-Links.outputs.filterContentDir == 'true' }}
49+
if: ${{ needs.PR-Preview-Links.outputs.filterContentDir == 'true' && (github.repository == 'github/docs-internal' || github.repository == 'github/docs') }}
5050
runs-on: ubuntu-latest
5151
env:
5252
PR_NUMBER: ${{ github.event.pull_request.number }}

.github/workflows/manually-purge-fastly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
purge:
1515
runs-on: ubuntu-latest
1616

17+
if: github.repository == 'github/docs-internal'
18+
1719
steps:
1820
- name: Check out repo
1921
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

.github/workflows/move-existing-issues-to-the-correct-repo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ permissions:
1313
jobs:
1414
transfer_issues:
1515
runs-on: ubuntu-latest
16+
if: github.repository == 'github/docs-internal'
1617
steps:
1718
- id: move_to_correct_repo
1819
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975

.github/workflows/repo-sync-stalls.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ permissions:
1515

1616
jobs:
1717
repo-sync-stalls:
18+
if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
1819
runs-on: ubuntu-latest
1920
steps:
20-
- if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
21-
name: Check if repo sync is stalled
21+
- name: Check if repo sync is stalled
2222
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
2323
with:
2424
script: |

.github/workflows/secret-scanning-pattern-table-updates.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ permissions:
1818
jobs:
1919
Process-secret-scanning-PR:
2020
runs-on: ubuntu-latest
21+
if: github.repository == 'github/docs-internal'
2122
steps:
2223
- name: Check out repo
2324
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

.github/workflows/test-changed-content.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ permissions:
2121
jobs:
2222
test-changed-content:
2323
runs-on: ${{ fromJSON('["ubuntu-latest", "ubuntu-20.04-xl"]')[github.repository == 'github/docs-internal'] }}
24+
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
2425
steps:
2526
# Each of these ifs needs to be repeated at each step to make sure the required check still runs
2627
# Even if if doesn't do anything

.github/workflows/validate-asset-images.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ permissions:
1515

1616
jobs:
1717
validate-asset-images:
18+
if: ${{ github.repository == 'github/docs-internal' || github.repository == 'github/docs' }}
1819
runs-on: ubuntu-latest
1920
steps:
2021
- name: Check out repo

src/workflows/tests/actions-workflows.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ const allUsedActions = chain(workflows)
3636

3737
const scheduledWorkflows = workflows.filter(({ data }) => data.on.schedule)
3838

39+
const alertWorkflows = workflows
40+
// Only include jobs running on docs-internal
41+
.filter(({ data }) =>
42+
Object.values(data.jobs)
43+
.map((job) => job.if)
44+
.toString()
45+
.includes('docs-internal'),
46+
)
47+
// Require slack alerts on workflows that aren't actively watched at time of run
48+
.filter(({ data }) => data.on.schedule || data.on.push || data.on.issues || data.on.issue_comment)
49+
// Not including
50+
// - premerge workflows: pull_request, pull_request_target, pull_request_review, merge_group
51+
// - adhoc workflows: workflow_dispatch, workflow_run, workflow_call, repository_dispatch
52+
// to generate list, console.log(new Set(workflows.map(({ data }) => Object.keys(data.on)).flat()))
53+
3954
const dailyWorkflows = scheduledWorkflows.filter(({ data }) =>
4055
data.on.schedule.find(({ cron }) => /^20 [^*]/.test(cron)),
4156
)
@@ -73,7 +88,13 @@ describe('GitHub Actions workflows', () => {
7388
},
7489
)
7590

76-
test.each(scheduledWorkflows)(
91+
test.each(workflows)('limits repository scope $filename', ({ filename, data }) => {
92+
for (const condition of Object.values(data.jobs).map((job) => job.if)) {
93+
expect(condition).toContain('github.repository')
94+
}
95+
})
96+
97+
test.each(alertWorkflows)(
7798
'scheduled workflows slack alert on fail $filename',
7899
({ filename, data }) => {
79100
for (const [name, job] of Object.entries(data.jobs)) {
@@ -84,7 +105,7 @@ describe('GitHub Actions workflows', () => {
84105
},
85106
)
86107

87-
test.each(scheduledWorkflows)(
108+
test.each(alertWorkflows)(
88109
'performs a checkout before calling composite action $filename',
89110
({ filename, data }) => {
90111
for (const [name, job] of Object.entries(data.jobs)) {

0 commit comments

Comments
 (0)