Strava Sync #12490
This file contains 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: Strava Sync | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 */3 * * *' | |
push: | |
branches: | |
- main | |
paths: | |
- scripts/strava_sync.py | |
- scripts/gen_svg.py | |
- scripts/gpx_sync.py | |
- scripts/garmin_sync.py | |
- scripts/fit_to_garmin_sync.py | |
- scripts/strava_to_garmin_sync.py | |
- requirements.txt | |
env: | |
RUN_TYPE: strava | |
ATHLETE: DuanFei | |
TITLE: Running Data | |
MIN_GRID_DISTANCE: 10 # change min distance here | |
TITLE_GRID: Over 5km Runs | |
GITHUB_NAME: shaonianche | |
GITHUB_EMAIL: [email protected] | |
jobs: | |
sync: | |
name: Sync | |
runs-on: ubuntu-latest | |
outputs: | |
SAVE_DATA_IN_GITHUB_CACHE: ${{ steps.set_output.outputs.SAVE_DATA_IN_GITHUB_CACHE }} | |
DATA_CACHE_PREFIX: ${{ steps.set_output.outputs.DATA_CACHE_PREFIX }} | |
BUILD_GH_PAGES: ${{ steps.set_output.outputs.BUILD_GH_PAGES }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
cache: pip | |
cache-dependency-path: 'requirements.txt' | |
- name: Install dependencies | |
run: | | |
pip install -r requirements.txt | |
- name: Cache Data Files | |
if: env.SAVE_DATA_IN_GITHUB_CACHE == 'true' | |
uses: actions/cache@v3 | |
with: | |
path: | | |
activities | |
assets | |
GPX_OUT | |
TCX_OUT | |
FIT_OUT | |
Workouts | |
scripts/data.db | |
src/static/activities.json | |
imported.json | |
key: ${{ env.DATA_CACHE_PREFIX }}-${{ github.sha }}-${{ github.run_id }} | |
restore-keys: | | |
${{ env.DATA_CACHE_PREFIX }}-${{ github.sha }}- | |
${{ env.DATA_CACHE_PREFIX }}- | |
- name: Run sync Strava script | |
if: env.RUN_TYPE == 'strava' | |
run: | | |
python scripts/strava_sync.py '${{ secrets.S_CLIENT_ID }}' '${{ secrets.S_CLIENT_SECRET }}' '${{ secrets.S_REFRESH_TOKEN }}' | |
- name: Run strava_to_garmin_sync script | |
if: env.RUN_TYPE == 'strava' | |
run: | | |
python scripts/strava_to_garmin_sync.py '${{ secrets.S_CLIENT_ID }}' '${{ secrets.S_CLIENT_SECRET }}' '${{ secrets.S_REFRESH_TOKEN }}' '${{ secrets.GARMIN_SECRET_CN }}' '${{ secrets.STRAVA_EMAIL }}' '${{ secrets.STRAVA_PASSWORD }}' --is-cn | |
# - name: Fit to garmin cn sync | |
# if: env.RUN_TYPE == 'strava' | |
# run: | | |
# python scripts/fit_to_garmin_sync.py '${{ secrets.GARMIN_SECRET_CN }}' --is-cn | |
- name: Fit to garmin sync | |
if: env.RUN_TYPE == 'strava' | |
run: | | |
python scripts/fit_to_garmin_sync.py '${{ secrets.GARMIN_SECRET }}' | |
- name: Run sync Only GPX script | |
if: env.RUN_TYPE == 'only_gpx' | |
run: | | |
python scripts/gpx_sync.py | |
- name: Make svg GitHub profile | |
if: env.RUN_TYPE != 'pass' | |
run: | | |
python scripts/gen_svg.py --from-db --title '${{ env.TITLE }}' --type github --athlete '${{ env.ATHLETE }}' --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github.svg --use-localtime --min-distance 0.5 | |
python scripts/gen_svg.py --from-db --title '${{ env.TITLE_GRID }}' --type grid --athlete '${{ env.ATHLETE }}' --output assets/grid.svg --min-distance '${{ env.MIN_GRID_DISTANCE }}' --special-color yellow --special-color2 red --special-distance 20 --special-distance2 40 --use-localtime | |
python scripts/gen_svg.py --from-db --type circular --use-localtime | |
python scripts/gen_svg.py --from-db --year $(date +"%Y") --language zh_CN --title '$(date +'%Y') Running' --type github --athlete '${{ env.ATHLETE }}' --special-distance 10 --special-distance2 20 --special-color yellow --special-color2 red --output assets/github_$(date +"%Y").svg --use-localtime --min-distance 0.5 | |
- name: Push new runs | |
run: | | |
git config --local user.email '${{ env.GITHUB_EMAIL }}' | |
git config --local user.name '${{ env.GITHUB_NAME }}' | |
git commit -a -m 'update new runs' || echo 'nothing to commit' | |
git push || echo 'nothing to push' | |
- name: Gitee Sync | |
uses: Yikun/hub-mirror-action@master | |
with: | |
src: github/shaonianche | |
dst: gitee/shaonianche | |
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} | |
dst_token: ${{ secrets.GITEE_TOKEN }} | |
force_update: true | |
static_list: running-data-sync |