What Is and How To Use Cron Jobs With GitHub
If you’ve ever needed to run a script automatically on a schedule — like every day at midnight or every hour — you’re looking for a cron job.
But did you know you can run cron jobs directly on GitHub, without any servers or infrastructure?
Here’s a simple, modern developer’s guide to cron jobs using GitHub Actions.
What Is a Cron Job?
A cron job is just a time-based task scheduler. It tells your system:
“Run this script at X time, every Y interval.”
Traditionally, you’d configure this on a Linux server using the crontab command. But in 2025, we can do better: serverless automation right inside GitHub.
Quick Guide to Cron Syntax in GitHub
When you define:
schedule:
- cron: '0 0 * * *'You’re telling GitHub Actions:
“Run this job at 00:00 UTC every day.”
Cron expressions follow this format:
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday = 0)
│ │ │ │ │
│ │ │ │ │
* * * * *Useful Examples
| Cron Expression | Description | |
|---|---|---|
| 0 9 * * 1 | Every Monday at 09:00 UTC | |
| 30 18 * * * | Every day at 18:30 UTC | |
| 0 0 1 * * | Run on the 1st day of every month at midnight | |
| 0 0 */2 * * | Every 2 days, at 00:00 | |
| 0 12 * * 1,3,5 | Every Mon/Wed/Fri at 12:00 UTC | |
| */15 * * * * | Every 15 minutes (be careful with limits from your provider!) |
Why Use Cron Jobs With GitHub?
You get:
Free compute (via GitHub Actions)
No infrastructure to manage
Native access to your repos, issues, APIs, etc.
Logs, versioning, and PR-triggered logic
Perfect for:
Running cleanup scripts
Syncing data with APIs
Sending reports or summaries
Keeping dependencies updated
Real Use Case Examples
Fetch and store latest API data daily
Close stale GitHub issues every week
Ping an endpoint to keep a server warm
Post a Slack message every Monday
You can even integrate secrets, fetch remote content, and trigger workflows conditionally.
How To Set Up a GitHub Cron Job (Step-by-Step)
- Create a .github/workflows/cron.yml file in your repo:
name: Run Scheduled Job
on:
schedule:
- cron: '0 0 * * *' # every day at midnight UTC
workflow_dispatch: # optional: lets you trigger it manually
jobs:
run-script:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run My Script
run: node ./scripts/my-script.js🧠 Tip: Use crontab.guru to craft your cron expression.
- Commit and push. GitHub will now run that job automatically on your schedule.
⚠️ GitHub Cron Jobs Are Not Precisely Timed
Here’s something many developers miss: GitHub Actions doesn’t guarantee exact execution time for scheduled workflows.
When you schedule a job for 0 0 * * * (midnight UTC), GitHub might not run it exactly at midnight. Instead, you could see a delay of several minutes, sometimes even longer, depending on how many scheduled jobs GitHub is processing at that time.
This happens because:
GitHub queues thousands of cron-based workflows across all public and private repos.
There’s no SLA (service-level agreement) for precise timing.
Workarounds & Alternatives
Use GitHub Enterprise / Premium Runners
With GitHub-hosted runners on a paid plan, especially self-hosted or enterprise-level runners, you may see:
Reduced queue times
More predictable scheduling
Higher concurrency limits
But still, even GitHub Enterprise doesn’t promise second-level accuracy.
Use External Scheduling Services
If timing is critical (e.g., you must hit an API exactly at 03:00 UTC), consider using:
cron-job.org — Free, simple cron-as-a-service
AWS EventBridge Scheduler — Cloud-native, scalable, precise
Zapier / n8n / Make — Great for no-code API automation
Cloudflare Workers + Cron Triggers — Fast, serverless, highly reliable
These services hit your endpoint or trigger a GitHub workflow_dispatch event, giving you tighter control.
For real-time-sensitive or coordinated operations, consider external schedulers or a hybrid model (e.g., external trigger → GitHub Action via API).
Debugging + Best Practices
Always add workflow_dispatch so you can test manually
Use
actions/setup-nodeif your script needs Node/npmUse GitHub cron jobs when timing isn’t critical, like:
Daily cleanup tasks
Weekly reports
API syncs with buffer room
Final Thoughts
GitHub Actions + cron is cron-as-a-service---a powerful, free tool for automation that lives next to your code. You don’t need to spin up servers or deploy functions. Just commit and let it run. Until next time!