Testing GitHub Actions Workflows Locally with act
Overview
This guide explains how to test GitHub Actions workflows locally usingact 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 withModuleNotFoundError: No module named 'black'
What Happened:
Quick Start
Prerequisites
-
Docker Running:
-
act Installed:
Basic Workflow Testing
Common Testing Patterns
1. Validate Workflow Syntax Only (Fast)
2. Test Specific Job (Recommended)
3. Test Full Workflow
4. Test Different Events
Testing Workflow Changes - Complete Example
Scenario: Adding New Dependency
Step 1: Make ChangesCommon Issues and Solutions
Issue #1: Docker Not Running
Symptom:Issue #2: Container Image Not Found
Symptom:Issue #3: Workflow Runs But Fails Due to Missing Infrastructure
Symptom:- ✅ Dependency installation succeeds
- ✅ Test collection works (no import errors)
- ⚠️ Test execution may fail (infrastructure missing - OK)
Issue #4: Secrets Not Available
Symptom:Makefile Integration
Available Commands
What to Look For During Testing
✅ Success Indicators
- Dependencies install without errors
- No “ModuleNotFoundError”
- No “command not found”
- Tests collect successfully
❌ Failure Indicators to Fix
⚠️ Expected Failures (Can Ignore)
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:
.secrets is gitignored - never commit it!
Integration with Development Workflow
Recommended Process
Before Every Workflow Commit:
- ✅ Validate:
make validate-workflows - ✅ Test with act:
act push -W .github/workflows/YOUR_FILE.yaml -j JOB_NAME - ✅ Fix any issues found by act
- ✅ Run pre-commit:
pre-commit run --all-files - ✅ Commit:
git commit -m "..." - ✅ Push:
git push - ✅ 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:| Metric | Target | Current |
|---|---|---|
| Workflow changes tested with act before commit | 100% | ~0% → 100% (new policy) |
| CI failures from preventable issues | <5% | Reducing |
| Time to detect issues | <5 min (local) | Was: 10+ min (CI) |
| CI minutes wasted | <50 min/month | Reducing |
Resources
- act Documentation: https://nektosact.com/
- act GitHub: https://github.com/nektos/act
- Makefile Targets: Run
make helpand look for “Workflow Testing” - Project CI/CD Guide: CI/CD Troubleshooting
Last Updated: 2025-11-02 Status: Active - Required for all workflow changes Tool Version: act v0.2+ recommended