5

I'd like to create a GitHub action that sets up an environment in Windows, running a few Powershell commands. Despite this can be done easily as a step, there does not seem to be a way to create a complete GitHub action for that. If I use this:

name: 'Rakudo Star fix for windows'
description: 'Updates zef for RakudoStar'
author: 'JJ'
runs:
  using: 'node12'
  main: 'upgrade.ps1'

There does not seem a way to run anything other than a JS script, or even to declare the environment. I understand that's left for later, during the job steps, but anyway it looks like a hack. Is there anything I'm missing here?

ugexe
  • 5,297
  • 1
  • 28
  • 49
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 1
    I just posted an answer to your question here: https://stackoverflow.com/questions/59184730/running-a-powershell-script-from-a-node-program-in-a-github-action/59185536#59185536 – Peter Kay Dec 04 '19 at 22:30
  • 2
    I just skimmed the docs and my understanding is, that `main` is expected to be `JavaScript` because you say it should be executed via `Node`, right? So in order to be able to use a Powershell script there you'd need to say so in the `using` field. So, `using: 'pshell.exe'` or something akin to that. – Holli Dec 05 '19 at 10:59
  • @PeterKay Do you agree with Holli's understanding above? – raiph Dec 19 '19 at 00:26
  • 1
    @raiph The `using` field is the application to use to execute the code specified in `main`. But Github Actions only support using `node12` and `docker`. As seen from this GHActions I just ran for example's sake. https://github.com/kaypeter87/GitHubActions-PSTest/commit/a6259247739b00998e5ca74f16016383fc9d01a6/checks?check_suite_id=367606540 – Peter Kay Dec 19 '19 at 23:03
  • 2
    Thank you @PeterKay. So perhaps you could edit your answer to make it clear that there are only those two options, namely running JS or docker, and the latter won't run in most Windows environments, and thus JJ's follow up question and your answer are the only way forward for someone with JJ's scenario. Then perhaps JJ will accept your answer below to make it clear that it is as acceptable for this question as your other answer is to JJ's follow up question. (Alternatively, you can do nothing because anyone reading this will presumably now get the picture.) Either way, thanks for replying. :) – raiph Dec 19 '19 at 23:36
  • 1
    @raiph thanks for the great moderating! I went ahead and updated the answer below for clarity. – Peter Kay Dec 20 '19 at 19:54

1 Answers1

4

You could also run docker directly with an entrypoint for the .ps1 script

FROM ubuntu:18.04

LABEL "com.github.actions.name"="test"
LABEL "com.github.actions.description"="test."

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 test.ps1 /test.ps1
ENTRYPOINT ["pwsh", "/test.ps1"]

Update:

The using field is the application to use to execute the code specified in main. But Github Actions only support using node12 and docker. As seen from this GHActions I just ran for example's sake.

Docker won't run in most Windows environment and you'd have to use Windows Server 2019 as your base environment.

Peter Kay
  • 926
  • 1
  • 7
  • 18
  • 1
    Docker environments don't run in Windows. – jjmerelo Dec 05 '19 at 06:10
  • 1
    Technically, you can with process isolation. Though, it is only possible in Windows 10/Server 2019. – Peter Kay Dec 05 '19 at 09:15
  • 1
    But is Windows Server 2019 available as base environment in GitHub Actions? – jjmerelo Dec 22 '19 at 08:42
  • 1
    It is, it can be assigned using `windows-latest`, you can also look at available software/OS here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners and here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners – Peter Kay Dec 31 '19 at 20:32