⚠️ This lesson is retired and might contain outdated information.

Scheduling GitHub Actions with cron

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 2 years ago

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.

  • https://crontab.guru/

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.

Joel Hooks
Joel Hooks
~ 5 years ago

What sort of action would be most appropriate for running on a schedule like this?

Chris Biscardi
Chris Biscardiinstructor
~ 5 years ago

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:

  • Every hour, fetch data from remote sources and store it locally, such as a slow CMS, for a static site build
  • Every day at 10am, move all posts from draft to published that are marked to be published that day. Pushing back to the repo triggers a build-and-deploy
  • Nightly releases of your library or product. Building at 8pm every night and releasing on an alpha or nightly branch.
  • Once a week, scan activity on the repo and send an email with a digest of the merged PRs or release notes
Ahmad Awais ⚡
Ahmad Awais ⚡
~ 5 years ago

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! 👌

Ahmad Awais ⚡
Ahmad Awais ⚡
~ 5 years ago

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.

Markdown supported.
Become a member to join the discussionEnroll Today