Scheduled GitHub Actions

For FormBus, I used two GitHub workflows. One is for code quality check by running ESList. The other is to publish a new version of the package on npm.

Both workflows are triggered when a commit is pushed to a branch. While everything happens without any extra effort, I'm the one who is initializing the events.

But GitHub Actions are not limited to these kinds of workflows. You can also schedule events. You can run workflows at specific intervals, and this opens up new possibilities for automation.

Because you can choose to run a Ubuntu image, you can do almost anything with a bit of scripting.

For example, you can rebuild your website every midnight on Netlify. Simply use curl to hit a webhook.

name: Scheduled workflow
on:
    schedule:
        -   cron: '0 0 * * *'
jobs:
    build:
        name: Rebuild website
        runs-on: ubuntu-latest
        steps:
            -   name: Build hook request
                run: curl -X POST -d '{}' https://api.netlify.com/build_hooks/

Sometimes it takes a few hours or even half a day until the cron event is registered and run for the first time on GitHub.

You can always make sure that your workflow works as expected by manually running it. Add the additional workflow_dispatch as an event trigger:

name: Scheduled workflow
on:
+   workflow_dispatch:
    schedule:
        -   cron: '0 0 * * *'