Skip to content

Sample project demonstrating how to safely run and test GitHub Actions locally with act in local environment before check-in the code.

License

Notifications You must be signed in to change notification settings

devopshubproject/gh-act-sandbox

Repository files navigation

gh-act-sandbox

Sample project demonstrating how to safely run and test GitHub Actions locally with act in local environment before check-in the code.

GitHub Actions + act + Terraform: Safe Local CI/CD Sandbox

✅ Test GitHub Actions locally.
🔐 Avoid cloud costs.
🧪 Validate functional changes safely.
🖥️ Works on private environments.


🧩 What Is This?

This repository demonstrates how to:

  • Use act to run GitHub Actions locally.
  • Test Terraform workflows safely without applying real infrastructure.
  • Work in secure, private, or self-hosted runner environments.
  • Validate modules, backends, and plans with dummy credentials and local state.

🔧 Prerequisites

  • Docker installed locally
  • act installed (docs)
  • Terraform CLI installed (>= 1.3.0)
  • Linux or macOS (Windows via WSL works too)
  • Optional: self-hosted GitHub Actions runner

🏗️ Repository Structure

.
├── .github/workflows/terraform.yml # GitHub Actions workflow
├── main.tf # Terraform example
├── backend.tf # Local backend config
├── variables.tf # Input variables
├── .secrets.dummy # Fake credentials for act
└── README.md
---

## 🚀 Running Locally with `act`

### 🧪 Dry Run Plan

```bash
act workflow_dispatch \
  -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest \
  --secret-file .secrets.dummy \
  --env DRY_RUN=true

✅ No real cloud infra is touched! Uses local backend and fake secrets.

💡 Tips for Safe Testing

Scenario Recommendation
Avoid real infra changes Use terraform plan, local backend, dummy secrets
Test apply logic Wrap in if: env.DRY_RUN != 'true'
Network-sensitive Run with --bind or isolate Docker network
Debug failures Add --verbose to act or run in bash container

📦 Why This Matters

act enables fast, cost-free testing of GitHub Actions workflows. Combined with Terraform and local backends, it lets you:

  • Catch errors early

  • Avoid cloud billing

  • Safely debug changes

🔧 Commands

🔧 Category 🧪 Command 💬 Description
Run default workflow act Runs default event (push) using default runner (ubuntu-latest)
Run specific event act pull_request Simulates a pull_request event
act workflow_dispatch Simulates a workflow_dispatch (manual trigger)
Run specific job act -j terraform Runs only the terraform job
Use custom runner image act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest Uses a GitHub-hosted runner-like Docker image
Use secrets inline act -s GITHUB_TOKEN=mytoken -s ARM_CLIENT_ID=fake Passes secrets directly in the command
Use secrets from file act --secret-file .secrets.dummy Loads secrets from a file
Set env variables act --env DRY_RUN=true Sets environment variable DRY_RUN=true
Specify workflow file act -W .github/workflows/terraform.yml Explicitly runs a specific workflow file
Verbose/debug mode act --verbose Enables verbose output for debugging
Mount local volume act -v $(pwd):/github/workspace Mounts local working directory inside the container
Run from Docker manually docker run --rm -it -v $(pwd):/github/workspace your-act-image act workflow_dispatch Manually runs act from a Docker container
  • Test from secure/self-hosted runners

📚 Resources

License

This project is licensed under the MIT - see the LICENSE file for details.

Please replace https://github.com/premkumar-palanichamy/gh-act-sandbox with the URL of your Git repository if you have one. This README provides a comprehensive guide to your Git Mirroring concept and can be extended or modified as needed.

Follow-Me

Portfolio

premkumarpalanichamy

youtube

About

Sample project demonstrating how to safely run and test GitHub Actions locally with act in local environment before check-in the code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published