diff --git a/daggerverse/gale/workflow_run.go b/daggerverse/gale/workflow_run.go index 8ca01af..2c05fa9 100644 --- a/daggerverse/gale/workflow_run.go +++ b/daggerverse/gale/workflow_run.go @@ -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 } @@ -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 diff --git a/ghx/context/paths.go b/ghx/context/paths.go index e59e45f..0cacbbd 100644 --- a/ghx/context/paths.go +++ b/ghx/context/paths.go @@ -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 @@ -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 @@ -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.