Yeah, being doing the CI/CD implementations via github workflow lately and i am also trapped in the process of making commits to trigger the workflows or better still making empty commits, haha.
Well, you can say why don't you just use Jenkins, CircleCi, Gitlab CI? i think this all boils down to what your org uses, i think there is no need to go the jenkins way, when my org uses github and github has the workflow to implement CI/CD.
Now, looking at the above screenshot, i am very sure that's how your Actions page looks like too, but what if you could test the workflows you write locally before pushing it to github?
That way, you can limit the spammy look of failed builds on your Actions page.
Act is a golang tool that allows you to run your GitHub Actions locally 🚀, making the feedback process really quick for your tests.
Now let's jump into how to use this
Firstly, you will need to install docker, Act depends fully on it,
Done with that? now lets install
act on our enviroment, i use macOS, so i will be installing it using
brew, you can also install on linux using
brew install act
You can as well check the installation guide for other installation methods.
Time to run your github actions locally
Done with the installation of
act ? it's time to run act.
Navigate into your project folder where you have your github workflow files and run the following command on your terminal.
That should spin things up and then display some outputs where you are asked to select the image you would like to use with
You will only see this once, because it's your first time running `
You can choose the medium image size, it is sufficient and okay, way better than micro option, after selecting the image size and hitting the enter button.
It will run and spin up the ~/.actrc file that contains the image configurations, you can always change this manually anytime.
So Immediately after selecting the image size,
act also auto detect any workflow file in your .github/workflow folder and it will proceed with spining up a docker conatiner and run the actions workflows in it.
Whenever the github actions workflow is done, the docker container gets discarded, but there is a way around that
In situations where you need to get the results/feedback of your workflow actions which are probably passed to html, json or xml files as output, you won't be able to access it because the docker container gets discarded.
act has a subcommand to help with that, which makes your docker containers resusable.
hence you can enter the docker container to view your actions output or copy it into your local system, which everone is okay with you.
Here is the parameter to achieve that
Saving time on running your actions locally
You can also save time running this actions workflows, sure you don't want to wait all day for the local option you've choosen to take so much of your time, so if you will be running npm install or yarn install in your workflow and by chance already have a node_modules folder in your project root.
act can feed on the node_modules folder and speed/skip the dependencies installation process, here is the command to get that done
Yeah, there is more, what about the github actions secrets? will your workflows with the secrets run locally? Yes they will
Passing secrets into your local github actions workflow
Passing github workflow secrets can be done in various ways, you can enter them manually using the
act -s GITHUB_TOKEN=[insert token]
Alternatively, you can use the
--secret-file parameter too, that way you can pass more workflow secrets along with your workflow, just create and open my.secrets file in your project root folder.
Then add your action secrets into the file in the following formats
then run the file with the
act --secret-file my.secrets
And thats all, there are more
act options you can play with to speed up your devsecops or devops with github action by testing workflows locally.