Write GitHub Actions In PowerShell
Run PowerShell commands from GitHub Actions instead of default bash shell.
By Den Delimarsky in Automation
December 12, 2018
I was just chatting with my good friend Anthony Chu about containers and an idea struck me - I love GitHub Actions, I love PowerShell. I wonder if the two would work together?
Mt. Rainier1
Science says yes! An easy way to do that is to rely on PowerShell Core. When creating custom actions, by default you need the following components:
Dockerfile
- the definition of the container within which the action is executed.entrypoint.sh
- the shell script that is executed when the Action is bootstrapped.
In our case, we will change things up a bit, and instead of entrypoint.sh
we’ll have entrypoint.ps1
. To make sure we can use PowerShell Core within the entrypoint script, we also need to do some preparation work within the Dockerfile
itself. That preparation is the installation of PowerShell - your Dockerfile
will end up looking like this:
|
|
That’s it - there is no additional configuration needed. Notice that compared to standard GitHub Actions examples, I’ve just replaced the bash script with the PowerShell script.
Will that work? Let’s put something basic in entrypoint.ps1
:
|
|
Now, in the repository where we need to use, we can configure a workflow that points to the action, and do a “dummy” commit:
If you are more comfortably writing PowerShell than bash scripts - you too can take advantage of GitHub Actions!
Feedback
Have any thoughts? Let me know on Twitter!