From b67017376471118ec3724f9f0b6868aad7a0f8c8 Mon Sep 17 00:00:00 2001 From: Aidan Steele Date: Sat, 14 Mar 2020 18:00:37 +1100 Subject: [PATCH] Add support for step.working-directory (closes #149) (#154) --- pkg/runner/runner_test.go | 1 + pkg/runner/step_context.go | 7 +++++++ pkg/runner/testdata/workdir/canary | 0 pkg/runner/testdata/workdir/push.yml | 16 ++++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 pkg/runner/testdata/workdir/canary create mode 100644 pkg/runner/testdata/workdir/push.yml 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" ]]'