-
-
Notifications
You must be signed in to change notification settings - Fork 18
206 lines (166 loc) Β· 7.12 KB
/
Copy pathdata-refresh.yaml
File metadata and controls
206 lines (166 loc) Β· 7.12 KB
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
204
205
206
name: Weekly Data Refresh
on:
schedule:
# Run at 02:00 UTC every Sunday
- cron: "0 2 * * Sun"
# Allow manual triggering
workflow_dispatch:
permissions:
contents: write
pull-requests: write
issues: write
jobs:
test-data:
runs-on: ubuntu-latest
outputs:
tests-passed: ${{ (steps.test.outcome == 'success' && 'true') || 'false' }}
branch-name: ${{ steps.branch.outputs.name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
- name: Create new branch
id: branch
run: |
BRANCH_NAME="data-refresh-$(date +%Y-%m-%d)"
git checkout -b $BRANCH_NAME
echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Install dependencies
run: npm ci
- name: Redownload mock data
run: npm run redownload
- name: Run tests
id: test
continue-on-error: true
run: npm run test
- name: Upload mock data
if: steps.test.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: mock-data
path: tests/mocks/data/
retention-days: 1
if-no-files-found: error
update-snapshots:
runs-on: ubuntu-latest
needs: test-data
# TODO: this is a workaround to allow the job to continue even if the tests fail so
# we can post the outcome of the job in case of failure but it will show the job as successful
# even if the tests fail. We should figure out how to do this without continuing on error.
continue-on-error: true
if: ${{ needs.test-data.outputs.tests-passed == 'false' }}
outputs:
tests-passed: ${{ (steps.retest.outcome == 'success' && 'true') || 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
- name: Checkout branch
run: git checkout -b ${{ needs.test-data.outputs.branch-name }}
# Each job runs on a new machine, so we need to reinstall dependencies
# even though we're on the same branch
- name: Install dependencies
run: npm ci
# Download the mock data from the previous job to ensure we're using
# the same data that caused the test failure
- name: Download mock data
uses: actions/download-artifact@v4
with:
name: mock-data
path: tests/mocks/data/
- name: Update snapshots
# TODO: check if we need the next step or we can just run this one instead
continue-on-error: true
run: npm run test:update
- name: Run tests again
id: retest
continue-on-error: true
run: npm run test
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "π€π β Update snapshots after data refresh" || echo "No changes to commit"
- name: Push branch
run: git push -u origin ${{ needs.test-data.outputs.branch-name }}
create-success-pr:
runs-on: ubuntu-latest
needs: [test-data, update-snapshots]
if: ${{ needs.update-snapshots.outputs.tests-passed == 'true' }}
steps:
- name: Create Pull Request
uses: actions/github-script@v7
with:
script: |
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'πβ
Data Refresh: Snapshot Update Complete!',
head: '${{ needs.test-data.outputs.branch-name }}',
base: 'main',
body: `The Automatic data refresh on ${new Date().toISOString().split('T')[0]} detected changes in AO3 responses.
Snapshots have been updated to reflect current status. All tests are now passing! πππ
Changes look good? β‘οΈ Merge this PR to update the snapshots and tests.
Changes look _yikes_? β Check out this PR and go get 'em! πͺπ₯`
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.data.number,
labels: ['data-refresh']
});
create-failure-pr-and-issue:
runs-on: ubuntu-latest
needs: [test-data, update-snapshots]
if: ${{ needs.update-snapshots.outputs.tests-passed == 'false' }}
steps:
- name: Create issue for failed tests
id: create-issue
uses: actions/github-script@v7
with:
script: |
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'π¨ Data Refresh Tests Failed After Snapshot Update',
body: `The daily data refresh tests failed on ${new Date().toISOString().split('T')[0]}. Yes, even with the snapshot updates!
Please check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.
---
Want to learn more about this issue and help us fix it? Check out the [README](https://github.com/FujoWebDev/AO3.js/blob/main/README.md#about--data-refresh-tests-failed-issues) for more information!`
});
return issue.data.number;
- name: Create Pull Request
uses: actions/github-script@v7
with:
script: |
const issueNumber = ${{ steps.create-issue.outputs.result }};
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'π¨ HALP! Tests are failing after data refresh!',
head: '${{ needs.test-data.outputs.branch-name }}',
base: 'main',
body: `Automatic data refresh on ${new Date().toISOString().split('T')[0]} detected changes in AO3 responses.
Despite our best efforts (in the form of a snapshot update), tests are still failing.
Manual investigation is required ππ΅οΈ To help you get started, we've created this PR with the already-updated data. May the bugs be ever in your favor! π
Check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.
Closes #${issueNumber}...eventually π€
---
Want to learn more about this issue and help us fix it? Check out the [README](https://github.com/FujoWebDev/AO3.js/blob/main/README.md#about--data-refresh-tests-failed-issues) for more information!`
});
// Add label to the PR for easy identification
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.data.number,
labels: ['data-refresh']
});