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" +