-
-
Notifications
You must be signed in to change notification settings - Fork 17
Testing Github Actions Locally
We're implementing a tool called Act. Act is a CLI tool that will allow us to test our Github Actions(GHAs) locally without having to create a duplicate project board.
Act uses Docker to create a container for our GHAs to run without affecting our project board.
To download directly from docker, click here
After downloading, start the application. Accept the recommended settings and enter your password if prompted. You aren’t required to make an account.
To download Act using Homebrew run brew install act
. This is a global download, so you don’t need to be in the project folder.
There are several ways to download Act. Feel free to use your preferred method.
Act allows us to call and run workflows by the trigger event, name, or a combination of the two. We currently don’t have very many actions (only one at time of writing), so using event is okay to call the actions. But as our GHAs scale, it will eventually be more convenient to use the workflow name to avoid having to wade through unrelated action logs.
First navigate to the root /expunge-assist
folder. This is where our .github/workflows
folder is. Running the act command requires that the terminal be located in the folder containing the .github/workflows
folder.
The first time you call the act
command in a project, you will be prompted to select a Docker container size. Micro will work for our purposes.
Otherwise, calling the act
command without an event will call the push event by default and trigger all actions connected to the push event.
Easiest but least specific way to trigger the workflows is by event. This works for now, but as we expand our actions, it will start to take a long time and have unrelated logs to sort through.
act EVENT [--var VARNAME=val] [-s GITHUB_TOKEN]
By default, the act
command without a specific event will run the push event. List of events that trigger workflows.
Values within the square brackets are only required if necessary for that github action.
More specific is to run by workflow file.
act -W .github/workflows/filename.yml [event] [-s GITHUB_TOKEN]
The event
and GITHUB_TOKEN
variables are only required if needed for that workflow.
Some actions require a personal access token from github. These tokens expire and have to be remade every once in a while.
To create a personal access token,
- go to your personal settings.
- On the bottom of the left hand menu, select Developer Tools.
- Select Tokens (classic)
- Fill out the prompts
- make sure to give access to ‘workflows’
- Leave 30 day expiration
- Copy and save somewhere protected, like a password manager
Reach out to the Dev Lead to add your token to the repository secrets.
If a workflow requires a github token, include it in the command after event call.
act schedule -s GITHUB_TOKEN
In this case, schedule
is the event. This will call all actions on a schedule.
If you haven’t previously entered your Github Token, it will take you to a secure input for you to enter your token. Future runs of this command will use the saved token automatically.
The last step of the deploy action fails. I think because it doesn’t have any changes to deploy? Error says something about not finding the .git folder. Needs more research.
The Wiki is a working document and we would love to improve it. Please compile any questions and suggestions you may have and submit it via GitHub. Here's information on how to create a GiHub issue.