Den Delimarsky

I am an engineer working on cloud infrastructure, developer experiences and machine learning.

github twitter linkedin youtube rss

Write GitHub Actions In PowerShell

Dec 12, 2018
2 minutes read

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.
  • - the shell script that is executed when the Action is bootstrapped.

In our case, we will change things up a bit, and instead of 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 ""="Do something"
LABEL "com.github.actions.description"="Do something else."
LABEL "com.github.actions.icon"="code"
LABEL "com.github.actions.color"="red"

LABEL "repository"=""
LABEL "homepage"=""
LABEL "maintainer"="Den <>"

RUN apt-get update \
    && apt-get install wget -y \
    && wget -q \
    && 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:


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!


Have any thoughts? Let me know on Twitter!

  1. Image sourced from Pixabay. [return]

Back to posts