mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix!: fallback to sh if bash does not exist
It is a breaking change because it changes how the shell is determined. Before, if `jobs.<job_id>.container.image` is set and the shell is not specified, it defaults to `sh` instead of `bash`. After, regardless of `jobs.<job_id>.container.image`, if the shell is not specified, it defaults to `bash` if available, otherwise it defaults to `sh`. Rework the shell integration tests: - Remove container specific tests because the special behavior related to shell being set differently when a container image is present is removed - Modify the defaults test case to verify the fallback logic - Use container images from code.forgejo.org to escape rate limiting in the CI - Add the missing node test - Use container: image: code.forgejo.org/oci/node:22-bookworm instead of container: code.forgejo.org/oci/node:22-bookworm because it silently failed to run (with no exit code) - Prefer `-z "${BASH}"` because `-z ${BASH+x}` reads obscure Closes forgejo/runner#150
This commit is contained in:
parent
6e59f129c1
commit
c1892b6398
10 changed files with 76 additions and 56 deletions
|
@ -194,9 +194,20 @@ func (sr *stepRun) setupShell(ctx context.Context) {
|
|||
if err != nil {
|
||||
step.Shell = shellWithFallback[1]
|
||||
}
|
||||
} else if containerImage := rc.containerImage(ctx); containerImage != "" {
|
||||
// Currently only linux containers are supported, use sh by default like actions/runner
|
||||
step.Shell = "sh"
|
||||
} else {
|
||||
shell_fallback := `
|
||||
if command -v bash >/dev/null; then
|
||||
echo -n bash
|
||||
else
|
||||
echo -n sh
|
||||
fi
|
||||
`
|
||||
stdout, _, err := rc.sh(ctx, shell_fallback)
|
||||
if err != nil {
|
||||
common.Logger(ctx).Error("fail to run %q: %v", shell_fallback, err)
|
||||
return
|
||||
}
|
||||
step.Shell = stdout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue