feat: add working-directory, defaults.run support
This commit is contained in:
parent
4ef95277e8
commit
673c20cc30
5 changed files with 18 additions and 15 deletions
|
@ -21,7 +21,9 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for
|
||||||
- [ ] jobs.<job_id>.concurrency
|
- [ ] jobs.<job_id>.concurrency
|
||||||
- [ ] jobs.<job_id>.outputs
|
- [ ] jobs.<job_id>.outputs
|
||||||
- [ ] jobs.<job_id>.env
|
- [ ] jobs.<job_id>.env
|
||||||
- [ ] jobs.<job_id>.defaults
|
- [x] jobs.<job_id>.defaults
|
||||||
|
- [ ] jobs.<job_id>.run.shell
|
||||||
|
- [x] jobs.<job_id>.run.working-directory
|
||||||
- [ ] jobs.<job_id>.timeout-minutes
|
- [ ] jobs.<job_id>.timeout-minutes
|
||||||
- [ ] jobs.<job_id>.strategy
|
- [ ] jobs.<job_id>.strategy
|
||||||
- [ ] jobs.<job_id>.container
|
- [ ] jobs.<job_id>.container
|
||||||
|
@ -37,7 +39,7 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for
|
||||||
- [ ] jobs.<job_id>.steps[*].name
|
- [ ] jobs.<job_id>.steps[*].name
|
||||||
- [ ] jobs.<job_id>.steps[*].uses
|
- [ ] jobs.<job_id>.steps[*].uses
|
||||||
- [x] jobs.<job_id>.steps[*].run
|
- [x] jobs.<job_id>.steps[*].run
|
||||||
- [ ] jobs.<job_id>.steps[*].working-directory
|
- [x] jobs.<job_id>.steps[*].working-directory
|
||||||
- [ ] jobs.<job_id>.steps[*].shell
|
- [ ] jobs.<job_id>.steps[*].shell
|
||||||
- [ ] jobs.<job_id>.steps[*].with
|
- [ ] jobs.<job_id>.steps[*].with
|
||||||
- [ ] jobs.<job_id>.steps[*].env
|
- [ ] jobs.<job_id>.steps[*].env
|
||||||
|
|
|
@ -8,7 +8,7 @@ type ContainerDriver interface {
|
||||||
Pull(string) error
|
Pull(string) error
|
||||||
Start(string, string) error
|
Start(string, string) error
|
||||||
Stop(string) error
|
Stop(string) error
|
||||||
Exec(string, string) CommandResult
|
Exec(containerId string, command string, cwd string) CommandResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents the outcome of a command call made by the driver.
|
// Represents the outcome of a command call made by the driver.
|
||||||
|
|
|
@ -79,8 +79,8 @@ func (d PodmanDriver) Stop(containerName string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d PodmanDriver) Exec(containerId string, command string) CommandResult {
|
func (d PodmanDriver) Exec(containerId string, command string, cwd string) CommandResult {
|
||||||
cmd := exec.Command("podman", "exec", containerId, "bash", "-c", command)
|
cmd := exec.Command("podman", "exec", "--workdir", cwd, containerId, "bash", "-c", command)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
||||||
jobContext := context.WithValue(workflowContext, "currentJob", job)
|
jobContext := context.WithValue(workflowContext, "currentJob", job)
|
||||||
jobContext = context.WithValue(jobContext, "runnerImageUri", runnerImage)
|
jobContext = context.WithValue(jobContext, "runnerImageUri", runnerImage)
|
||||||
|
|
||||||
// Runs a given job (provided a runner to run it on, its context, a task tracker for progress monitoring and
|
// Runs a given job (provided a runner to run it on, its context, a task tracker for progress monitoring and
|
||||||
// a WaitGroup to coordinate concurrent tasks) and updates the tracker with results.
|
// a WaitGroup to coordinate concurrent tasks) and updates the tracker with results.
|
||||||
runJob := func(runner *Runner, jobContext context.Context, jobTracker *TaskTracker, jobWaitGroup *sync.WaitGroup) {
|
runJob := func(runner *Runner, jobContext context.Context, jobTracker *TaskTracker, jobWaitGroup *sync.WaitGroup) {
|
||||||
defer jobWaitGroup.Done()
|
defer jobWaitGroup.Done()
|
||||||
jobTracker.SetStatus("started")
|
jobTracker.SetStatus("started")
|
||||||
|
@ -92,8 +92,8 @@ func (r *Runner) RunWorkflow(workflow workflow.Workflow) TaskTracker {
|
||||||
//
|
//
|
||||||
// If the command raises an error while in the container or fails to run
|
// If the command raises an error while in the container or fails to run
|
||||||
// the command at all, an error is returned, otherwise nil.
|
// the command at all, an error is returned, otherwise nil.
|
||||||
func (r *Runner) RunCommandInContainer(containerId string, command string) error {
|
func (r *Runner) RunCommandInContainer(containerId string, command string, stepCwd string) error {
|
||||||
result := r.Driver.Exec(containerId, command)
|
result := r.Driver.Exec(containerId, command, stepCwd)
|
||||||
|
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
|
@ -121,12 +121,13 @@ func (r *Runner) RunJobInContainer(imageUri string, containerId string, jobConte
|
||||||
|
|
||||||
logger.Info("Started %s", containerId)
|
logger.Info("Started %s", containerId)
|
||||||
for stepIndex, step := range job.Steps {
|
for stepIndex, step := range job.Steps {
|
||||||
|
stepCwd := jobContext.Value("workflow").(workflow.Workflow).GetWorkingDirectory(job.Name, stepIndex)
|
||||||
logger.Info("Run: %s", step.Run)
|
logger.Info("Run: %s", step.Run)
|
||||||
logger.Info("Using working directory %s", jobContext.Value("workflow").(workflow.Workflow).GetWorkingDirectory(job.Name, stepIndex))
|
logger.Info("Using working directory %s", stepCwd)
|
||||||
var stepError error
|
var stepError error
|
||||||
|
|
||||||
if step.Run != "" {
|
if step.Run != "" {
|
||||||
stepError = r.RunCommandInContainer(containerId, step.Run)
|
stepError = r.RunCommandInContainer(containerId, step.Run, stepCwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if stepError != nil {
|
if stepError != nil {
|
||||||
|
|
|
@ -59,11 +59,11 @@ func (d *MockDriver) Stop(uri string) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MockDriver) Exec(containerName string, command string) CommandResult {
|
func (d *MockDriver) Exec(containerName string, command string, cwd string) CommandResult {
|
||||||
if _, init := d.calls["Exec"]; !init {
|
if _, init := d.calls["Exec"]; !init {
|
||||||
d.calls["Exec"] = []MockCall{}
|
d.calls["Exec"] = []MockCall{}
|
||||||
}
|
}
|
||||||
d.calls["Exec"] = append(d.calls["Exec"], MockCall{fname: "Exec", args: []string{containerName, command}})
|
d.calls["Exec"] = append(d.calls["Exec"], MockCall{fname: "Exec", args: []string{containerName, command, cwd}})
|
||||||
|
|
||||||
if d.mockResult != nil {
|
if d.mockResult != nil {
|
||||||
return *d.mockResult
|
return *d.mockResult
|
||||||
|
@ -80,7 +80,7 @@ func TestRunnerRunCommandInContainerReturnsErrorFromDriver(t *testing.T) {
|
||||||
Driver: &mockDriver,
|
Driver: &mockDriver,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := runner.RunCommandInContainer("test-container", "test-command")
|
err := runner.RunCommandInContainer("test-container", "test-command", ".")
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected error, got nil.")
|
t.Errorf("Expected error, got nil.")
|
||||||
|
@ -95,7 +95,7 @@ func TestRunnerRunCommandInContainerReturnsErrorIfCommandExitCodeNonzero(t *test
|
||||||
Driver: &mockDriver,
|
Driver: &mockDriver,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := runner.RunCommandInContainer("test-container", "test-command")
|
err := runner.RunCommandInContainer("test-container", "test-command", ".")
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected error, got nil.")
|
t.Errorf("Expected error, got nil.")
|
||||||
|
|
Loading…
Reference in a new issue