diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 9e6ee91..8b9e1be 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -53,6 +53,7 @@ func TestRunEvent(t *testing.T) { {"local-action-dockerfile", "push", ""}, {"matrix", "push", ""}, {"commands", "push", ""}, + {"workdir", "push", ""}, } log.SetLevel(log.DebugLevel) diff --git a/pkg/runner/step_context.go b/pkg/runner/step_context.go index 379a14a..7c30c67 100644 --- a/pkg/runner/step_context.go +++ b/pkg/runner/step_context.go @@ -110,6 +110,13 @@ func (sc *StepContext) setupShellCommand() common.Executor { return err } + if step.WorkingDirectory != "" { + _, err = script.WriteString(fmt.Sprintf("cd %s\n", step.WorkingDirectory)) + if err != nil { + return err + } + } + run := rc.ExprEval.Interpolate(step.Run) if _, err = script.WriteString(run); err != nil { diff --git a/pkg/runner/testdata/workdir/canary b/pkg/runner/testdata/workdir/canary new file mode 100644 index 0000000..e69de29 diff --git a/pkg/runner/testdata/workdir/push.yml b/pkg/runner/testdata/workdir/push.yml new file mode 100644 index 0000000..16c7fe4 --- /dev/null +++ b/pkg/runner/testdata/workdir/push.yml @@ -0,0 +1,16 @@ +name: workdir +on: push + +jobs: + workdir: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: '[[ "$(pwd)" == "/github/workspace/workdir" ]]' + working-directory: workdir + + noworkdir: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: '[[ "$(pwd)" == "/github/workspace" ]]'