Skip to main content

Testing GitHub Actions Workflows Locally with act

Overview

This guide explains how to test GitHub Actions workflows locally using act before pushing changes to GitHub, preventing CI failures and wasted CI minutes.

Why Test Workflows Locally?

Benefits

  • Catch issues before CI: Find missing dependencies, syntax errors, configuration mistakes
  • Save CI minutes: Avoid wasting GitHub Actions minutes on fixable issues
  • Faster feedback: Test in seconds vs. minutes waiting for CI
  • Better confidence: Know changes work before pushing

Real Example from This Project

Historical Issue: E2E tests failing with ModuleNotFoundError: No module named 'black' What Happened:
If We Had Tested with act:
Savings: ~30 min of debugging + wasted CI minutes

Quick Start

Prerequisites

  1. Docker Running:
  2. act Installed:

Basic Workflow Testing


Common Testing Patterns

1. Validate Workflow Syntax Only (Fast)

Use when: Quick syntax check before detailed testing
Use when: Modified specific job, want fast feedback

3. Test Full Workflow

Use when: Testing workflow-level changes (triggers, dependencies)

4. Test Different Events


Testing Workflow Changes - Complete Example

Scenario: Adding New Dependency

Step 1: Make Changes
Step 2: Validate Syntax
Step 3: Test with act
Step 4: Fix Issues Found If act shows errors:
Step 5: Commit & Push

Common Issues and Solutions

Issue #1: Docker Not Running

Symptom:
Solution:

Issue #2: Container Image Not Found

Symptom:
Solution:

Issue #3: Workflow Runs But Fails Due to Missing Infrastructure

Symptom:
Expected Behavior: This is normal! act can’t run full test infrastructure. What to Check:
  • ✅ Dependency installation succeeds
  • ✅ Test collection works (no import errors)
  • ⚠️ Test execution may fail (infrastructure missing - OK)
Focus on: Setup steps, not test results

Issue #4: Secrets Not Available

Symptom:
Solution:

Makefile Integration

Available Commands


What to Look For During Testing

✅ Success Indicators

Good signs:
  • Dependencies install without errors
  • No “ModuleNotFoundError”
  • No “command not found”
  • Tests collect successfully

❌ Failure Indicators to Fix


⚠️ Expected Failures (Can Ignore)

Why it’s OK: Test infrastructure (Postgres, Redis, etc.) not running in act environment. What to verify: Tests COLLECT without import errors, even if they skip/fail during execution.

Performance Tips

Faster Testing

Parallel Testing


act Configuration Reference

.actrc File

Located at: /home/vishnu/.config/act/actrc

.secrets File (Optional)

Create .secrets for workflows that need credentials:
Important: .secrets is gitignored - never commit it!

Integration with Development Workflow

Before Every Workflow Commit:

  1. Validate: make validate-workflows
  2. Test with act: act push -W .github/workflows/YOUR_FILE.yaml -j JOB_NAME
  3. Fix any issues found by act
  4. Run pre-commit: pre-commit run --all-files
  5. Commit: git commit -m "..."
  6. Push: git push
  7. Monitor: gh run watch

Troubleshooting

act Command Not Found

Workflow Not Found

Too Slow


Advanced Usage

Testing with Different Runner Images

Debugging Specific Steps

Testing Locally Modified Workflows Without Committing


Success Metrics

Track these to measure effectiveness:

Resources


Last Updated: 2025-11-02 Status: Active - Required for all workflow changes Tool Version: act v0.2+ recommended