Github Action won't allow cron starting in custom year period

Viewed 55

The following cron expression:

0 3 1 5-5/3 *

“At 03:00 on day-of-month 1 in every 3rd month from May through May.”

Is not accepted by Github actions:

on:
  schedule:
    - cron: "0 3 1 5-5/3 *"  ## Day 1, every 3rd month May-May

With the following output:

ERROR: String does not match the pattern of "^(((\d+,)+\d+|((\d+|\*)/\d+|((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?))|(\d+-\d+)|\d+|\*|((MON|TUE|WED|THU|FRI|SAT|SUN)(-(MON|TUE|WED|THU|FRI|SAT|SUN))?)) ?){5}$".yaml-schema: GitHub Workflow

How is it possible to run a cron starting 1st of May, every 3 months, until the next May?

1 Answers

Your cron expression probably does not what you expect. The part 5-5/3 restricts the execution times to May only. This results in a job that will be run at 03:00 on the first day of every May:

2022-05-01 03:00:00
2023-05-01 03:00:00
2024-05-01 03:00:00

The regex that GitHub is using to verify the cron expression (according to the error message in your question) does not allow defining a range and step at the same time. This might be a bug as such expressions would usually be valid.

To fix this, you could list all months in the cron expression directly like 0 3 1 5,8,11,2 * which results in the following schedule:

2022-05-01 03:00:00
2022-08-01 03:00:00
2022-11-01 03:00:00
2023-02-01 03:00:00
2023-05-01 03:00:00
2023-08-01 03:00:00
2023-11-01 03:00:00
2024-02-01 03:00:00
Related