implenton - Mészáros Róbert

Persist changes from within a GitHub Action workflow

Imagine that you have a static site and a data file has to update periodically from an API. Or, you want to fix code style issues on every commit. Or, update the contributors' list automatically whenever somebody contributes.

All these are possible with GitHub Action, and one thing is common in them. In the end, you want to persist the updates.

With the checkout action, this is extremely easy.

Once you referenced the action, you can use the familiar Git add, commit, push commands.

Here's an example from an actual project using scheduled actions where a file is updated every 6 hours:

name: Update daily schedule
        -   cron: '0 */6 * * *'
        name: Update data
        runs-on: ubuntu-latest
+           -   name: Checkout code
+               uses: actions/checkout@v2
            -   name: Fetch the data and save it
                run: |
                    curl "$(date --date='-12 hour' +%s)000&end=$(date --date='+12 hour' +%s)000" -o public/daily-schedule.json
+                   git config github-actions
+                   git config
+                   git add .
+                   git commit -m "Update daily-schedule.json"
+                   git push

The commit will appear as expected in Git history.

See all posts