Weekly Data Refresh #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Daily Data Refresh | |
| on: | |
| schedule: | |
| # Run at 00:00 UTC every day | |
| - cron: '0 0 * * *' | |
| # Allow manual triggering | |
| workflow_dispatch: | |
| jobs: | |
| refresh-data: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.18' | |
| cache: 'npm' | |
| - name: Create new branch | |
| run: | | |
| BRANCH_NAME="data-refresh-$(date +%Y-%m-%d)" | |
| git checkout -b $BRANCH_NAME | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Redownload mock data | |
| run: npm run redownload | |
| - name: Run tests | |
| id: tests | |
| continue-on-error: true | |
| run: npm test | |
| - name: Create issue if tests fail | |
| if: steps.tests.outcome == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: '🚨 Data Refresh Tests Failed', | |
| body: `The daily data refresh tests failed on ${new Date().toISOString().split('T')[0]}. | |
| Please check the [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.` | |
| }) | |
| - name: Delete branch if tests fail | |
| if: steps.tests.outcome == 'failure' | |
| run: | | |
| git checkout main | |
| git branch -D $BRANCH_NAME | |
| - name: Commit changes if tests pass | |
| if: steps.tests.outcome == 'success' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add tests/mocks/data/ | |
| git commit -m "chore: update mock data [skip ci]" | |
| git push origin $BRANCH_NAME | |
| - name: Create PR if tests pass | |
| if: steps.tests.outcome == 'success' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: '📦 Update mock data', | |
| body: 'This PR updates the mock data used in tests.', | |
| head: process.env.BRANCH_NAME, | |
| base: 'main' | |
| }) |