Skip to content

Commit

Permalink
chore: merge mater to fix confict
Browse files Browse the repository at this point in the history
  • Loading branch information
yihong0618 committed Sep 17, 2023
2 parents 3a089e3 + 3d5b8d9 commit 97f62b6
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 77 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ jobs:
python-version: ['3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
id: setup_python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
# from pdm
- name: Set Variables and install dep
id: set_variables
run: |
sudo apt-get install libxml2-dev libxslt-dev python3-dev
echo "PY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_OUTPUT
echo "PIP_CACHE=$(pip cache dir)" >> $GITHUB_OUTPUT
cache: 'pip'
cache-dependency-path: 'requirements-dev.txt'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Check formatting (black)
run: black . --check
45 changes: 38 additions & 7 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ name: Publish GitHub Pages

# Controls when the action will run.
on:
# trigger when the Run Data Sync workflow succeeded
workflow_run:
workflows: ['Run Data Sync']
types:
- completed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
save_data_in_github_cache:
required: true
type: boolean
default: false
data_cache_prefix:
required: true
type: string
default: track_data
workflow_call:
inputs:
save_data_in_github_cache:
required: true
type: boolean
default: false
data_cache_prefix:
required: true
type: string
default: track_data

permissions:
contents: read
Expand All @@ -36,6 +48,25 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Cache Data Files
if: inputs.save_data_in_github_cache
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: ${{ inputs.data_cache_prefix }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
${{ inputs.data_cache_prefix }}-${{ github.sha }}-
${{ inputs.data_cache_prefix }}-
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
Expand Down
83 changes: 64 additions & 19 deletions .github/workflows/run_data_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:

env:
# please change to your own config.
RUN_TYPE: pass # support strava/nike/garmin/garmin_cn/keep/only_gpx/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
RUN_TYPE: pass # support strava/nike/garmin/garmin_cn/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: yihong0618
TITLE: Yihong0618 Running
MIN_GRID_DISTANCE: 10 # change min distance here
Expand All @@ -34,37 +34,53 @@ env:
# 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: true # 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@v3

- name: Set up Python
id: setup_python
uses: actions/setup-python@v4
with:
python-version: 3.8

# from pdm and install dep
- name: Set Variables
id: set_variables
run: |
sudo apt-get install libxml2-dev libxslt-dev python3-dev
echo "PY=$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_OUTPUT
echo "PIP_CACHE=$(pip cache dir)" >> $GITHUB_OUTPUT
python-version: "3.10"
cache: pip
cache-dependency-path: 'requirements.txt'

- name: Cache PIP
uses: actions/cache@v2
with:
path: ${{ steps.set_variables.outputs.PIP_CACHE }}
key: Ubuntu-pip-${{ steps.set_variables.outputs.PY }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
if: steps.pip-cache.outputs.cache-hit != 'true'
- 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 Nike script
if: env.RUN_TYPE == 'nike'
Expand All @@ -84,8 +100,9 @@ jobs:
- 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 }}
# python run_page/garmin_sync.py ${{ secrets.GARMIN_EMAIL }} ${{ secrets.GARMIN_PASSWORD }} --only-run --is-cn
python scripts/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).
# python scripts/garmin_sync.py ${{ secrets.GARMIN_EMAIL }} ${{ secrets.GARMIN_PASSWORD }} --only-run --is-cn

- name: Run sync Codoon script
if: env.RUN_TYPE == 'codoon'
Expand All @@ -112,6 +129,16 @@ jobs:
run: |
python run_page/gpx_sync.py
- name: Run sync Only FIT script
if: env.RUN_TYPE == 'only_fit'
run: |
python scripts/fit_sync.py
- name: Run sync Only TCX script
if: env.RUN_TYPE == 'only_tcx'
run: |
python scripts/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: |
Expand Down Expand Up @@ -146,9 +173,27 @@ jobs:
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
19 changes: 17 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ R.I.P. 希望大家都能健康顺利的跑过终点,逝者安息。
git clone https://github.com/yihong0618/running_page.git --depth=1
```

## 安装及测试 (node >= 12 and <= 14 python >= 3.7)
## 安装及测试 (node >= 14.15.0 python >= 3.7)

```
pip3 install -r requirements.txt
Expand Down Expand Up @@ -822,13 +822,26 @@ Actions [源码](https://github.com/yihong0618/running_page/blob/master/.github/

1. 更改成你的 app type 及 info
![image](https://user-images.githubusercontent.com/15976103/94450124-73f98800-01df-11eb-9b3c-ac1a6224f46f.png)

2. 在 repo Settings > Secrets 中增加你的 secret (只添加你需要的即可)

![image](https://user-images.githubusercontent.com/15976103/94450295-aacf9e00-01df-11eb-80b7-a92b9cd1461e.png)
我的 secret 如下
![image](https://user-images.githubusercontent.com/15976103/94451037-8922e680-01e0-11eb-9bb9-729f0eadcdb7.png)

</details>

## 把数据文件放在 github cache 中

<details>
<summary>把数据文件放在github cache中</summary>

`run_data_sync.yml`中的`SAVE_DATA_IN_GITHUB_CACHE`设置为`true`时,可以把脚本抓取和中间产生的数据文件放到 github action cache 中。这样可以让你的 github commit 历史和目录保持干净。

如果你用 github pages 部署建议把这个值设置成`true`

</details>

# Fit 文件

测试发现,不同厂商在写 fit 文件的时候有略微差异。
Expand All @@ -855,7 +868,7 @@ Actions [源码](https://github.com/yihong0618/running_page/blob/master/.github/
- [x] 完善前端代码
- [x] better actions
- [ ] tests
- [ ] 支持不同的运动类型
- [x] 支持不同的运动类型

# 参与项目

Expand Down Expand Up @@ -898,3 +911,5 @@ Actions [源码](https://github.com/yihong0618/running_page/blob/master/.github/
Strava API Rate Limit Exceeded. Retry after 100 seconds
Strava API Rate Limit Timeout. Retry in 799.491622 seconds
```

### vercel git 如果想 ignpre gh-pages 可以在 settings -> build -> Ignored Build Step -> Custom 输入命令 `if [ "$VERCEL_GIT_COMMIT_REF" != "gh-pages" ]; then exit 1; else exit 0;`
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ English | [简体中文](https://github.com/yihong0618/running_page/blob/master/
| [EINDEX](https://github.com/eindex) | <https://workouts.eindex.me/> | Strava/Nike |
| [Melt](https://github.com/fpGHwd) | <https://running.autove.dev/> | Strava |
| [deepinwine](https://github.com/deepinwine) | <https://deepin.autove.dev/> | Garmin-cn |
| [Echo](https://github.com/donghao526) | <https://donghao526.github.io/running> | JoyRun |

</details>

Expand Down Expand Up @@ -118,7 +119,7 @@ Clone or fork the repo.
git clone https://github.com/yihong0618/running_page.git --depth=1
```

## Installation and testing (node >= 12 and <= 14 python >= 3.7)
## Installation and testing (node >= 14.15.0 python >= 3.7)

```
pip3 install -r requirements.txt
Expand Down Expand Up @@ -668,6 +669,17 @@ The following steps need to be taken

</details>

## Storing Data Files in GitHub Cache

<details>
<summary>Storing Data Files in GitHub Cache</summary>

When `SAVE_DATA_IN_GITHUB_CACHE` is set to `true` in the `run_data_sync.yml` file, the script can store fetched and intermediate data files in the GitHub Action cache. This helps keep your GitHub commit history and directory clean.

If you are deploying using GitHub Pages, it is recommended to set this value to `true`, and set `BUILD_GH_PAGES` to true.

</details>

# Fit file

supported manufacturer:
Expand Down Expand Up @@ -726,3 +738,5 @@ Just enjoy it~
Strava API Rate Limit Exceeded. Retry after 100 seconds
Strava API Rate Limit Timeout. Retry in 799.491622 seconds
```

### vercel git ignpre gh-pages: you can change settings -> build -> Ignored Build Step -> Custom command `if [ "$VERCEL_GIT_COMMIT_REF" != "gh-pages" ]; then exit 1; else exit 0;`
2 changes: 1 addition & 1 deletion assets/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/github_2022.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/github_2023.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 97f62b6

Please sign in to comment.