Update PER Data #31
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: Update PER Data | |
| on: | |
| schedule: | |
| # Runs at 00:00 UTC every day | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: # Allows manual trigger | |
| jobs: | |
| update-data: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.PAT_TOKEN }} | |
| persist-credentials: true | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Fetch and process data | |
| run: | | |
| npm run update-data | |
| env: | |
| # Add any required API keys or environment variables here | |
| NODE_ENV: production | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if [[ -n "$(git status --porcelain)" ]]; then | |
| echo "changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit changes if they exist | |
| if: steps.check_changes.outputs.changes == 'true' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| CURRENT_DATE=$(date -u +"%Y-%m-%d") | |
| LAST_UPDATE=$(jq -r '.lastUpdate' data/last-update.json) | |
| git add data/ | |
| git commit -m "Update PER data: ${CURRENT_DATE}" -m "Last data update: ${LAST_UPDATE}" | |
| - name: Push changes | |
| if: steps.check_changes.outputs.changes == 'true' | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ secrets.PAT_TOKEN }} | |
| branch: main | |
| force: true |