DEV Community

Cover image for How to Run Scheduled Cron Jobs in GitHub Workflows for Free
Dylan Britz
Dylan Britz

Posted on • Originally published at dylanbritz.dev

3 1

How to Run Scheduled Cron Jobs in GitHub Workflows for Free

Ever wanted to automate repetitive tasks without paying for a dedicated server? GitHub Actions offers a powerful (and free!) solution for running scheduled tasks also known as cron jobs. Whether you need to sync data, generate reports, or even run a web scraper on schedule, this guide has you covered!

What Are GitHub Actions Scheduled Workflows?

GitHub Actions lets you automate tasks based on various triggers, including time-based schedules using cron syntax. The best part? It's completely free for public repositories, with generous free minute allocations for private repos too.

Setting Up Your First Scheduled Workflow

1. Create or Choose Your Repository

Remember that public repositories have unlimited free minutes, while private repos get around 2000 minutes/month on free plans.

2. Add a Workflow File

Create a new file at .github/workflows/cron-job.yml in your repository.

3. Define Your Schedule Using Cron Syntax

Here's a simple example that runs every day at midnight (UTC):

name: Daily Cron Job

on:
  schedule:
    - cron: '0 0 * * *' # Every day at midnight UTC

jobs:
  run-script:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Run script
        run: echo "Scheduled job ran at $(date -u)"
Enter fullscreen mode Exit fullscreen mode

4. Understanding Cron Syntax

Cron expressions use five fields representing:

  • Minute (0-59)
  • Hour (0-23)
  • Day of Month (1-31)
  • Month (1-12)
  • Day of Week (0-6, where Sunday = 0)

Here are some common patterns:

Cron Expression What It Does
0 0 * * * Every day at midnight UTC
*/5 * * * * Every five minutes
0 13 * * 1 Every Monday at 1:00 PM UTC

Pro tip: Use crontab.guru to test your cron expressions!

Best Practices for GitHub Actions Cron Jobs

Mind the Time Zone

All GitHub Actions schedules run in UTC. Make sure to adjust your schedule accordingly if you need tasks to run at specific local times.

Schedule Strategically

  • The minimum interval allowed is every 5 minutes (*/5 * * * *)
  • Avoid scheduling exactly on the hour (0 * * * *) to prevent delays due to high demand
  • You can set multiple schedules in one workflow to create complex timing patterns

Choose the Right Environment

By default, jobs run on Ubuntu, but you can specify runs-on: windows-latest or macos-latest if your tasks need a specific operating system.

Real-World Example: Scheduled Web Scraper

Want to collect data from a website daily? Here's how to set up a Python web scraper to run every morning:

name: Scheduled Web Scraper

on:
  schedule:
    - cron: '0 6 * * *' # Every day at 6am UTC

jobs:
  scrape:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install dependencies
        run: pip install -r requirements.txt
      - name: Run scraper
        run: python scraper.py
Enter fullscreen mode Exit fullscreen mode

This will run your scraper automatically at 6 AM UTC every day.

Why Choose GitHub Actions Over Alternatives?

Feature GitHub Actions Traditional Cron Cloud Schedulers
Setup Simple YAML in repo Requires server access Cloud configuration
Cost Free for public repos Free (but needs a server) Usually requires payment
Maintenance Managed by GitHub Your responsibility Minimal but requires account
Best for Code projects, automation Local tasks Production systems

Tips

  1. Test your workflows manually before scheduling them to catch any issues
  2. Use GitHub Secrets for storing API keys or sensitive information
  3. Add conditions to make your workflows smarter using the if: syntax
  4. Monitor your usage if you're using private repositories to avoid exceeding free minutes

GitHub Actions scheduled workflows give you a free, flexible way to automate recurring tasks without managing servers or paying for third-party schedulers. Whether you're running maintenance scripts, syncing data, or creating automated reports, these cloud-based cron jobs integrate seamlessly with your existing GitHub workflow.

Have you set up any cool automated workflows with GitHub Actions? What tasks are you planning to automate?


Source:

Image of Quadratic

AI, code, and data connections in a familiar spreadsheet UI

Simplify data analysis by connecting directly to your database or API, writing code, and using the latest LLMs.

Try Quadratic free

Top comments (1)

Collapse
 
manjunathpatat profile image
Manjunath Patat

Sounds good

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay