Skip to content

Commit

Permalink
make backend step dag generation deterministic (#3037)
Browse files Browse the repository at this point in the history
the the generation for backend steps if a dag is used deterministic.

this also fix where the test randomly fail like in:
- https://ci.woodpecker-ci.org/repos/3780/pipeline/11057/30
- https://ci.woodpecker-ci.org/repos/3780/pipeline/11076/25
  • Loading branch information
6543 authored Dec 27, 2023
1 parent 05f26ba commit 840fca1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 13 additions & 1 deletion pipeline/frontend/yaml/compiler/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package compiler

import (
"fmt"
"sort"

backend_types "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
)
Expand Down Expand Up @@ -130,14 +131,25 @@ func convertDAGToStages(steps map[string]*dagCompilerStep, prefix string) ([]*ba
Alias: fmt.Sprintf("%s_stage_%d", prefix, len(stages)),
}

var stepsToAdd []*dagCompilerStep
for name, step := range steps {
if allDependenciesSatisfied(step, addedSteps) {
stage.Steps = append(stage.Steps, step.step)
stepsToAdd = append(stepsToAdd, step)
addedNodesThisLevel[name] = struct{}{}
delete(steps, name)
}
}

// as steps are from a map that has no deterministic order,
// we sort the steps by original config position to make the order similar between pipelines
sort.Slice(stepsToAdd, func(i, j int) bool {
return stepsToAdd[i].position < stepsToAdd[j].position
})

for i := range stepsToAdd {
stage.Steps = append(stage.Steps, stepsToAdd[i].step)
}

for name := range addedNodesThisLevel {
addedSteps[name] = struct{}{}
}
Expand Down
6 changes: 1 addition & 5 deletions web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@ declare module 'vue' {
GeneralTab: typeof import('./src/components/repo/settings/GeneralTab.vue')['default']
Header: typeof import('./src/components/layout/scaffold/Header.vue')['default']
IBiCheckCircleFill: typeof import('~icons/bi/check-circle-fill')['default']
IBiCircle: typeof import('~icons/bi/circle')['default']
IBiExclamationTriangle: typeof import('~icons/bi/exclamation-triangle')['default']
IBiExclamationTriangleFill: typeof import('~icons/bi/exclamation-triangle-fill')['default']
IBiPlayCircleFill: typeof import('~icons/bi/play-circle-fill')['default']
IBiSlashCircleFill: typeof import('~icons/bi/slash-circle-fill')['default']
IBiStopCircleFill: typeof import('~icons/bi/stop-circle-fill')['default']
IBiXCircleFill: typeof import('~icons/bi/x-circle-fill')['default']
IBxBxPowerOff: typeof import('~icons/bx/bx-power-off')['default']
ICarbonCloseOutline: typeof import('~icons/carbon/close-outline')['default']
ICarbonInProgress: typeof import('~icons/carbon/in-progress')['default']
IClarityDeployLine: typeof import('~icons/clarity/deploy-line')['default']
IClaritySettingsSolid: typeof import('~icons/clarity/settings-solid')['default']
Icon: typeof import('./src/components/atomic/Icon.vue')['default']
Expand Down Expand Up @@ -73,6 +68,7 @@ declare module 'vue' {
IMdiRadioboxIndeterminateVariant: typeof import('~icons/mdi/radiobox-indeterminate-variant')['default']
IMdiSourceBranch: typeof import('~icons/mdi/source-branch')['default']
IMdisourceCommit: typeof import('~icons/mdi/source-commit')['default']
IMdiSourceMerge: typeof import('~icons/mdi/source-merge')['default']
IMdiSourcePull: typeof import('~icons/mdi/source-pull')['default']
IMdiStop: typeof import('~icons/mdi/stop')['default']
IMdiSync: typeof import('~icons/mdi/sync')['default']
Expand Down

0 comments on commit 840fca1

Please sign in to comment.