Github Actions - Developing Workflows before merge
TL;DR - Commit a dummy workflow to main, develop and trigger manually from another branch
Background
When I was developing a Github Actions Workflow I was confused as to how to test it and tweak it before creating a Pull Request and asking for a review. It isn't as straightforward as you could imagine but it turns out it's not that difficult. Our repository already had GH Actions workflows so when trying to select the one I pushed to a git branch it didn't show up.
For this post, we'll be creating a Github Workflow which runs some NPM scripts, and make it possible to trigger it manually.
Setup
In your repository, checkout your main branch and, if you don't already have one, create a workflows folder inside a .github
-folder. .github/workflows
will - you guessed it - contain your workflow yml files. This workflow file is basically a dummy file which we will commit and push directly to main (not for the faint of heart!). Let's open up the terminal and get going:
The workflow below doesn't really do anything, but it will allow us to find it and trigger it manually from another git branch later. It is safe to commit to your main branch, just make sure you don't commit and push other unrelated code.
Let's head back to the terminal and finish the setup.
Get to work
Let's work on the new workflow in the feature-branch, create a Pull Request and try it out directly from Github before commiting it to your main branch.
You can now select the workflow from the list using the name provided in the .yml-file.
Once selected, choose what branch to run it from, and now you're ready to incrementally add steps and jobs to your workflow on your working branch! For more information on how to setup a Github Actions Workflow, please refer to the documentation.
In this post, we'll take a look at how to parallelise your build and make use of the Github Actions runner cache to speed up builds!