Skip to content

Commit

Permalink
Create a GitHub Actions workflow to automatically sync Peloton to Gar…
Browse files Browse the repository at this point in the history
…min (#244)

* Add workflow to sync to garmin

* Update sync_peloton_to_garmin.yml

* Update sync_peloton_to_garmin.yml

* Update sync_peloton_to_garmin.yml

* Fix exclude

* Deploy to different docker repo

* Fix workflow

* Update docker tags

* Add documentation

* Change log level to Information

* Use stable tag for sync workflow

* Use full path for output

* Update nav order

* Fix missing quotes for schedule
  • Loading branch information
dkuwahara authored Mar 28, 2022
1 parent 207d817 commit ecb05a8
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
with:
push: true
file: ./docker/Dockerfile.console
tags: philosowaffle/peloton-to-garmin:latest
tags: ${{ secrets.DOCKER_USERNAME }}/peloton-to-garmin:latest
platforms: linux/arm64,linux/amd64
build-args: VERSION=${{ env.BUILD_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
with:
push: true
file: ./docker/Dockerfile.api
tags: philosowaffle/peloton-to-garmin:api-latest
tags: ${{ secrets.DOCKER_USERNAME }}/peloton-to-garmin:api-latest
platforms: linux/arm64,linux/amd64
build-args: VERSION=${{ env.BUILD_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
with:
push: true
file: ./docker/Dockerfile.webui
tags: philosowaffle/peloton-to-garmin:webui-latest
tags: ${{ secrets.DOCKER_USERNAME }}/peloton-to-garmin:webui-latest
platforms: linux/arm64,linux/amd64
build-args: VERSION=${{ env.BUILD_VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/sync_peloton_to_garmin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This is a workflow that will automatically sync your Peloton rides with Garmin

name: Sync workflow

# Controls when the action will run.
on:
workflow_dispatch:
inputs:
workoutsToDownload:
type: number
default: "5"
schedule:
- cron: '0 1 * * *'

jobs:
sync:
runs-on: ubuntu-latest
# The type of runner that the job will run on
container:
image: philosowaffle/peloton-to-garmin:stable
steps:
- run: mkdir -p /app/output
- name: Create device info file
run: |
cat <<EOT > /app/deviceInfo.xml
${{secrets.DEVICE_INFO}}
EOT
- name: Create config file
env:
DEFAULT_WORKOUT_NUM: 5
run: |
cat <<EOT > /app/configuration.local.json
{
"App": {
"OutputDirectory": "/app/output",
"EnablePolling": false,
"CloseWindowOnFinish": true
},
"Format": {
"Fit": true,
"Json": false,
"Tcx": false,
"SaveLocalCopy": false,
"IncludeTimeInHRZones": false,
"IncludeTimeInPowerZones": false,
"DeviceInfoPath": "./deviceInfo.xml"
},
"Peloton": {
"NumWorkoutsToDownload": ${{ github.event.inputs.workoutsToDownload || env.DEFAULT_WORKOUT_NUM }},
"ExcludeWorkoutTypes": [ "meditation" ],
},
"Garmin": {
"Upload": true,
"FormatToUpload": "fit",
"UploadStrategy": 2
},
"Observability": {
"Prometheus": {
"Enabled": false
},
"Jaeger": {
"Enabled": false
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console"],
"MinimumLevel": "Information",
"WriteTo": [
{ "Name": "Console" }
]
}
}
}
EOT
- run: /app/PelotonToGarminConsole
working-directory: /app
env:
P2G_PELOTON__EMAIL: ${{ secrets.P2G_PELOTON__EMAIL }}
P2G_PELOTON__PASSWORD: ${{ secrets.P2G_PELOTON__PASSWORD }}
P2G_GARMIN__EMAIL: ${{ secrets.P2G_GARMIN__EMAIL }}
P2G_GARMIN__PASSWORD: ${{ secrets.P2G_GARMIN__PASSWORD }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ configuration.local.json
/Output
/src/PelotonToGarminConsole/data
/src/WebApp/data
/.vs/ProjectSettings.json
Binary file modified .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/configuration/environment-variables.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: default
title: Environmnet Variables
title: Environment Variables
parent: Configuration
nav_order: 2
---
Expand Down
38 changes: 38 additions & 0 deletions docs/install/github-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: default
title: Using the Github Action
nav_order: 2
has_children: false
---

# Github Actions

A Github Actions workflow exists that can be used to automatically sync your rides on a schedule (by default once a day)

## Getting started

The easiest way to use the action is to simply create a fork of the repo using the `Fork` button.

## Secrets

Once you've created your fork, you'll need to set a number of secrets in your repository.

You can set secrets by clicking the `Settings` tab in your fork. Then, on the side nav, select `Secrets` and then `Actions`.

From this point on you can add secrets by clicking the `New repository secret` button at the top right.

| Secret Name | Value |
|:-----------------|:------------------|
| `P2G_PELOTON__EMAIL` | The email address you use to login to Peloton |
| `P2G_PELOTON__PASSWORD` | The password that you use to login to Peloton |
| ` P2G_GARMIN__EMAIL` | The email address that you use to login to Garmin |
| `P2G_GARMIN__PASSWORD` |The password that you use to log into Garmin |
| `DEVICE_INFO` | The contents of the deviceInfo.xml that you want to use for the sync |

## Starting the workflow

Once you've configured your secrets, you can then navigate to the `Actions` tab within your repository. Enable actions for your fork. You can now run the `Sync workflow` manually, or have it automatically run on the schedule set by the `cron` line in the `./github/workflows/sync_peloton_to_garmin.yml` file.

## Additional Notes

If you're doing more than 5 runs a day, you will need to change the default number of workouts downloaded as part of the workflow.
2 changes: 1 addition & 1 deletion docs/install/migrate-v1-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: default
title: Migrating from V1 to V2
parent: Install
nav_order: 3
nav_order: 4
---

# Migrating from V1 to V2
Expand Down
2 changes: 1 addition & 1 deletion docs/install/source.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: default
title: Build from Source
parent: Install
nav_order: 2
nav_order: 3
---

# Build from Source
Expand Down
2 changes: 1 addition & 1 deletion src/Peloton/PelotonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public async Task DownloadLatestWorkoutDataAsync(int numWorkoutsToDownload)
}

_logger.Debug("Check if workout is in ExcludeWorkoutTypes list. {@WorkoutId}", workoutId);
if (!_config.Peloton.ExcludeWorkoutTypes?.Contains(deSerializedData.WorkoutType) ?? true)
if (_config.Peloton.ExcludeWorkoutTypes.Contains(deSerializedData.WorkoutType))
{
_logger.Debug("Skipping excluded workout type. {@WorkoutId} {@WorkoutType}", deSerializedData.Workout.Id, deSerializedData.WorkoutType);
continue;
Expand Down

0 comments on commit ecb05a8

Please sign in to comment.