Local Pipeline Execution with Act
This guide explains how to run the pull request pipeline locally using nektos/act , which allows you to test GitHub Actions workflows locally without pushing to the repository.
Prerequisites
1. Install Act
macOS (using Homebrew):
brew install actLinux:
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bashWindows:
choco install act-cli2. Install Docker
Act requires Docker to run. Install Docker Desktop or Docker Engine:
3. Setup Environment
- Copy the example environment file:
cp env.local.example .env.local- Customize
.env.localas needed:
# Edit the file to set your preferences
nano .env.localRunning the Pipeline Locally
Basic Usage
Run the entire pull request pipeline:
act pull_requestRun a specific job:
act pull_request -j testManual Trigger
Simulate a manual workflow dispatch:
act workflow_dispatchWith custom inputs:
act workflow_dispatch \
-e <(echo '{"inputs": {"run_tests": "true", "run_security": "false", "run_validation": "true"}}')Advanced Options
Dry run (list what would be executed):
act pull_request --dryrunVerbose output:
act pull_request -vUse specific image:
act pull_request -P ubuntu-latest=catthehacker/ubuntu:act-latestRun with secrets:
act pull_request --secret-file .secretsConfiguration Files
.actrc
The .actrc file contains default configuration for act:
# Use medium-sized image for better compatibility
-P ubuntu-latest=catthehacker/ubuntu:act-latest
# Set environment variables for local execution
--env-file .env.local
# Enable verbose output for debugging
-v
# Use bind mounts for better performance
--bind
# Set working directory
--workflows .github/workflows/
# Enable reuse of containers
--reuse.env.local
Environment variables for local execution:
# Local development settings
ACT_LOCAL=true
# Skip external services for local testing
SKIP_CODECOV=true
SKIP_SECURITY_SCAN=true
# Rust configuration
RUST_VERSION=stable
RHEMA_RUN_INTEGRATION_TESTS=1
# Cargo configuration
CARGO_TERM_COLOR=always
RUST_BACKTRACE=1
RUST_LOG=infoWorkflow Modifications for Local Execution
The pull request workflow has been enhanced with local execution support:
Conditional Steps
-
System Dependencies: Skipped in local mode
-
Security Scanning: Can be disabled via
SKIP_SECURITY_SCAN -
Codecov Upload: Can be disabled via
SKIP_CODECOV
Environment Variables
-
ACT_LOCAL: Indicates local execution mode -
SKIP_CODECOV: Skip Codecov integration -
SKIP_SECURITY_SCAN: Skip security scanning steps
Troubleshooting
Common Issues
1. Docker Permission Issues
# Add user to docker group
sudo usermod -aG docker $USER
# Log out and back in, or restart Docker
2. Image Pull Failures
# Pull the image manually
docker pull catthehacker/ubuntu:act-latest3. Memory Issues
# Increase Docker memory limit in Docker Desktop settings
# Or use a smaller image
act pull_request -P ubuntu-latest=node:16-bullseye4. Network Issues
# Use host networking
act pull_request --network hostPerformance Optimization
1. Use Bind Mounts
act pull_request --bind2. Reuse Containers
act pull_request --reuse3. Use Smaller Images
# For faster startup
act pull_request -P ubuntu-latest=node:16-bullseyeDebugging
Enable Verbose Output:
act pull_request -vCheck Container Logs:
docker logs <container_id>Run Single Step:
act pull_request --list
act pull_request -s <step_name>Best Practices
1. Local Development Workflow
-
Make changes to your code
-
Run tests locally with act
-
Fix issues before pushing
-
Push to GitHub for full CI/CD
2. Environment Management
-
Keep
.env.localin.gitignore -
Use different environment files for different scenarios
-
Document required environment variables
3. Performance
-
Use bind mounts for faster file access
-
Reuse containers when possible
-
Skip external services in local mode
4. Security
-
Never commit secrets to version control
-
Use
.secretsfile for local testing -
Be cautious with security scanning in local mode
Integration with Development Workflow
Pre-commit Testing
Add to your development workflow:
# Before committing
act pull_request --dryrun
act pull_request -j test
# If tests pass, commit
git add .
git commit -m "Your commit message"Continuous Local Testing
Set up a watch script:
# Watch for changes and run tests
fswatch -o . | xargs -n1 -I{} act pull_request -j testIDE Integration
Configure your IDE to run act:
VS Code (tasks.json):
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Pipeline",
"type": "shell",
"command": "act",
"args": ["pull_request"],
"group": "test"
}
]
}Comparison: Local vs Remote
| Feature | Local (Act) | Remote (GitHub) |
|---|---|---|
| Speed | Faster iteration | Full CI/CD |
| Resources | Limited by local machine | GitHub runners |
| External Services | Can be skipped | Full integration |
| Debugging | Easy access to logs | Limited access |
| Cost | Free | GitHub minutes |
| Dependencies | Local Docker setup | Managed by GitHub |
Next Steps
-
Install act and Docker
-
Copy environment file and customize
-
Run your first local pipeline
-
Integrate into your development workflow
-
Optimize for your specific needs
For more information, see the act documentation .