Photo by Jakob Owens on Unsplash

In the ever-evolving landscape of software development, efficiency in testing and validating workflows is crucial. “Act” is a powerful tool designed to enhance and streamline the testing process within GitHub Actions. This tool is not only a time-saver but also a facilitator for a smoother and more reliable CI/CD pipeline.

Think globally act locally

Why act — Key features

  1. Local Workflow Testing — Act allows developers to run GitHub Actions workflows locally on their machines. This feature is invaluable for rapid iteration and debugging before pushing changes.
  2. Isolated Testing Environment — Act creates an isolated environment that closely resembles the GitHub Actions runtime. This ensures that the local test results are consistent with the actual workflow outcomes.
  3. Workflow Selection — Developers can specify which workflows or jobs to test locally, enabling targeted testing of specific components rather than the entire workflow.
  4. Simple Integration — With a straightforward setup, Act seamlessly integrates into existing GitHub Actions workflows. Developers can incorporate it into their CI/CD pipelines without disrupting the established processes.

How to get started

  1. Install act —
  2. Clone the repository that needs github action and create a branch or use existing one. (For this, I am using a branch named ghactions)

Let us assume that this workflow will display the commit message and the author who made that push on a particular branch. If we are not using this tool, we will be testing this workflow by making an actual push to github. But act provides local testing without the need of an actual push to github.

Create .github/workflows directory and the file below:

The above workflow has one job named check-push and it will display the commit message and author name whenever a push event happens to ghactions branch. Also, this is using a self-hosted runner, which is a Linux variant.

By default, everyone will assume that simulating the above needs a lot of payload and event-triggering actions locally. But act uses docker for executing the above workflow and JSON payloads for event triggering.

When a push event happens, payload for that event will look like this —

push-event.json resonates the same for the above. The major attributes to be checked here are head_commit.message and They should be supplied with testing values because those two fields are used in the workflow.

echo “Commit message: ${{ github.event.head_commit.message }}”
echo “Committed by: ${{ }}”

Now, the following command should be executed —

act -j check-push -e push-event.json -P self-hosted=ubuntu

From my laptop

In the above screenshot, we can see that the Commit message and Committed by are the same as mentioned in the push-event.json

Act helps minimize resource consumption by avoiding unnecessary executions on the GitHub Actions platform during the development and testing phase.

“Act” empowers developers to take control of their GitHub Actions testing, fostering a more efficient and reliable software development lifecycle. By providing a local testing environment, Act enhances the overall workflow testing experience, contributing to the creation of high-quality software with confidence.