Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use predictable names as dir names #152

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions daggerverse/gale/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@ func (wr *WorkflowRun) Result(ctx context.Context) (string, error) {

var result WorkflowRunReport

runs := container.Directory("/home/runner/_temp/ghx/runs")

// runs directory should only have one entry with the workflow run id
entries, err := runs.Entries(ctx)
if err != nil {
return "", err
}

wrID := entries[0]

resultJSON := filepath.Join("/home/runner/_temp/ghx/runs", wrID, "workflow_run.json")

err = container.File(resultJSON).unmarshalContentsToJSON(ctx, &result)
err = container.File("/home/runner/_temp/ghx/run/workflow_run.json").unmarshalContentsToJSON(ctx, &result)
if err != nil {
return "", err
}
Expand All @@ -48,36 +36,33 @@ func (wr *WorkflowRun) Directory(ctx context.Context, opts WorkflowRunDirectoryO
return nil, err
}

runs := container.Directory("/home/runner/_temp/ghx/runs")

// runs directory should only have one entry with the workflow run id
entries, err := runs.Entries(ctx)
if err != nil {
return nil, err
}

wrID := entries[0]

dir := dag.Directory().WithDirectory("runs", runs)
dir := dag.Directory().WithDirectory("run", container.Directory("/home/runner/_temp/ghx/run"))

if opts.IncludeRepo {
dir = dir.WithDirectory(fmt.Sprintf("runs/%s/repo", wrID), container.Directory("."))
dir = dir.WithDirectory("repo", container.Directory("."))
}

if opts.IncludeSecrets {
dir = dir.WithDirectory(fmt.Sprintf("runs/%s/secrets", wrID), container.Directory("/home/runner/_temp/ghx/secrets"))
dir = dir.WithDirectory("secrets", container.Directory("/home/runner/_temp/ghx/secrets"))
}

if opts.IncludeEvent && wr.Config.EventFile != nil {
dir = dir.WithFile(fmt.Sprintf("runs/%s/event.json", wrID), container.File(filepath.Join("/home", "runner", "work", "_temp", "_github_workflow", "event.json")))
dir = dir.WithFile("event.json", container.File("/home/runner/_temp/_github_workflow/event.json"))
}

if opts.IncludeArtifacts {
var report WorkflowRunReport

err := dir.File("run/workflow_run.json").unmarshalContentsToJSON(ctx, &report)
if err != nil {
return nil, err
}

container = dag.Container().From("alpine:latest").
WithMountedCache("/artifacts", dag.Source().ArtifactService().CacheVolume()).
WithExec([]string{"cp", "-r", fmt.Sprintf("/artifacts/%s", wrID), "/exported_artifacts"})
WithExec([]string{"cp", "-r", fmt.Sprintf("/artifacts/%s", report.RunID), "/exported_artifacts"})

dir = dir.WithDirectory(fmt.Sprintf("runs/%s/artifacts", wrID), container.Directory("/exported_artifacts"))
dir = dir.WithDirectory("artifacts", container.Directory("/exported_artifacts"))
}

return dir, nil
Expand Down
6 changes: 3 additions & 3 deletions ghx/context/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *Context) GetWorkflowRunPath() (string, error) {
return "", errors.New("no workflow run is set")
}

return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID)
return EnsureDir(c.GhxConfig.HomeDir, "run")
}

// GetJobRunPath returns the path of the current job run path. If the path does not exist, it creates it. If the job run
Expand All @@ -60,7 +60,7 @@ func (c *Context) GetJobRunPath() (string, error) {
return "", errors.New("no job is set")
}

return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID, "jobs", c.Execution.JobRun.RunID)
return EnsureDir(c.GhxConfig.HomeDir, "run", "jobs", c.Execution.JobRun.Job.ID)
}

// GetStepRunPath returns the path of the current step run path. If the path does not exist, it creates it. If the step
Expand All @@ -70,7 +70,7 @@ func (c *Context) GetStepRunPath() (string, error) {
return "", errors.New("no step is set")
}

return EnsureDir(c.GhxConfig.HomeDir, "runs", c.Execution.WorkflowRun.RunID, "jobs", c.Execution.JobRun.RunID, "steps", c.Execution.StepRun.Step.ID)
return EnsureDir(c.GhxConfig.HomeDir, "run", "jobs", c.Execution.JobRun.Job.ID, "steps", c.Execution.StepRun.Step.ID)
}

// EnsureDir return the joined path and ensures that the directory exists. and returns the joined path.
Expand Down
Loading