Setting Up a Cron Job with GitHub Actions

Setting up your project to build on a schedule (i.e. Cron job) is very straight forward with GitHub Actions. The below example shows how to trigger an action on the 15th of every month at the 42nd minute on the 7th hour(i.e. 07:42 UTC):

{% c-block language="yaml" %}
on:
 schedule:
   - cron:  "42 7 15 * *" #build project on the 15th day of every month on the 42nd minute of the 7th hour.
{% c-block-end %}

Here is a great resource on how to customize your scheduled event even more.

One thing to note, GitHub sets a minimum time of 5 minutes between scheduled events. In addition, there is no assurance that scheduled actions will run on time. The delay time between when an action is scheduled and when it runs is normally between 3 to 10 minutes, but can be even more ranging from dozens of minutes to more than an hour 😰

Now, let's look at a real life example using the workflow in a simple blinky led example we've created:

{% c-block language="yaml" %}
name: Simple pipeline to build firmware and save generated image
on:
  push:
  schedule:
    - cron:  "7 3,15 * * *" #build project everyday at hour 3, minute 7, and hour 15 and minute 7 (aka 3:07 and 15:07)
{% c-block-end %}

In our example above our action will trigger on either a {% c-line %}push{% c-line-end %} event or a {% c-line %}schedule{% c-line-end %} event. For the schedule event, our project will build every day at 3:07 and 15:07 UTC time. And that's it!

Want to stay up to date on the future of firmware? Join our mailing list.

Section
Chapter
Published