-
Notifications
You must be signed in to change notification settings - Fork 7
203 lines (192 loc) · 6.42 KB
/
update-known-good.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Update Known Good Block Numbers
on:
workflow_dispatch:
inputs:
retry:
description: 'If this is a retry run'
required: false
type: boolean
failed_tests:
description: 'Failed tests to retry (JSON array)'
required: false
type: string
schedule:
- cron: '0 */6 * * *'
env:
GH_TOKEN: ${{ github.token }}
permissions:
contents: write
pull-requests: write
actions: write
issues: write
jobs:
define-matrix:
runs-on: ubuntu-latest
outputs:
tests: ${{ steps.tests.outputs.tests }}
steps:
- uses: actions/checkout@v4
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- name: Define Tests
id: tests
run: |
if [ "${{ github.event.inputs.retry }}" == "true" ]; then
echo "tests=$(echo '${{ github.event.inputs.failed_tests }}' | sed 's/^"\(.*\)"$/\1/')" >> "$GITHUB_OUTPUT"
else
echo tests=$(cd packages && ls */src/*.test.ts | jq -R -s -c 'split("\n")[:-1]') >> "$GITHUB_OUTPUT"
fi
- name: Update Known Good Block Numbers
run: |
yarn update-known-good
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: KNOWN_GOOD_BLOCK_NUMBERS.env
path: KNOWN_GOOD_BLOCK_NUMBERS.env
retention-days: 1
tests:
needs: define-matrix
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
tests: ${{ fromJSON(needs.define-matrix.outputs.tests) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: KNOWN_GOOD_BLOCK_NUMBERS.env
- run: yarn test packages/${{ matrix.tests }}
save:
needs: tests
runs-on: ubuntu-latest
if: success() && github.event.inputs.retry != 'true'
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: KNOWN_GOOD_BLOCK_NUMBERS.env
- name: Commit and push changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add KNOWN_GOOD_BLOCK_NUMBERS.env
if ! git diff --cached --quiet; then
git commit -m "[ci skip] Update KNOWN_GOOD_BLOCK_NUMBERS"
git push
else
echo "No changes to commit"
fi
schedule-retry:
needs: tests
if: failure() && github.event.inputs.retry != 'true'
runs-on: ubuntu-latest
steps:
- name: Get failed jobs
id: get-failed
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
});
const failedTests = response.data.jobs
.filter(job => job.name.startsWith('tests (') && job.conclusion === 'failure')
.map(job => {
const match = job.name.match(/tests \((.*)\)/);
return match ? match[1] : null;
})
.filter(Boolean);
return JSON.stringify(failedTests);
- name: sleep
run: sleep 300
- name: Dispatch retry workflow
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'update-known-good.yml',
ref: 'master',
inputs: {
retry: 'true',
failed_tests: '${{ steps.get-failed.outputs.result }}'
}
})
notify:
needs: tests
if: failure() && github.event.inputs.retry == 'true'
runs-on: ubuntu-latest
steps:
- name: Create Comment
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
});
const failedTests = response.data.jobs
.filter(job => job.name.startsWith('tests (') && job.conclusion === 'failure')
.map(job => {
const match = job.name.match(/tests \((.*)\)/);
return match ? match[1] : null;
})
.filter(Boolean);
const impactedNetworks = new Set()
const regex = /(\w+)\.(\w+)?(\.\w+)?\.test/
for (const test of failedTests) {
const match = test.match(regex)
if (match) {
impactedNetworks.add(match[1])
if (match[2]) {
impactedNetworks.add(match[2])
}
} else {
impactedNetworks.add("unknown")
}
}
const { data: config } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: '.github/workflows/notifications.json',
ref: 'master'
})
const notifications = JSON.parse(Buffer.from(config.content, 'base64').toString('utf8'))
for (const network of impactedNetworks) {
const issueNumber = notifications[network]
if (issueNumber) {
// add a comment to the issue
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Workflow failed: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
})
}
}