Sync Activities (Legacy SQLite) #65
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: Sync Activities | |
| on: | |
| schedule: | |
| # 每天北京时间早上 8 点运行(UTC 0:00) | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: # 允许手动触发 | |
| permissions: | |
| contents: write # 允许写入仓库内容 | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} | |
| # 使用 PAT (Personal Access Token) 以获得推送权限 | |
| # 如果没有设置 PAT,则回退到默认的 GITHUB_TOKEN | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Run sync script | |
| env: | |
| DATABASE_URL: file:./data/activities.db | |
| STRAVA_CLIENT_ID: ${{ secrets.STRAVA_CLIENT_ID }} | |
| STRAVA_CLIENT_SECRET: ${{ secrets.STRAVA_CLIENT_SECRET }} | |
| STRAVA_REFRESH_TOKEN: ${{ secrets.STRAVA_REFRESH_TOKEN }} | |
| run: bun run sync | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if git diff --quiet data/activities.db; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add data/activities.db | |
| git commit -m "chore: Update activities database" | |
| git push |