Daily Data Refresh #16
This file contains 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 |