I am Nik Butler

Knowledge Knolling

Running Github Actions Locally

The project Nektos provides a tool kit to explore and develop github actions locally by creating a local dev environment . It uses a command named act to emulate the github action. The Act use guide has more information

Requirements

When I ran this process I was using a Windows 11 desktop; your OS may vary.

Github Desktop Windows Subsytem Linux Visual Studio Code

Since I am running windows subsystem linux under windows so I have used Homebrew to install the client ( note this is a bit build/intensive ). I can then run this command the Ubuntu shell within the Visual Studio Code workspace.

brew install act --HEAD

##Running for the first time##

if you have need of handing SECRETS you will need to load these into your act command as well and so to do this ENSURE your secrets are not stored in the repo add the following to your .gitignore

act/act.secrets

now create your new folder and file

mkdir ./act
cat > ./act/act.secrets
LIVE_DEPLOY_KEY="your id key here"

From within the Terminal windows of Visual Studio Code in the Ubuntu Desktop provided by Windows Subsystem Linux we run act for the first time and it will check to ensure there is a .github/workflow folder. then

nikbutler@RH20220829001:/mnt/c/Users/Public/Github/plugin_example_local$ act --secret-file act/act.secrets -W '.github/workflows/deploy.yml'
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
? Please choose the default image you want to use with act:
  - Large size image: ca. 17GB download + 53.1GB storage, you will need 75GB of free disk space, snapshots of GitHub Hosted Runners without snap and pulled docker images
  - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with most actions
  - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions

Default image and other options can be changed manually in /home/nikbutler/.config/act/actrc (please refer to https://github.com/nektos/act#configuration for additional information about file structure)  [Use arrows to move, type to
filter, ? for more help]
  Large
> Medium
  Micro

I selected Medium for the Storage image

This now builds a container and runs the github actions within the container and reports back the result. take care it will operate on all the workflows in your .github/workflow folder unless you are declaring the yml file with the -W argument.

##testing out a workflow##

act --secret-file act/act.secrets -W '.github/workflows/deploy.yml'

This ran the workflow command and built the container to run it within. It then handled the env.secrets variables from act.secrets and it processed the steps/jobs in the .yml

Manually building from source##

  • Install Go tools 1.20+ - (https://golang.org/doc/install)
  • Clone this repo git clone git@github.com:nektos/act.git
  • Run unit tests with make test
  • Build and install: make install