AI Hints
Home›CI/CD with GitHub Actions Tutorial›Filters, Manual and Scheduled Runs
CI/CD with GitHub Actions · Lesson 33 of 138

Scheduled Runs

Cron in the cloud.

⏱ 2 min read▶ Video at 37:03🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Some checks should run even when nobody pushes. A nightly test against the latest dependencies. A weekly security scan. Clearing old artifacts. The schedule event runs a workflow on a timer, using cron syntax.

Scheduled Runs
From the video: Scheduled Runs
  • Runs without a push
  • Nightly tests, weekly scans
  • The schedule event

Cron in five fields

A cron line has five fields. Minute, hour, day of the month, month, and day of the week. A star means every. So thirty two star star star means at two thirty every night. And zero nine star star one means nine AM every Monday. Schedules use UTC time.

CronRuns
30 2 * * *02:30 every day
0 9 * * 109:00 every Monday
0 */6 * * *every 6 hours
0 0 1 * *midnight, 1st of each month

A nightly workflow

On schedule takes a list of cron lines, in quotes, because the star has a special meaning in YAML. We also add workflow dispatch, so we can test the job by hand, without waiting until the middle of the night. That's a good habit for every scheduled workflow.

.github/workflows/nightly.ymlyaml
name: Nightly
on:
  schedule:
    - cron: "30 2 * * *"
  workflow_dispatch:
jobs:
  nightly:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pytest -q

Summary

Schedule runs workflows on a cron timer, in UTC. Add workflow dispatch too, so you can test it by hand. Next, practice.

Key takeaways
  • on: schedule
  • cron: "30 2 * * *"
  • UTC time
Next up: Practice: A Lint Workflow — your turn