Multiline commands on Windows do not fail if individual commands fail

I have a step like this:

- name: npm ci, lint and build
  run: |
    npm ci
    npm run lint
    npm run build

This is very similar to one shown in the docs, however on Windows if the first command fails, the other commands still run and the step is considered to have passed (see here):

This results in a failure further down (in a step that relies on this one having worked) which is a bit confusing to track down.

It’s possible this is because of PowerShell’s default value of $ErrorActionPreference being Continue, but I think GH Actions should override it if that’s the case - it’s probably not what people would expect as the default behaviour for CI (and it’d be nice if by default the behaviour across OSes was as consistent as possible).

2 Likes

Hi DanTup,

Thanks for your feedback!

I copied your repro and reproduced the issue. I have submitted a query internally,  i will update once there is a response.

PS: It’s not repro for shell cmd/bash. 

> PS: It’s not repro for shell cmd/bash. 

Yeah, that makes sense if it’s caused by PowerShell’s default $ErrorActionPreference. The shell commands are detailed here:

https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell

I think the pwsh and powershell ones should maybe be something like:

pwsh -command "$ErrorActionPreference = 'Stop'; & {0}"

This would cause the scripts to stop on errors isntead of continuing.

Hi @dantup ,

Sorry for late response, confirmed with github stuff, yes this is a powershell behavior. Error action preference only stops for a failed cmdlet. A failed external command (e.g. npm process) does not stop the script from proceeding.

An an alternative, please use bash/cmd shell.

Thanks.

I understand that it’s PoSh default behaviour, but it seems strange for Travis to use this as default - it’s not really what people will expect. I posted an example above of how it might be changed to stop on error the same as other shells - I think most users would probably prefer that?

Thanks @dantup ! According to the policy, it’s recommended to share your idea here where github product manager will take a review. It could be an improvment for github action.

This just bit me, @dantup could you find a workaround for this issue?