GitHub Actions can be triggered to run on a schedule using cron syntax. In this video we go over what that means and how to write cron syntax. We also show a tool and a series of examples to aid in writing and debugging cron.
Instructor: [00:00] In addition to triggering GitHub actions on push, we can schedule GitHub actions to occur using cron syntax. Note that scheduled workflows will get run with the latest commit on the default branch.
[00:11] To understand how to schedule GitHub actions using cron, we can use crontab guru. Crontab guru will show us a minute, hour, day, month, and day of the week. Using this display, we can click on the field that we want to change, look at the options available to us, and choose one.
[00:31] Note that now the next time this cron job will run is at 2:05. Crontab guru has a set of examples that can be found. If you want to run ever Friday, every hour at 30 minutes, or every day at 1:00 AM. Let's look at the every five minutes.
[00:47] The syntax to run every five minutes uses a star, a slash, and a five in the minute category. All of the other fields will be set to any value. Let's go to our GitHub workflow.
[01:00] This GitHub workflow runs echo. Currently, our workflow is run on push. Let's change that.
[01:08] We'll change this to run on schedule. Note that we have to wrap our string in quotes because star is a special character in YAML. We'll commit this.
[01:26] Let's go back to our actions tab. The workflow now runs on a schedule. Note that our action is now running every five minutes.
Anything that you want to run on an interval that doesn't have a pre-existing event. For example, if you can run your action on push
, then you shouldn't be scheduling it. Here's a couple examples of interesting schedulable actions:
Wow, I had to provision a server only for running crons on GitHub since Actions didn't have that. And I didn't get to know when they introduced it. This will save me so much time and money. Thank you! 👌
Once a week, scan activity on the repo and send an email with a digest of the merged PRs or release notes
Do you have this one handy? Would love to check it out.
What sort of action would be most appropriate for running on a schedule like this?