fix: set sh
as default shell for containers (#853)
* fix: set default shell for containers to sh This matches GitHub Actions behaviour where, runners use bash since it's guaranteed to exist there while containers use sh for compatibility * tests: fixup for default shell
This commit is contained in:
parent
7c73531008
commit
e9ae7894e3
8 changed files with 76 additions and 3 deletions
|
@ -97,6 +97,7 @@ func TestRunEvent(t *testing.T) {
|
||||||
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, ""},
|
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, ""},
|
||||||
{"testdata", "runs-on", "push", "", platforms, ""},
|
{"testdata", "runs-on", "push", "", platforms, ""},
|
||||||
{"testdata", "checkout", "push", "", platforms, ""},
|
{"testdata", "checkout", "push", "", platforms, ""},
|
||||||
|
{"testdata", "shells/defaults", "push", "", platforms, ""},
|
||||||
{"testdata", "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "ghcr.io/justingrote/act-pwsh:latest"}, ""}, // custom image with pwsh
|
{"testdata", "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "ghcr.io/justingrote/act-pwsh:latest"}, ""}, // custom image with pwsh
|
||||||
{"testdata", "shells/bash", "push", "", platforms, ""},
|
{"testdata", "shells/bash", "push", "", platforms, ""},
|
||||||
{"testdata", "shells/python", "push", "", map[string]string{"ubuntu-latest": "node:12-buster"}, ""}, // slim doesn't have python
|
{"testdata", "shells/python", "push", "", map[string]string{"ubuntu-latest": "node:12-buster"}, ""}, // slim doesn't have python
|
||||||
|
|
|
@ -183,6 +183,7 @@ func (sc *StepContext) setupEnv(ctx context.Context) (ExpressionEvaluator, error
|
||||||
return evaluator, nil
|
return evaluator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:gocyclo
|
||||||
func (sc *StepContext) setupShellCommand() common.Executor {
|
func (sc *StepContext) setupShellCommand() common.Executor {
|
||||||
rc := sc.RunContext
|
rc := sc.RunContext
|
||||||
step := sc.Step
|
step := sc.Step
|
||||||
|
@ -237,6 +238,11 @@ func (sc *StepContext) setupShellCommand() common.Executor {
|
||||||
if step.Shell == "" {
|
if step.Shell == "" {
|
||||||
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
|
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
|
||||||
}
|
}
|
||||||
|
if rc.Run.Job().Container() != nil {
|
||||||
|
if rc.Run.Job().Container().Image != "" && step.Shell == "" {
|
||||||
|
step.Shell = "sh"
|
||||||
|
}
|
||||||
|
}
|
||||||
scCmd := step.ShellCommand()
|
scCmd := step.ShellCommand()
|
||||||
|
|
||||||
var finalCMD []string
|
var finalCMD []string
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
name: container-hostname
|
name: container-hostname
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
with-hostname:
|
with-hostname:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
17
pkg/runner/testdata/shells/bash/push.yml
vendored
17
pkg/runner/testdata/shells/bash/push.yml
vendored
|
@ -5,6 +5,19 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- shell: bash
|
- shell: bash
|
||||||
run: |
|
run: |
|
||||||
if [[ -n "$PATH" ]] ; then
|
if [[ -n "$BASH" ]]; then
|
||||||
echo "I'm Bash!"
|
echo "I'm $BASH!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
check-container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: node:12-buster-slim
|
||||||
|
steps:
|
||||||
|
- shell: bash
|
||||||
|
run: |
|
||||||
|
if [[ -n "$BASH" ]]; then
|
||||||
|
echo "I'm $BASH!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
21
pkg/runner/testdata/shells/defaults/push.yml
vendored
Normal file
21
pkg/runner/testdata/shells/defaults/push.yml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
check: # GHA uses `bash` as default for runners
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
if [[ -n "$BASH" ]]; then
|
||||||
|
echo "I'm $BASH!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
check-container: # GHA uses `sh` as default for containers
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: alpine:latest
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
if [ -z ${BASH+x} ]; then
|
||||||
|
echo "I'm sh!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
7
pkg/runner/testdata/shells/pwsh/push.yml
vendored
7
pkg/runner/testdata/shells/pwsh/push.yml
vendored
|
@ -6,3 +6,10 @@ jobs:
|
||||||
- shell: pwsh
|
- shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$PSVersionTable
|
$PSVersionTable
|
||||||
|
check-container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ghcr.io/justingrote/act-pwsh:latest
|
||||||
|
steps:
|
||||||
|
- shell: pwsh
|
||||||
|
run: |
|
||||||
|
$PSVersionTable
|
||||||
|
|
8
pkg/runner/testdata/shells/python/push.yml
vendored
8
pkg/runner/testdata/shells/python/push.yml
vendored
|
@ -7,3 +7,11 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
import platform
|
import platform
|
||||||
print(platform.python_version())
|
print(platform.python_version())
|
||||||
|
check-container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: node:12-buster
|
||||||
|
steps:
|
||||||
|
- shell: python
|
||||||
|
run: |
|
||||||
|
import platform
|
||||||
|
print(platform.python_version())
|
||||||
|
|
15
pkg/runner/testdata/shells/sh/push.yml
vendored
15
pkg/runner/testdata/shells/sh/push.yml
vendored
|
@ -5,6 +5,19 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- shell: sh
|
- shell: sh
|
||||||
run: |
|
run: |
|
||||||
if [ -n "$PATH" ] ; then
|
if [ -z ${BASH+x} ]; then
|
||||||
echo "I'm sh!"
|
echo "I'm sh!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
check-container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: alpine:latest
|
||||||
|
steps:
|
||||||
|
- shell: sh
|
||||||
|
run: |
|
||||||
|
if [ -z ${BASH+x} ]; then
|
||||||
|
echo "I'm sh!"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue