Skip to content

Commit 559a650

Browse files
update data refresh workflow
1 parent 2bd8104 commit 559a650

File tree

1 file changed

+147
-23
lines changed

1 file changed

+147
-23
lines changed
Lines changed: 147 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
name: Daily Data Refresh
1+
name: Weekly Data Refresh
22

33
on:
44
schedule:
5-
# Run at 00:00 UTC every day
5+
# Run at 00:00 UTC every Sunday
66
- cron: "0 0 * * Sun"
77
# Allow manual triggering
88
workflow_dispatch:
99

10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
issues: write
14+
1015
jobs:
11-
refresh-data:
16+
test-data:
1217
runs-on: ubuntu-latest
18+
outputs:
19+
tests-passed: ${{ steps.test.outcome == 'success' }}
20+
branch-name: ${{ steps.branch.outputs.name }}
1321

1422
steps:
1523
- name: Checkout repository
@@ -18,43 +26,159 @@ jobs:
1826
- name: Setup Node.js
1927
uses: actions/setup-node@v4
2028
with:
21-
node-version: "18.18"
29+
node-version: "22"
2230
cache: "npm"
2331

2432
- name: Create new branch
33+
id: branch
2534
run: |
2635
BRANCH_NAME="data-refresh-$(date +%Y-%m-%d)"
2736
git checkout -b $BRANCH_NAME
28-
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
37+
echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT
2938
3039
- name: Install dependencies
3140
run: npm ci
3241

3342
- name: Redownload mock data
3443
run: npm run redownload
44+
3545
- name: Run tests
36-
id: tests
46+
id: test
47+
continue-on-error: true
48+
run: npm run test
49+
50+
- name: Upload mock data
51+
if: steps.test.outcome == 'failure'
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: mock-data
55+
path: test/
56+
retention-days: 1
57+
58+
update-snapshots:
59+
runs-on: ubuntu-latest
60+
needs: test-data
61+
if: needs.test-data.outputs.tests-passed == 'false'
62+
outputs:
63+
tests-passed: ${{ steps.retest.outcome == 'success' }}
64+
65+
steps:
66+
- name: Checkout repository
67+
uses: actions/checkout@v4
68+
69+
- name: Setup Node.js
70+
uses: actions/setup-node@v4
71+
with:
72+
node-version: "22"
73+
cache: "npm"
74+
75+
- name: Checkout branch
76+
run: git checkout -b ${{ needs.test-data.outputs.branch-name }}
77+
78+
# Each job runs on a new machine, so we need to reinstall dependencies
79+
# even though we're on the same branch
80+
- name: Install dependencies
81+
run: npm ci
82+
83+
# Download the mock data from the previous job to ensure we're using
84+
#the sames data that caused the test failure
85+
- name: Download mock data
86+
uses: actions/download-artifact@v4
87+
with:
88+
name: mock-data
89+
path: test/
90+
91+
- name: Update snapshots
92+
run: npm run test:update
93+
94+
- name: Run tests again
95+
id: retest
3796
continue-on-error: true
38-
run: npm test
97+
run: npm run test
98+
99+
- name: Commit changes
100+
run: |
101+
git config user.name "github-actions[bot]"
102+
git config user.email "github-actions[bot]@users.noreply.github.com"
103+
git add .
104+
git commit -m "🤖💖 — Update snapshots after data refresh" || echo "No changes to commit"
105+
106+
- name: Push branch
107+
run: git push -u origin ${{ needs.test-data.outputs.branch-name }}
39108

40-
- name: Create issue if tests fail
41-
if: steps.tests.outcome == 'failure'
109+
create-success-pr:
110+
runs-on: ubuntu-latest
111+
needs: [test-data, update-snapshots]
112+
if: needs.update-snapshots.outputs.tests-passed == 'true'
113+
114+
steps:
115+
- name: Create Pull Request
42116
uses: actions/github-script@v7
43117
with:
44118
script: |
45-
github.rest.issues.create({
119+
const pr = await github.rest.pulls.create({
46120
owner: context.repo.owner,
47121
repo: context.repo.repo,
48-
title: '🚨 Data Refresh Tests Failed',
49-
body: `The daily data refresh tests failed on ${new Date().toISOString().split('T')[0]}.
50-
51-
Please check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.
52-
53-
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!`
54-
})
55-
56-
- name: Delete branch if tests fail
57-
if: steps.tests.outcome == 'failure'
58-
run: |
59-
git checkout main
60-
git branch -D $BRANCH_NAME
122+
title: '🔄✅ Data Refresh: Snapshot Update Complete!',
123+
head: '${{ needs.test-data.outputs.branch-name }}',
124+
base: 'main',
125+
body: `The Automatic data refresh on ${new Date().toISOString().split('T')[0]} detected changes in AO3 responses.
126+
127+
Snapshots have been updated to reflect current status. All tests are now passing! 🎉🎊🌟
128+
129+
Changes look good? ➡️ Merge this PR to update the snapshots and tests.
130+
Changes look _yikes_? ❌ Check out this PR and go get 'em! 💪🔥`
131+
});
132+
133+
create-failure-pr-and-issue:
134+
runs-on: ubuntu-latest
135+
needs: [test-data, update-snapshots]
136+
if: needs.update-snapshots.outputs.tests-passed == 'false'
137+
138+
steps:
139+
- name: Create issue for failed tests
140+
id: create-issue
141+
uses: actions/github-script@v7
142+
with:
143+
script: |
144+
const issue = await github.rest.issues.create({
145+
owner: context.repo.owner,
146+
repo: context.repo.repo,
147+
title: '🚨 Data Refresh Tests Failed After Snapshot Update',
148+
body: `The daily data refresh tests failed on ${new Date().toISOString().split('T')[0]}. Yes, even with the snapshot updates!
149+
150+
Please check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.
151+
152+
---
153+
154+
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!`
155+
});
156+
157+
return issue.data.number;
158+
159+
- name: Create Pull Request
160+
uses: actions/github-script@v7
161+
with:
162+
script: |
163+
const issueNumber = ${{ steps.create-issue.outputs.result }};
164+
165+
const pr = await github.rest.pulls.create({
166+
owner: context.repo.owner,
167+
repo: context.repo.repo,
168+
title: '🚨 HALP! Tests are failing after data refresh!',
169+
head: '${{ needs.test-data.outputs.branch-name }}',
170+
base: 'main',
171+
body: `Automatic data refresh on ${new Date().toISOString().split('T')[0]} detected changes in AO3 responses.
172+
173+
Despite our best efforts (in the form of a snapshot update), tests are still failing.
174+
175+
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! 🍀
176+
177+
Check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.
178+
179+
Closes #${issueNumber}...eventually 🤞
180+
181+
---
182+
183+
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!`
184+
});

0 commit comments

Comments
 (0)