-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (65 loc) · 2.85 KB
/
Copy pathupdate-data.yml
File metadata and controls
78 lines (65 loc) · 2.85 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
name: Update Station Data
on:
# Run daily at 03:00 UTC (05:00 Berlin summer time, 04:00 winter)
schedule:
- cron: '0 3 * * *'
# Allow manual trigger from the GitHub Actions tab
workflow_dispatch:
permissions:
contents: write # needed to commit updated data files back
jobs:
update-data:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
# Use a token with write access so we can push the commit back
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- name: Install dependencies
run: npm ci
# ── Step 1: Build lines.json from the VBB HAFAS API ────────────────────
# fetch-stations.js also writes station_mappings.json (identity map,
# since stations carry their VBB stop ID natively) and qa-report.json
# (a cross-check against the Wikipedia line list). No separate mapping
# step is needed.
- name: Fetch station data from VBB API
run: node data/fetch-stations.js
timeout-minutes: 15
# ── Step 2: Commit and push only if something actually changed ─────────
- name: Check for changes
id: check_changes
run: |
git diff --quiet data/lines.json data/station_mappings.json data/qa-report.json \
&& echo "changed=false" >> "$GITHUB_OUTPUT" \
|| echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Commit updated data files
if: steps.check_changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add data/lines.json data/station_mappings.json data/qa-report.json
git commit -m "chore: auto-update station data [$(date -u +'%Y-%m-%d')]"
# The push can race with another commit landing on main (a manual
# run overlapping the schedule, or a human push). The data files are
# fully regenerated from source each run, so rebasing our commit onto
# whatever arrived is always safe. Retry a few times before failing.
for attempt in 1 2 3 4 5; do
if git push; then
echo "Pushed on attempt $attempt."
exit 0
fi
echo "Push attempt $attempt rejected — rebasing onto latest main and retrying…"
git pull --rebase --autostash origin main
sleep 5
done
echo "::error::Failed to push after 5 attempts."
exit 1
- name: No changes detected
if: steps.check_changes.outputs.changed == 'false'
run: echo "Station data is already up to date — nothing to commit."