Skip to content

Update Data

Update Data #16

Workflow file for this run

name: Update Data
on:
# Run weekly on Sundays at 00:00 UTC
schedule:
- cron: '0 0 * * 0'
# Allow manual trigger
workflow_dispatch:
jobs:
update-data:
name: Update Timezone Data
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Download latest data
run: |
curl -L "https://github.com/dr5hn/countries-states-cities-database/releases/latest/download/json-countries%2Bstates%2Bcities.json.gz" \
-o /tmp/countries-data.json.gz
gunzip /tmp/countries-data.json.gz
echo "Downloaded data size:"
ls -lh /tmp/countries-data.json
- name: Backup current data statistics
run: |
echo "=== Current Data Statistics ===" > /tmp/data-stats-before.txt
if [ -f src/data/timezones.json ]; then
echo "Timezones: $(grep -c '"zoneName"' src/data/timezones.json)" >> /tmp/data-stats-before.txt
echo "Data files: $(find src/data -type f | wc -l)" >> /tmp/data-stats-before.txt
else
echo "No existing data found" >> /tmp/data-stats-before.txt
fi
cat /tmp/data-stats-before.txt
- name: Generate timezone data
run: node scripts/generate-data.cjs /tmp/countries-data.json
- name: Collect new data statistics
id: data-stats
run: |
echo "=== New Data Statistics ===" > /tmp/data-stats-after.txt
echo "Timezones: $(grep -c '"zoneName"' src/data/timezones.json)" >> /tmp/data-stats-after.txt
echo "Countries: $(grep -c '"countryCode"' src/data/timezones.json | head -1)" >> /tmp/data-stats-after.txt
echo "Abbreviations: $(find src/data/abbreviations -type f -name '*.json' | wc -l)" >> /tmp/data-stats-after.txt
cat /tmp/data-stats-after.txt
# Export for PR description
TIMEZONES=$(grep -c '"zoneName"' src/data/timezones.json)
COUNTRIES=$(find src/data/countries -type f -name '*.json' | wc -l)
ABBREVIATIONS=$(find src/data/abbreviations -type f -name '*.json' | wc -l)
echo "timezones=$TIMEZONES" >> $GITHUB_OUTPUT
echo "countries=$COUNTRIES" >> $GITHUB_OUTPUT
echo "abbreviations=$ABBREVIATIONS" >> $GITHUB_OUTPUT
- name: Build and test with new data
run: |
npm run build
npm test
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Check for changes
id: check-changes
run: |
if git diff --name-only -- src/data | grep -q .; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Data changes detected"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "No data changes detected"
fi
- name: Create Pull Request
if: steps.check-changes.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update timezone data'
title: '🔄 Automated Timezone Data Update'
body: |
## Automated Timezone Data Update
This PR contains the latest timezone data from [countries-states-cities-database](https://github.com/dr5hn/countries-states-cities-database).
### Statistics
- Timezones: ${{ steps.data-stats.outputs.timezones }}
- Countries with timezones: ${{ steps.data-stats.outputs.countries }}
- Abbreviations: ${{ steps.data-stats.outputs.abbreviations }}
### Changes
- Downloaded latest dataset from source repository
- Regenerated timezone data structure
- Updated timezone abbreviations
- All tests passing ✅
### Verification
- ✅ Data generation completed successfully
- ✅ Build successful
- ✅ All tests passing
This is an automated pull request. Please review the changes before merging.
branch: automated-data-update
delete-branch: true
labels: |
automated
data-update
- name: No changes detected
if: steps.check-changes.outputs.changed == 'false'
run: |
echo "✅ Data is already up to date. No PR created."