Run Data Sync #866
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: Run Data Sync | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * *' | |
push: | |
branches: | |
- master | |
paths: | |
- run_page/nike_sync.py | |
- run_page/nike_to_strava_sync.py | |
- run_page/strava_sync.py | |
- run_page/gen_svg.py | |
- run_page/garmin_sync.py | |
- run_page/coros_sync.py | |
- run_page/keep_sync.py | |
- run_page/gpx_sync.py | |
- run_page/tcx_sync.py | |
- run_page/garmin_to_strava_sync.py | |
- requirements.txt | |
env: | |
# please change to your own config. | |
RUN_TYPE: strava # support strava/nike/garmin/coros/garmin_cn/garmin_sync_cn_global/keep/only_gpx/only_fit/nike_to_strava/strava_to_garmin/strava_to_garmin_cn/garmin_to_strava/garmin_to_strava_cn/codoon, Please change the 'pass' it to your own | |
ATHLETE: sh33pyang | |
TITLE: sh33pyang Running | |
MIN_GRID_DISTANCE: 10 # change min distance here | |
TITLE_GRID: Over 10km Runs # also here | |
GITHUB_NAME: sh33pyang # change to yours | |
GITHUB_EMAIL: [email protected] # change to yours | |
# IGNORE_BEFORE_SAVING: True # if you want to ignore some data before saving, set this to True | |
IGNORE_START_END_RANGE: 10 # Unit meter | |
# Dont making this huge, just picking points you needing. https://developers.google.com/maps/documentation/utilities/polylineutility using this tool to making your polyline | |
IGNORE_POLYLINE: 'ktjrFoemeU~IorGq}DeB' | |
IGNORE_RANGE: 10 # Unit meter | |
SAVE_DATA_IN_GITHUB_CACHE: false # if you deploy in the vercal, check the README | |
DATA_CACHE_PREFIX: 'track_data' | |
BUILD_GH_PAGES: false # If you do not need GitHub Page please set it to `false` | |
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 | |
id: setup_python | |
uses: actions/setup-python@v5 | |
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@v4 | |
with: | |
path: | | |
activities | |
assets | |
GPX_OUT | |
TCX_OUT | |
FIT_OUT | |
Workouts | |
run_page/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 Nike script | |
if: env.RUN_TYPE == 'nike' | |
run: | | |
python run_page/nike_sync.py ${{ secrets.NIKE_REFRESH_TOKEN }} | |
- name: Run sync Nike to Strava(Run with nike data backup and show with strava) | |
if: env.RUN_TYPE == 'nike_to_strava' | |
run: | | |
python run_page/nike_to_strava_sync.py ${{ secrets.NIKE_REFRESH_TOKEN }} ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} | |
- name: Run sync Keep script | |
if: env.RUN_TYPE == 'keep' | |
run: | | |
python run_page/keep_sync.py ${{ secrets.KEEP_MOBILE }} ${{ secrets.KEEP_PASSWORD }} --with-gpx | |
- name: Run sync Coros script | |
if: env.RUN_TYPE == 'coros' | |
run: | | |
python run_page/coros_sync.py ${{ secrets.COROS_ACCOUNT }} ${{ secrets.COROS_PASSWORD }} | |
- name: Run sync Strava script | |
if: env.RUN_TYPE == 'strava' | |
run: | | |
python run_page/strava_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} | |
# If you only want to sync `type running` add args --only-run, default script is to sync all data (rides and runs). | |
- name: Run sync Codoon script | |
if: env.RUN_TYPE == 'codoon' | |
run: | | |
python run_page/codoon_sync.py ${{ secrets.CODOON_MOBILE }} ${{ secrets.CODOON_PASSWORD }} | |
# for garmin if you want generate `tcx` you can add --tcx command in the args. | |
- name: Run sync Garmin script | |
if: env.RUN_TYPE == 'garmin' | |
run: | | |
# make garimin secret string `python run_page/get_garmin_secret.py ${email} ${password} | |
python run_page/garmin_sync.py ${{ secrets.GARMIN_SECRET_STRING }} | |
# If you only want to sync `type running` add args --only-run, default script is to sync all data (rides and runs). | |
# python run_page/garmin_sync.py ${{ secrets.GARMIN_SECRET_STRING }} --only-run | |
- name: Run sync Garmin CN script | |
if: env.RUN_TYPE == 'garmin_cn' | |
run: | | |
# make garimin secret string `python run_page/get_garmin_secret.py ${email} ${password} --is-cn | |
python run_page/garmin_sync.py ${{ secrets.GARMIN_SECRET_STRING_CN }} --is-cn | |
# If you only want to sync `type running` add args --only-run, default script is to sync all data (rides and runs). | |
# python run_page/garmin_sync.py ${{ secrets.GARMIN_SECRET_STRING_CN }} --only-run --is-cn | |
- name: Run sync Garmin CN to Garmin script | |
if: env.RUN_TYPE == 'garmin_sync_cn_global' | |
run: | | |
# make garimin secret string `python run_page/garmin_sync_cn_global.py ${email} ${password} --is-cn | |
python run_page/garmin_sync_cn_global.py ${{ secrets.GARMIN_SECRET_STRING_CN }} ${{ secrets.GARMIN_SECRET_STRING }} | |
# If you only want to sync `type running` add args --only-run, default script is to sync all data (rides and runs). | |
# python run_page/garmin_sync_cn_global.py ${{ secrets.GARMIN_SECRET_STRING_CN }} ${{ secrets.GARMIN_SECRET_STRING }} --only-run | |
- name: Run sync Only GPX script | |
if: env.RUN_TYPE == 'only_gpx' | |
run: | | |
python run_page/gpx_sync.py | |
- name: Run sync Only FIT script | |
if: env.RUN_TYPE == 'only_fit' | |
run: | | |
python run_page/fit_sync.py | |
- name: Run sync Only TCX script | |
if: env.RUN_TYPE == 'only_tcx' | |
run: | | |
python run_page/tcx_sync.py | |
- name: Run sync Strava to Garmin(Run with strava(or others upload to strava) data backup in Garmin) | |
if: env.RUN_TYPE == 'strava_to_garmin' | |
run: | | |
python run_page/strava_to_garmin_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} ${{ secrets.GARMIN_SECRET_STRING }} ${{ secrets.STRAVA_EMAIL }} ${{ secrets.STRAVA_PASSWORD }} | |
- name: Run sync Strava to Garmin-cn(Run with strava(or others upload to strava) data backup in Garmin-cn) | |
if: env.RUN_TYPE == 'strava_to_garmin_cn' | |
run: | | |
python run_page/strava_to_garmin_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} ${{ secrets.GARMIN_SECRET_STRING_CN }} ${{ secrets.STRAVA_EMAIL }} ${{ secrets.STRAVA_PASSWORD }} --is-cn | |
- name: Run sync Garmin-cn to Strava(Run with Garmin data backup in Strava) | |
if: env.RUN_TYPE == 'garmin_to_strava_cn' | |
run: | | |
python run_page/garmin_to_strava_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} ${{ secrets.GARMIN_SECRET_STRING_CN }} --is-cn | |
- name: Run sync Garmin to Strava(Run with Garmin data backup in Strava) | |
if: env.RUN_TYPE == 'garmin_to_strava' | |
run: | | |
python run_page/garmin_to_strava_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} ${{ secrets.GARMIN_EMAIL }} ${{ secrets.GARMIN_PASSWORD }} | |
- name: Run sync Tulipsport script | |
if: env.RUN_TYPE == 'tulipsport' | |
run: | | |
python run_page/tulipsport_sync.py ${{ secrets.TULIPSPORT_TOKEN }} --with-gpx | |
- name: Make svg GitHub profile | |
if: env.RUN_TYPE != 'pass' | |
run: | | |
python run_page/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 run_page/gen_svg.py --from-db --title "${{ env.TITLE_GRID }}" --type grid --athlete "${{ env.ATHLETE }}" --output assets/grid.svg --special-color yellow --special-color2 red --special-distance 20 --special-distance2 40 --use-localtime --min-distance "${{ env.MIN_GRID_DISTANCE }}" | |
python run_page/gen_svg.py --from-db --type circular --use-localtime | |
python run_page/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 | |
if: env.SAVE_DATA_IN_GITHUB_CACHE != 'true' | |
run: | | |
git config --local user.email "${{ env.GITHUB_EMAIL }}" | |
git config --local user.name "${{ env.GITHUB_NAME }}" | |
git add . | |
git commit -m 'update new runs' || echo "nothing to commit" | |
git push || echo "nothing to push" | |
- name: Set Output | |
id: set_output | |
run: | | |
echo "SAVE_DATA_IN_GITHUB_CACHE=${{ env.SAVE_DATA_IN_GITHUB_CACHE }}" >> "$GITHUB_OUTPUT" | |
echo "DATA_CACHE_PREFIX=${{ env.DATA_CACHE_PREFIX }}" >> "$GITHUB_OUTPUT" | |
echo "BUILD_GH_PAGES=${{ env.BUILD_GH_PAGES }}" >> "$GITHUB_OUTPUT" | |
publish_github_pages: | |
if: needs.sync.result == 'success' && needs.sync.outputs.BUILD_GH_PAGES == 'true' | |
name: Build and publish Github Pages | |
uses: ./.github/workflows/gh-pages.yml | |
with: | |
save_data_in_github_cache: ${{needs.sync.outputs.SAVE_DATA_IN_GITHUB_CACHE == 'true'}} | |
data_cache_prefix: ${{needs.sync.outputs.DATA_CACHE_PREFIX}} | |
needs: | |
- sync |