-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (111 loc) · 4.69 KB
/
update-data.yml
File metadata and controls
132 lines (111 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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://raw.githubusercontent.com/dr5hn/countries-states-cities-database/refs/heads/master/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: |
git add src/data
if git diff --cached --quiet; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No data changes detected"
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "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."