11 KiB
GitHub Actions Testing with Act - Complete Implementation
This document provides a comprehensive overview of the act testing implementation for diagnosing and fixing GitHub Actions workflow failures.
What Was Implemented
1. Documentation
docs/ACT_TESTING.md - Complete Guide
Comprehensive documentation covering:
- What act is and why to use it
- Installation instructions for all platforms
- Quick start guide
- Testing all project workflows
- Common issues and solutions
- Advanced usage patterns
- Debugging workflows step-by-step
- Best practices and CI workflow
docs/ACT_QUICK_REFERENCE.md - Quick Reference Card
Condensed cheat sheet with:
- Essential commands
- Common fixes table
- Pre-push checklist
- Troubleshooting flowchart
- Useful aliases
- Emergency fixes
docs/github-actions-local-testing.md - Technical Deep Dive
Detailed technical documentation including:
- Act fundamentals
- Workflow-specific testing
- Custom event payloads
- Secrets management
- Platform specifications
- Current known issues in project
2. Testing Scripts
scripts/diagnose-workflows.sh - Diagnostic Tool
Bash script that checks for workflow issues without running act:
- ✅ Validates package.json structure and scripts
- ✅ Checks for required dependencies
- ✅ Verifies Prisma setup
- ✅ Validates Playwright configuration
- ✅ Checks node_modules installation
- ✅ Inspects workflow files
- ✅ Validates environment configuration
- ✅ Checks git ignore settings
- 📊 Provides detailed report with issue counts
- 💡 Suggests fixes for each problem
Usage:
chmod +x scripts/diagnose-workflows.sh
./scripts/diagnose-workflows.sh
Output:
- Green ✓ for passing checks
- Yellow ⚠ for warnings
- Red ✗ for critical issues
- Actionable fix suggestions for each issue
- Exit code reflects issue count
scripts/test-workflows.sh - Interactive Testing Tool
Interactive menu-driven script for running workflows with act:
- 📋 Lists all workflows and jobs
- 🔍 Dry run preview
- 🧪 Test individual jobs
- 🔄 Run full CI pipeline
- 📝 Verbose output mode
- 🩺 Built-in diagnostics
- 📁 Saves logs to
/tmp/for analysis - ✨ Color-coded output
- 📊 Summary report
Menu Options:
- List all workflows
- Dry run (preview)
- Test Prisma setup
- Test linting
- Test build
- Test E2E tests
- Run full CI pipeline
- Run with verbose output
- Diagnose issues
3. Updated Documentation
.github/workflows/README.md
Enhanced with:
- Act testing section
- Links to comprehensive guides
- Troubleshooting with act examples
- Command examples for each workflow
README.md
Updated with:
- Act installation instructions
- Quick testing commands
- Links to detailed documentation
- Integration with existing workflow
How to Use
For First-Time Setup
-
Install Prerequisites:
# Install Docker (if not already installed) # macOS: Docker Desktop # Linux: docker.io package # Windows: Docker Desktop # Install act # macOS brew install act # Linux curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash # Windows choco install act-cli -
Run Diagnostics:
./scripts/diagnose-workflows.sh -
Fix Reported Issues: Follow the fix suggestions in the diagnostic output.
-
Test Workflows:
./scripts/test-workflows.sh
For Daily Development
Before Every Commit:
npm run lint
npm run build
Before Every Push:
./scripts/diagnose-workflows.sh
act -j lint -j build
Before Creating PR:
./scripts/test-workflows.sh
# Select option 7 (full CI pipeline)
When Workflow Fails on GitHub:
# Run the same job locally
act -j <job-name> -v
# Or use interactive menu
./scripts/test-workflows.sh
Workflow Coverage
Workflows That Can Be Tested
✅ ci.yml - Full Support
All jobs can be tested locally:
prisma-check- Validates Prisma setuplint- Runs ESLintbuild- Tests production buildtest-e2e- Runs Playwright tests
Test with:
act push
# or individually
act -j prisma-check
act -j lint
act -j build
act -j test-e2e
⚠️ code-review.yml - Limited Support
Can be tested but requires PR context:
act pull_request -W .github/workflows/code-review.yml
Use custom event payload for better simulation.
⚠️ auto-merge.yml - Limited Support
Requires GitHub API access, may not work fully locally.
⚠️ pr-management.yml - Limited Support
Can be tested with custom event payload:
act pull_request -W .github/workflows/pr-management.yml -e event.json
Known Limitations
-
GitHub API Calls: Workflows that use
github.rest.*APIs may not work fully with act. -
Secrets: Some workflows may require secrets. Create
.secretsfile (don't commit!). -
Docker Resources: E2E tests may require more Docker memory (8GB+).
-
Browser Tests: Playwright tests may behave differently in Docker environment.
Troubleshooting Guide
Issue: Act Not Found
Symptoms:
bash: act: command not found
Solution: Install act:
- macOS:
brew install act - Linux:
curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash - Windows:
choco install act-cli
Issue: Docker Not Running
Symptoms:
Cannot connect to the Docker daemon
Solution: Start Docker Desktop or Docker daemon.
Issue: Missing Dependencies
Symptoms:
npm ERR! missing: @prisma/client
Solution:
npm install
Issue: Prisma Schema Not Found
Symptoms:
Error: Could not find Prisma schema
Solution:
npx prisma init
# Edit prisma/schema.prisma
npx prisma generate
Issue: Docker Out of Memory
Symptoms:
Error: Process completed with exit code 137
Solution: Open Docker Desktop → Settings → Resources → Increase Memory to 8GB+
Issue: Workflow Passes Locally but Fails on GitHub
Possible Causes:
package-lock.jsonnot committed- Environment differences
- Secrets not available on GitHub
- Different Node version
Solution:
# Ensure lockfile is committed
git add package-lock.json
git commit -m "Update package-lock.json"
# Test with exact CI environment
act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
File Structure
/workspaces/spark-template/
├── .github/
│ └── workflows/
│ ├── README.md # Updated with act instructions
│ ├── ci.yml # Main CI workflow
│ ├── code-review.yml # Automated PR review
│ ├── auto-merge.yml # Auto-merge workflow
│ └── pr-management.yml # PR labeling
├── docs/
│ ├── ACT_TESTING.md # NEW: Complete testing guide
│ ├── ACT_QUICK_REFERENCE.md # NEW: Quick reference card
│ └── github-actions-local-testing.md # NEW: Technical deep dive
├── scripts/
│ ├── diagnose-workflows.sh # NEW: Diagnostic tool
│ └── test-workflows.sh # NEW: Interactive testing
└── README.md # Updated with act section
Benefits
1. Faster Development
- Test workflows locally before pushing
- No need to push "fix CI" commits
- Immediate feedback on workflow issues
2. Better Debugging
- Verbose output shows exactly what fails
- Logs saved for analysis
- Can run specific jobs in isolation
3. Cost Savings
- Reduce GitHub Actions minutes usage
- No pollution of commit history
- Faster iteration cycles
4. Improved Confidence
- Know workflows will pass before pushing
- Catch issues early in development
- Better understanding of CI/CD pipeline
5. Learning Tool
- See how workflows execute
- Understand Docker environment
- Learn GitHub Actions behavior
Next Steps
For Users
- Install act following platform-specific instructions
- Run diagnostics to ensure project is ready
- Test one job to verify act is working
- Integrate into workflow - run before pushing
- Share knowledge with team members
For Maintainers
- Create ~/.actrc with common settings
- Set up aliases for frequently used commands
- Document project-specific quirks in README
- Update workflows to be act-friendly
- Add act to CI/CD documentation
Advanced Features
Custom Event Payloads
Create event.json:
{
"pull_request": {
"number": 1,
"title": "Test PR",
"body": "Testing with act"
}
}
Use with:
act pull_request -e event.json
Secrets Management
Create .secrets (add to .gitignore!):
GITHUB_TOKEN=ghp_your_token
DATABASE_URL=postgresql://localhost/db
Use with:
act --secret-file .secrets
Platform Specification
Create ~/.actrc:
-P ubuntu-latest=catthehacker/ubuntu:act-latest
--secret-file .secrets
--env ACT=true
Conditional Steps
Skip steps in act environment:
- name: Deploy to production
if: ${{ !env.ACT }}
run: ./deploy.sh
Resources
Documentation
- ACT_TESTING.md - Complete guide
- ACT_QUICK_REFERENCE.md - Quick reference
- github-actions-local-testing.md - Technical details
Scripts
./scripts/diagnose-workflows.sh- Diagnostics./scripts/test-workflows.sh- Interactive testing
External Resources
Support
Getting Help
- Run diagnostics:
./scripts/diagnose-workflows.sh - Check documentation:
docs/ACT_TESTING.md - Check logs:
/tmp/act_output_*.log - Verbose mode:
act -j <job> -v - Check act docs: https://github.com/nektos/act
- Open issue: Include diagnostic output
Common Questions
Q: Do I need to install act?
A: No, but it's highly recommended. You can use the diagnostic script without act.
Q: Can I test all workflows?
A: Most workflows work. Those requiring GitHub API may have limitations.
Q: Is Docker required?
A: Yes, act uses Docker to simulate the GitHub Actions environment.
Q: How much disk space do I need?
A: ~5GB for Docker images, more if running E2E tests.
Q: Can I use act in CI/CD?
A: Not recommended. Act is for local development/testing.
Conclusion
This implementation provides a complete solution for testing GitHub Actions locally using act, with:
- ✅ Comprehensive documentation at multiple levels
- ✅ Interactive and automated testing tools
- ✅ Diagnostic capabilities without Docker
- ✅ Clear troubleshooting guides
- ✅ Integration with existing workflows
- ✅ Best practices and patterns
Users can now:
- Quickly diagnose workflow issues
- Test workflows before pushing
- Debug failures locally
- Reduce CI/CD iteration time
- Build confidence in their changes
Last Updated: 2024 Maintainer: Project Team Version: 1.0.0