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
on:
schedule:
- cron: '0 */6 * * *'
jobs:
update_daily_schedule:
name: Update data
runs-on: ubuntu-latest
steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
- name: Fetch the data and save it
run: |
curl "https://tilos.hu/api/v1/episode?start=$(date --date='-12 hour' +%s)000&end=$(date --date='+12 hour' +%s)000" -o public/daily-schedule.json
+ git config user.name github-actions
+ git config user.email github-actions@github.com
+ git add .
+ git commit -m "Update daily-schedule.json"
+ git push
The commit will appear as expected in Git history.