Make sure working directory is respected when configured from matrix (#1686)
* Make sure working directory is respected when configured from matrix * Fix regression by setting Workingdirectory on stepRun instead of step or too early
This commit is contained in:
parent
351ae99bc1
commit
75ffa205c4
2 changed files with 24 additions and 10 deletions
|
@ -17,6 +17,7 @@ type stepRun struct {
|
||||||
RunContext *RunContext
|
RunContext *RunContext
|
||||||
cmd []string
|
cmd []string
|
||||||
env map[string]string
|
env map[string]string
|
||||||
|
WorkingDirectory string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sr *stepRun) pre() common.Executor {
|
func (sr *stepRun) pre() common.Executor {
|
||||||
|
@ -27,12 +28,11 @@ func (sr *stepRun) pre() common.Executor {
|
||||||
|
|
||||||
func (sr *stepRun) main() common.Executor {
|
func (sr *stepRun) main() common.Executor {
|
||||||
sr.env = map[string]string{}
|
sr.env = map[string]string{}
|
||||||
|
|
||||||
return runStepExecutor(sr, stepStageMain, common.NewPipelineExecutor(
|
return runStepExecutor(sr, stepStageMain, common.NewPipelineExecutor(
|
||||||
sr.setupShellCommandExecutor(),
|
sr.setupShellCommandExecutor(),
|
||||||
func(ctx context.Context) error {
|
func(ctx context.Context) error {
|
||||||
sr.getRunContext().ApplyExtraPath(ctx, &sr.env)
|
sr.getRunContext().ApplyExtraPath(ctx, &sr.env)
|
||||||
return sr.getRunContext().JobContainer.Exec(sr.cmd, sr.env, "", sr.Step.WorkingDirectory)(ctx)
|
return sr.getRunContext().JobContainer.Exec(sr.cmd, sr.env, "", sr.WorkingDirectory)(ctx)
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -167,16 +167,20 @@ func (sr *stepRun) setupShell(ctx context.Context) {
|
||||||
func (sr *stepRun) setupWorkingDirectory(ctx context.Context) {
|
func (sr *stepRun) setupWorkingDirectory(ctx context.Context) {
|
||||||
rc := sr.RunContext
|
rc := sr.RunContext
|
||||||
step := sr.Step
|
step := sr.Step
|
||||||
|
workingdirectory := ""
|
||||||
|
|
||||||
if step.WorkingDirectory == "" {
|
if step.WorkingDirectory == "" {
|
||||||
step.WorkingDirectory = rc.Run.Job().Defaults.Run.WorkingDirectory
|
workingdirectory = rc.Run.Job().Defaults.Run.WorkingDirectory
|
||||||
|
} else {
|
||||||
|
workingdirectory = step.WorkingDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
// jobs can receive context values, so we interpolate
|
// jobs can receive context values, so we interpolate
|
||||||
step.WorkingDirectory = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, step.WorkingDirectory)
|
workingdirectory = rc.NewExpressionEvaluator(ctx).Interpolate(ctx, workingdirectory)
|
||||||
|
|
||||||
// but top level keys in workflow file like `defaults` or `env` can't
|
// but top level keys in workflow file like `defaults` or `env` can't
|
||||||
if step.WorkingDirectory == "" {
|
if workingdirectory == "" {
|
||||||
step.WorkingDirectory = rc.Run.Workflow.Defaults.Run.WorkingDirectory
|
workingdirectory = rc.Run.Workflow.Defaults.Run.WorkingDirectory
|
||||||
}
|
}
|
||||||
|
sr.WorkingDirectory = workingdirectory
|
||||||
}
|
}
|
||||||
|
|
10
pkg/runner/testdata/workdir/push.yml
vendored
10
pkg/runner/testdata/workdir/push.yml
vendored
|
@ -22,3 +22,13 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: '[[ "$(pwd)" == "/tmp" ]]'
|
- run: '[[ "$(pwd)" == "/tmp" ]]'
|
||||||
|
|
||||||
|
workdir-from-matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
max-parallel: 1
|
||||||
|
matrix:
|
||||||
|
work_dir: ["/tmp", "/root"]
|
||||||
|
steps:
|
||||||
|
- run: '[[ "$(pwd)" == "${{ matrix.work_dir }}" ]]'
|
||||||
|
working-directory: ${{ matrix.work_dir }}
|
||||||
|
|
Loading…
Reference in a new issue