Skip to main content
  1. Writing/

Write GitHub Actions In PowerShell

·282 words

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?

Mount Rainier

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:

FROM ubuntu:18.04

LABEL "com.github.actions.name"="Do something"
LABEL "com.github.actions.description"="Do something else."
LABEL "com.github.actions.icon"="code"
LABEL "com.github.actions.color"="red"

LABEL "repository"="https://github.com/dend/blog"
LABEL "homepage"="https://den.dev"
LABEL "maintainer"="Den"

RUN apt-get update \
    && apt-get install wget -y \
    && wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb \
    && dpkg -i packages-microsoft-prod.deb \
    && apt-get update \
    && apt-get install -y powershell

ADD entrypoint.ps1 /entrypoint.ps1
ENTRYPOINT ["pwsh", "/entrypoint.ps1"]

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:

Get-Help

Now, in the repository where we need to use, we can configure a workflow that points to the action, and do a “dummy” commit:

Run PowerShell GitHub Actions

If you are more comfortably writing PowerShell than bash scripts - you too can take advantage of GitHub Actions!


  1. Image sourced from Pixabay↩︎