Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell does not return the correct non-zero exit code #351

Open
johnstevenson opened this issue Mar 2, 2020 · 5 comments
Open

Powershell does not return the correct non-zero exit code #351

johnstevenson opened this issue Mar 2, 2020 · 5 comments
Assignees
Labels
Runner Bug Bug fix scope to the runner

Comments

@johnstevenson
Copy link

Describe the bug
Powershell does not return the correct exit code if it is non-zero and not 1.

To Reproduce
Steps to reproduce the behavior:

  1. Create an action that outputs an exit code that is not 0 or 1.
run: php -r "exit(42);"
shell: pwsh
  1. See error, as in this example from https://github.com/johnstevenson/runner-actions-test/actions/runs/48177580 which shows the correct behaviour for cmd and bash and the error from pwsh.

action-error-exit

Expected behavior
For powershell to return the exit code returned by the script.

Runner Version and Platform

Current runner version: 2.165.2
Tested on ubuntu-latest, macos-latest and windows-latest

See https://github.com/johnstevenson/runner-actions-test/actions/runs/48202446 for tests that use .bat, .sh and .ps1 scripts rather than using the php code.

What's not working?

The code that is appended to the powershell script in FixUpScriptContents:

var append = @"if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE }";

This can be fixed by either changing the line to:

var append = @"if (Test-Path -LiteralPath variable:\LASTEXITCODE) { $Host.SetShouldExit($LASTEXITCODE) }"; 

or by executing the script as a file, rather than a command which always returns the correct exit code:

["pwsh"] = "-command \". '{0}'\"",
["powershell"] = "-command \". '{0}'\"",

        ["pwsh"] = "-file \"'{0}'\""
        ["powershell"] = "-file \"'{0}'\"",

Incidentally, the documentation at https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell shows the powershell internal commands as pwsh -command "& '{0}'" rather than pwsh -command ". '{0}'", but I'm not sure where to report this.

@johnstevenson johnstevenson added the bug Something isn't working label Mar 2, 2020
@bryanmacfarlane
Copy link
Member

@thboop - this is a dupe right?

@thboop
Copy link
Collaborator

thboop commented Mar 3, 2020

@thboop - this is a dupe right?

I do not believe so.

@thboop thboop self-assigned this Mar 3, 2020
@thboop thboop removed their assignment Apr 14, 2020
@TingluoHuang TingluoHuang added runner Runner Bug Bug fix scope to the runner and removed bug Something isn't working runner labels Jun 6, 2020
@cprosser-clear
Copy link

Is this being worked on? This is causing a lot of problems for us.

anthonysessa added a commit to anthonysessa/runner that referenced this issue Oct 28, 2020
@ruvceskistefan ruvceskistefan self-assigned this Feb 28, 2022
@tomer-ds
Copy link

tomer-ds commented Nov 9, 2022

Hi all... any updates on this?
Tried the same test for LASTEXITCODE and same result of course

@bartekpacia
Copy link

This problem makes it easy to miss test failures on Windows! IMHO it should be prioritized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Runner Bug Bug fix scope to the runner
Projects
None yet
Development

No branches or pull requests

8 participants