Daily workout with GitHub Actions

For a long time I’ve tried to code my own “workout” solutions to track my sessions, be it creating a timer app, listing workouts, or just tracking my daily exercise.

The other day I had an epiphany and thought I could use GitHub Issues in combination with GitHub Actions to create a daily routine using GitHub as my backend.

It's quite simple, seriously.

How does it work?

Using GitHub Actions we create a daily job that creates a new issue with tasks and assigns it to me.

I then check off the tasks as I complete them during the day, directly on the GitHub issue interface.

Another action is run nightylty and checks if there are any issues with all its tasks completed, then closes the issues.

Rinse and repeat.

Create new daily issue

name: Create Workout

on:
  schedule:
    - cron: '15 7 * * *' # Runs every day at 8:15AM CET
  workflow_dispatch: # Allows manual trigger

jobs:
  create_issue:
    runs-on: ubuntu-latest
    steps:
      - name: Create issue
        uses: actions/github-script@v7
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const date = new Date();
            const issue = {
              owner: context.repo.owner,
              repo: context.repo.repo,
              title: `Workout for ${date.toISOString().split('T')[0]}`,
              body: `Hello there! This is your workout menu:
              - [ ] 10 pushups
              - [ ] 10 pushups
              - [ ] 10 pushups
              - [ ] 20 lunges
              - [ ] 40 squats
              - [ ] 40 hostages
              - [ ] 40 hostages`,
              assignees: ['quicoto']
            };
            github.rest.issues.create(issue);Code language: YAML (yaml)

Close completed issues

name: Close Completed

on:
  schedule:
    - cron: '0 0 * * *' # Runs every day at midnight UTC
  workflow_dispatch: # Allows manual trigger

jobs:
  close_issues:
    runs-on: ubuntu-latest
    steps:
      - name: Close completed issues
        uses: actions/github-script@v7
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const issues = await github.rest.issues.listForRepo({
              owner: context.repo.owner,
              repo: context.repo.repo,
              state: 'open'
            });

            for (const issue of issues.data) {
              const taskProgress = issue.body.match(/\[.\]/g);
              if (taskProgress) {
                const completedTasks = taskProgress.filter(task => task === '[x]').length;
                const totalTasks = taskProgress.length;
                if (completedTasks === totalTasks) {
                  await github.rest.issues.update({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    issue_number: issue.number,
                    state: 'closed'
                  });
                }
              }
            }Code language: YAML (yaml)

Freebies

If you decide to automatically assign the issues to you, you will get the GitHub email with the notifications. Nice!

You use the GitHub UI, no need to code any frontend or maintain any backend.

Conclusion

Very happy with this, I feel it could be improved with some sort of graphs or stats. Since you can’t delete issues with the REST API you could list them all and update the repository README with stats. 

Repository

Fork it and play with it!

https://github.com/quicoto/workout-tracker

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *