-
Notifications
You must be signed in to change notification settings - Fork 0
39 lines (36 loc) · 1.74 KB
/
run_data_sync.yml
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
name: Run Data Sync
on:
workflow_dispatch:
schedule:
- cron: '0 1 * * *'
env:
GITHUB_NAME: ZhengHe-MD
GITHUB_EMAIL: [email protected]
jobs:
sync:
name: Sync
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download latest tracks
run: |
wget -P public/ https://zhenghe-md.github.io/running_page/activities.json
- name: Install jq
run: |
sudo apt-get update && sudo apt-get install -y jq
- name: Transform the activities.json data
run: |
cat public/activities.json | jq '.[] | {distance, moving_time, start_date_local}' | jq -s '.' > public/activities-tmp-1.json
cat public/activities-tmp-1.json | jq '.[].distance /= 1000' > public/activities-tmp-2.json
cat public/activities-tmp-2.json| jq '.[].start_date_local |= sub(" .*"; "")' > public/activities-tmp-3.json
cat public/activities-tmp-3.json | jq '.[] | {date: .start_date_local, distance, duration: {hours: (.moving_time | split(":") | map(tonumber) | .[0]), mins: (.moving_time | split(":") | map(tonumber) | .[1]), secs: (.moving_time | split(":") | map(tonumber) | .[2])}}' | jq -s '.' > public/activities-tmp-4.json
jq -s 'add' public/data.json public/activities-tmp-4.json | jq 'unique_by(.date)' > public/merged.json
mv public/merged.json public/data.json
- name: Push the merged data to the repo
run: |
git config --local user.email "${{ env.GITHUB_EMAIL }}"
git config --local user.name "${{ env.GITHUB_NAME }}"
git add public/data.json
git commit -m "update new runs $(date +'%Y-%m-%d')" || echo "nothing to commit"
git push || echo "nothing to push"