fix: make workflow generation deterministic - #174
Merged
Merged
Conversation
Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Repeated runs of the same manifest produced workflows whose ordering varied run to run: job blocks,
needs: [...]entries, and the OR'dcontains(fromJSON(...), needs.X.result)checks inside finalizeif:expressions. Root cause is Go randomizing map range order per process.DependencyGraph.TopologicalSortseeded its walk by rangingg.Nodes(a map), so the emitted job order, the finalizeneeds:list, the summary table, the failure-check conditions, and the output aggregation all inherited a random seed. This is cosmetic (jobs run by theneeds:DAG,needsis a set,||is commutative) but it makes any committed-vs-regenerated drift gate flaky, including this repo's own Workflow Drift Check.Fix
Record manifest declaration order while building the graph and seed the topological sort from it instead of from a map range. Declaration order is the most intuitive read for a human (validate, then builds, then deploys, each in the order they appear in the manifest); the DAG still constrains the result wherever real dependencies exist, so only the free ordering is pinned. Two map-seeded lookups in the generator (the release-tag job lookup) and two validation loops (warning/error emission) were switched to the same declaration order so their output is stable as well. No semantics change: only ordering is stabilized. Sets that have no meaningful declaration order (matrix dimensions, dispatch inputs, secrets, finalize outputs) were already alphabetically sorted and are untouched.
Verification
go build ./...,go test ./...(1349 pass),go vet ./...,golangci-lint run ./...all green. e2e module builds and vets clean.needs:list and the failure-checkif:. Tokenizing each of those two lines and sorting shows the member sets are identical; only their order within the line changed. Every other line is byte-identical..github/manifest.yamlproduces no change (its manifest is a linear chain whose order was already stable), so the Workflow Drift Check stays green and the determinism test is the coverage for the multi-root case the dogfood manifest does not exercise.