Skip to content

Commit

Permalink
refactor: prefix step index to step id to keep execution order steps …
Browse files Browse the repository at this point in the history
…with custom step ids
  • Loading branch information
aweris committed Dec 10, 2023
1 parent 5fc1e4d commit 2803aec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/model/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ghx/src/context/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion ghx/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2803aec

Please sign in to comment.