From 2803aec68bcb9cea97f0e9a1cd1fb91546d6d7bf Mon Sep 17 00:00:00 2001 From: Ali AKCA Date: Sun, 10 Dec 2023 23:06:04 +0100 Subject: [PATCH] refactor: prefix step index to step id to keep execution order steps with custom step ids --- common/model/step.go | 1 + ghx/src/context/paths.go | 2 +- ghx/src/main.go | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/model/step.go b/common/model/step.go index 925594b..87cad6c 100644 --- a/common/model/step.go +++ b/common/model/step.go @@ -6,6 +6,7 @@ import "strings" // // See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsteps type Step struct { + Index string `yaml:"-"` // Index is the index of the step in the job context. ID string `yaml:"id,omitempty"` // ID is the unique identifier of the step. If string `yaml:"if,omitempty"` // If is the conditional expression to run the step. Name string `yaml:"name,omitempty"` // Name is the name of the step. diff --git a/ghx/src/context/paths.go b/ghx/src/context/paths.go index 607dea1..ee32968 100644 --- a/ghx/src/context/paths.go +++ b/ghx/src/context/paths.go @@ -66,7 +66,7 @@ func (c *Context) GetStepRunPath() (string, error) { return "", errors.New("no step is set") } - return EnsureDir(c.GhxConfig.HomeDir, "run", "jobs", c.Execution.JobRun.Job.ID, "steps", c.Execution.StepRun.Step.ID) + return EnsureDir(c.GhxConfig.HomeDir, "run", "jobs", c.Execution.JobRun.Job.ID, "steps", c.Execution.StepRun.Step.Index+"."+c.Execution.StepRun.Step.ID) } // EnsureDir return the joined path and ensures that the directory exists. and returns the joined path. diff --git a/ghx/src/main.go b/ghx/src/main.go index 8265c7f..f616666 100644 --- a/ghx/src/main.go +++ b/ghx/src/main.go @@ -91,8 +91,10 @@ func LoadWorkflow(cfg context.GhxConfig, path string) (model.Workflow, error) { // update step IDs if not provided for ids, step := range job.Steps { + step.Index = fmt.Sprintf("%d", ids) + if step.ID == "" { - step.ID = fmt.Sprintf("%d", ids) + step.ID = step.Index } job.Steps[ids] = step