Guides / Schedule a nightly workflow
Schedule a nightly workflow
Some jobs run on a clock: a nightly dependency audit, a weekly full test suite, a daily cache warm-up. This guide adds a schedule to a config.
Prerequisites
Section titled “Prerequisites”- A job to run on the schedule. This guide uses
audit.
-
Write the cron expression
Section titled “Write the cron expression”A cron expression has five fields, in UTC:
Field Values minute 0 to 59 hour 0 to 23 day of month 1 to 31 month 1 to 12 day of week 0 to 6, Sunday is 0 30 2 * * *is 02:30 UTC every day.0 6 * * 1is 06:00 UTC every Monday. -
Add a scheduled workflow
Section titled “Add a scheduled workflow”.hatchrun/config.yml jobs:audit:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v5- run: npm audit --audit-level=highworkflows:nightly:on:schedule:- cron: '30 2 * * *'jobs:- auditQuote the expression. YAML reads an unquoted value that starts with
*as an alias, and fails. -
Add more schedules if needed
Section titled “Add more schedules if needed”scheduleis a list, so one workflow can have several:.hatchrun/config.yml jobs:full-test:runs-on: ubuntu-26.04-8coresteps:- run: make test-allworkflows:weekly:on:schedule:- cron: '0 6 * * 1'- cron: '0 6 * * 4'jobs:- full-test -
Commit to the default branch
Section titled “Commit to the default branch”Validate, then merge the change into the default branch:
Terminal window hatchrun validatehatchrun reads schedules only from the config on the default branch.
Expected result: after the merge, the workflow runs at the next due time on the default branch’s latest commit, and its check runs appear on that commit.
Good to know
Section titled “Good to know”hatchrun validatedoes not check cron expressions. Check the five fields by eye.- Scheduled runs see the default branch. A
branches: [main]filter on an entry passes whenmainis the default branch. - A workflow can have
scheduleand other events together. Keep long scheduled jobs in their own workflow so pushes do not run them.