-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (146 loc) · 5.26 KB
/
Copy pathsync-data.yml
File metadata and controls
177 lines (146 loc) · 5.26 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Sync Strava Data
on:
schedule:
# Run daily; manual sync is available from the app through workflow_dispatch.
- cron: '0 6 * * *'
workflow_dispatch:
inputs:
force_full_sync:
description: 'Force full sync (fetch all activities)'
required: false
default: 'false'
type: boolean
regenerate_maps:
description: 'Regenerate all static maps'
required: false
default: 'false'
type: boolean
permissions:
contents: write
env:
STRAVA_CLIENT_ID: ${{ secrets.STRAVA_CLIENT_ID }}
STRAVA_CLIENT_SECRET: ${{ secrets.STRAVA_CLIENT_SECRET }}
STRAVA_REFRESH_TOKEN: ${{ secrets.STRAVA_REFRESH_TOKEN }}
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
jobs:
sync-data:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
pip install requests python-dotenv
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: 'package-lock.json'
- name: Install Node.js dependencies
run: |
npm ci
- name: Create data directories
run: |
mkdir -p apps/web/data
mkdir -p apps/web/public
mkdir -p apps/web/public/maps
- name: Run Strava sync
run: |
cd scripts
python sync_strava.py
env:
FORCE_FULL_SYNC: ${{ github.event.inputs.force_full_sync }}
- name: Migrate data to SQLite
run: |
cd scripts
node migrate-strava-json.js
- name: Test Mapbox token configuration
run: |
cd scripts
python test-mapbox-token.py
env:
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
- name: Generate static maps
run: |
cd scripts
python generate-static-maps.py
env:
REGENERATE_MAPS: ${{ github.event.inputs.regenerate_maps }}
MAPBOX_TOKEN: ${{ secrets.MAPBOX_TOKEN }}
- name: Prepare database for Vercel
run: |
cd apps/web
npm run prepare-db
- name: Generate sync report
run: |
cd apps/web/data
echo "## Sync Report - $(date -u '+%Y-%m-%d %H:%M:%S UTC')" > sync-report.md
echo "" >> sync-report.md
if [ -f "strava_activities.json" ]; then
BASIC_COUNT=$(jq length strava_activities.json)
echo "- Basic activities: $BASIC_COUNT" >> sync-report.md
fi
if [ -f "strava_detailed.json" ]; then
DETAILED_COUNT=$(jq length strava_detailed.json)
echo "- Detailed activities: $DETAILED_COUNT" >> sync-report.md
fi
if [ -f "running_page_2.db" ]; then
DB_COUNT=$(sqlite3 running_page_2.db "SELECT COUNT(*) FROM activities;")
echo "- Database records: $DB_COUNT" >> sync-report.md
fi
# Map statistics
if [ -d "../public/maps" ]; then
MAP_COUNT=$(find ../public/maps -name "*.png" | wc -l)
MAP_SIZE=$(du -sh ../public/maps 2>/dev/null | cut -f1 || echo "0")
echo "- Static maps: $MAP_COUNT files ($MAP_SIZE)" >> sync-report.md
fi
echo "" >> sync-report.md
echo "Last sync: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> sync-report.md
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Add all data files with force flag to override gitignore
git add -f apps/web/data/
git add -f apps/web/public/
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
# Show what's being committed
echo "Changes to commit:"
git diff --staged --name-only
# Commit with detailed message
COMMIT_MSG="Sync Auto-sync Strava data with static maps - $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
if [ -f "apps/web/data/sync-report.md" ]; then
echo "$COMMIT_MSG" > commit_body.txt
echo "" >> commit_body.txt
cat apps/web/data/sync-report.md >> commit_body.txt
git commit -F commit_body.txt
else
git commit -m "$COMMIT_MSG"
fi
git push
- name: Summary
run: |
echo "OK Strava data sync completed successfully"
if [ -f "apps/web/data/sync-report.md" ]; then
echo "Stats Sync Report:"
cat apps/web/data/sync-report.md
fi
# Add to GitHub Actions summary
echo "## Sync Summary" >> $GITHUB_STEP_SUMMARY
echo "- **Date**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: OK Completed" >> $GITHUB_STEP_SUMMARY
if [ -f "apps/web/data/sync-report.md" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
cat apps/web/data/sync-report.md >> $GITHUB_STEP_SUMMARY
fi