Skip to content

Commit

Permalink
fix: iterate over sorted build.steps
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Nov 15, 2023
1 parent 7191518 commit 808914c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions api/build/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package build
import (
"fmt"
"net/http"
"sort"
"strings"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -380,10 +381,8 @@ func GetBuildGraph(c *gin.Context) {
}

// retrieve the stage to update
s := stageMap[name]

// this shouldnt happen
if s == nil {
s, ok := stageMap[name]
if !ok {
continue
}

Expand Down Expand Up @@ -450,6 +449,7 @@ func GetBuildGraph(c *gin.Context) {
// construct pipeline stages nodes when stages exist
for _, stage := range p.Stages {
// skip steps/stages that were not present in the build
// this fixes the scenario where mutable templates are updated
s, ok := stageMap[stage.Name]
if !ok {
continue
Expand Down Expand Up @@ -481,13 +481,15 @@ func GetBuildGraph(c *gin.Context) {

// create single-step stages when no stages exist
if len(p.Stages) == 0 {
for _, step := range p.Steps {
// scrub the environment
step.Environment = nil
// sort them by number
sort.Slice(steps, func(i, j int) bool {
return steps[i].GetNumber() < steps[j].GetNumber()
})

for _, step := range steps {
// mock stage for edge creation
stage := &pipeline.Stage{
Name: step.Name,
Name: step.GetName(),
Needs: []string{},
}

Expand Down

0 comments on commit 808914c

Please sign in to comment.