DEV Community

datadr1ven
datadr1ven

Posted on

A simple, but useful, and *powerful* GitHub action example

We maintain a Formula 1 Fantasy hobbyist/enthusiast tool, which we wrote a technical article about here last year. One room for improvement was in automation -- specifically, after each race concluded, we had to perform manual action to propagate the results to our tool. Well, we finally took the time automate that step, using GitHub actions. After figuring things out, the whole automation capability took only 28 lines (over half of which are superfluous), and so we thought that this could make for a nice tutorial and/or example of how to use GitHub actions.

So in our tool, which is hosted via GitHub pages, the data that changes over time (i.e. after each grand prix) is entirely contained in this file, of which here is a gestalt look at it...

export const active_season = 2025
export const latest_race = "Monaco Grand Prix";
export const race_names = ['AUS', 'CHN', 'JPN', 'BHR', 'SAU', 'USA', 'ITA', 'MCO'];
export const driver_points = {'GAS': [1, -8, 0, 13, -17, 18, 3, -20], 'ALO': [-20, -16, ...};
export const driver_prices = {'GAS': [11.8, 11.2, 10.6, 10, 9.4, 8.8, 8.2, 7.6], 'ALO': [8.8, 8.2, ...};
export const team_points = {'ALP': [-14, -6, 9, 22, -6, 10, 10, -11], 'AST': [1, 4, ...};
export const team_prices = {'ALP': [9.5, 8.9, 8.3, 7.7, 7.9, 8.1, 8.3, 7.7], 'AST': [8.5, 7.9, ...};
Enter fullscreen mode Exit fullscreen mode

This file is created by piping the contents of f1fantasytools.com's statistics page through a script we wrote to transform the data into the form our tool uses. In other words, after each race, we would run

curl https://f1fantasytools.com/statistics | python3 stats_to_race_data.py > race_data.js
Enter fullscreen mode Exit fullscreen mode

and then manually update the repository with the resulting file. This is the process we automated.

name: update race data
run-name: pull results and reorganize data for our platform
on:
  schedule:
    # * is a special character in YAML so you have to quote this string
    - cron:  '0 1 * * *'
jobs:
  Update-Race-Data:
    runs-on: ubuntu-latest
    permissions:
      contents: write    
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }}
      - name: Download latest race data
        uses: sozo-design/curl@v1.0.2
        with:
          args: -o statistics.html https://f1fantasytools.com/statistics
      - name: Process latest race data
        run: |
          cat statistics.html | python3 stats_to_race_data.py > race_data.js      
      - name: Remove our downloaded race data so as to not pollute repo
        run: |
          rm statistics.html
      - name: Commit any changes back to repo
        uses: stefanzweifel/git-auto-commit-action@v5
Enter fullscreen mode Exit fullscreen mode

The cron schedule is such that this runs once per day, which is acceptable because there is sometimes a lag in the final points assignment. The steps are somewhat self explanatory. First the repository is cloned by the runner. Then the latest statistics are downloaded via curl and saved to a file. That file is piped through our data transformation script. Then the downloaded html is removed, and then the results are committed back to the repository.

Here's the first run of this action after the 2025 Spanish Grand Prix - https://github.com/datadr1ven/teamtool/actions/runs/15382619543/job/43275725139

And this is the commit that resulted from that run -
https://github.com/datadr1ven/teamtool/commit/d8a769c2c3c9275adeede040619c3a6f284089fb

I hope you find this GitHub Action interesting and useful!

Top comments (0)