Support setting shell via defaults.run (#343)

Note that we don't support the more general use of defaults, just its
run key for setting shell and working directory.

The documentation for defaults.run is here:
  https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#defaultsrun

Fixes #214.

Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Julian Squires
2020-08-28 16:22:25 -02:30
committed by GitHub
parent b3b8961122
commit e698e8b324
4 changed files with 60 additions and 4 deletions

View File

@@ -111,6 +111,12 @@ func (sc *StepContext) setupShellCommand() common.Executor {
return err
}
if step.WorkingDirectory == "" {
step.WorkingDirectory = rc.Run.Job().Defaults.Run.WorkingDirectory
}
if step.WorkingDirectory == "" {
step.WorkingDirectory = rc.Run.Workflow.Defaults.Run.WorkingDirectory
}
if step.WorkingDirectory != "" {
_, err = script.WriteString(fmt.Sprintf("cd %s\n", step.WorkingDirectory))
if err != nil {
@@ -126,6 +132,13 @@ func (sc *StepContext) setupShellCommand() common.Executor {
scriptName := fmt.Sprintf("workflow/%s", step.ID)
log.Debugf("Wrote command '%s' to '%s'", run, scriptName)
containerPath := fmt.Sprintf("/github/%s", scriptName)
if step.Shell == "" {
step.Shell = rc.Run.Job().Defaults.Run.Shell
}
if step.Shell == "" {
step.Shell = rc.Run.Workflow.Defaults.Run.Shell
}
sc.Cmd = strings.Fields(strings.Replace(step.ShellCommand(), "{0}", containerPath, 1))
return rc.JobContainer.Copy("/github/", &container.FileEntry{
Name: scriptName,