From b072cfa1f7ee9959ad3423926850fadf44d98a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Mu=C3=B1oz?= Date: Thu, 17 Oct 2024 10:40:33 +0200 Subject: [PATCH] Add pwsh as the default shell for windows runners --- ql/lib/codeql/actions/ast/internal/Ast.qll | 10 ++++++-- .../library-tests/.github/workflows/shell.yml | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 ql/test/library-tests/.github/workflows/shell.yml diff --git a/ql/lib/codeql/actions/ast/internal/Ast.qll b/ql/lib/codeql/actions/ast/internal/Ast.qll index 7c433a39e62..67ef99e0fc8 100644 --- a/ql/lib/codeql/actions/ast/internal/Ast.qll +++ b/ql/lib/codeql/actions/ast/internal/Ast.qll @@ -1438,12 +1438,18 @@ class RunImpl extends StepImpl { /** Gets the shell for this `run` mapping. */ string getShell() { - if exists(n.lookup("shell").(YamlString).getValue()) + if exists(n.lookup("shell")) then result = n.lookup("shell").(YamlString).getValue() else if exists(this.getInScopeDefaultValue("run", "shell")) then result = this.getInScopeDefaultValue("run", "shell").getValue() - else result = "bash" + else + if this.getEnclosingJob().getARunsOnLabel().matches(["ubuntu%", "macos%"]) + then result = "bash" + else + if this.getEnclosingJob().getARunsOnLabel().matches("windows%") + then result = "pwsh" + else result = "bash" } ShellScriptImpl getScript() { result = scriptScalar } diff --git a/ql/test/library-tests/.github/workflows/shell.yml b/ql/test/library-tests/.github/workflows/shell.yml new file mode 100644 index 00000000000..9392b81c6ab --- /dev/null +++ b/ql/test/library-tests/.github/workflows/shell.yml @@ -0,0 +1,23 @@ +on: push + +jobs: + job1: + runs-on: ubuntu-latest + steps: + - shell: pwsh + run: Write-Output "foo" + job2: + runs-on: ubuntu-latest + steps: + - run: echo "foo" + + job3: + runs-on: windows-latest + steps: + - shell: bash + run: echo "foo" + job4: + runs-on: windows-latest + steps: + - run: Write-Output "foo" +