Title: perf(ci): version refactor (remove Xref/status.sh) by davdhacs · Pull Request #19424 · stackrox/stackrox · GitHub
Open Graph Title: perf(ci): version refactor (remove Xref/status.sh) by davdhacs · Pull Request #19424 · stackrox/stackrox
X Title: perf(ci): version refactor (remove Xref/status.sh) by davdhacs · Pull Request #19424 · stackrox/stackrox
Description: Problem: -X ldflags break Go's build and test cache Go's build cache keys every action (compile, link, test) on an ActionID — a hash of all inputs that affect the output. The link ActionID includes the full -ldflags string (exec.go:linkActionID() — see fmt.Fprintf(h, "link\n") ... fmt.Fprintf(h, "ldflags %q\n", ldflags)). The old status.sh + //XDef: mechanism injected version data via -X ldflags: -X "github.com/stackrox/rox/pkg/version/internal.MainVersion=4.11.x-431-gbbcc7d3be2" -X "github.com/stackrox/rox/pkg/version/internal.GitShortSha=bbcc7d3be24" Since MainVersion and GitShortSha change on every commit, the ldflags string changes, which changes the link ActionID. This has two effects: Build cache miss at link step: every binary re-links on every commit, even if no source code changed. Go's compile cache uses dependency contentID (output hash) rather than actionID, so compile steps can still cache-hit. But the link step always re-runs because its ActionID includes the changed ldflags. On CI, this means ~100s spent re-linking binaries that haven't actually changed. Test cache miss at Phase 1: Go's test result cache computes a test binary identity from the test binary's build ActionID, which includes the link ActionID (test.go:builderTest() — the test binary hash flows through packageActionID() → linkActionID()). When the link ActionID changes, the test binary identity changes, and Go discards all cached test results — every test re-runs from scratch. Fix: generated zversion.go instead of -X ldflags Replace -X ldflags with a generated pkg/version/internal/zversion.go file that sets version data via init(). This eliminates -X from the link step entirely, making ldflags stable across commits (-s -w only). For tests, go-tool.sh writes only the base tag (e.g. "4.11.x") — stable across commits on the same release branch. For builds, it writes the full git describe output (e.g. "4.11.x-431-gbbcc7d3be2"). The generated zversion.go is a source file, so it flows through the compile ActionID (content-hashed). When its content doesn't change (test mode), the compile output is byte-identical, giving the same contentID, so all 4400+ downstream packages get cache hits at both compile and link. Only 2 packages recompile (the version packages themselves, whose output is byte-identical anyway). Result: build compilation step drops from 100s → 27s (3.7x), and this improvement works independently of the test cache fix. Companion PRs PR #19395: Phase 2 fix (stabilize file mtimes for test input validation). PR #19585: disable -buildvcs (split out from this PR). Test caching requires both Phase 1 (this PR) and Phase 2 (#19395). The build cache improvement from this PR works on its own. Prior art: PR #15609 PR #15609 was closed due to two blockers (comment). Both are now resolved: -coverprofile broke test caching (Go <1.25): fixed in Go 1.25 (golang/go#23565). We are on Go 1.25.5. release vs non-release GOTAGS sharing one cache: our research (PR #19576) showed they share 93% of entries — only 6/1952 packages have release build tags. Go correctly recompiles those when GOTAGS changes. Separating caches would duplicate 93% of entries. Measured results (both PRs combined) Job Master warm Combined warm Speedup go (GOTAGS="") 35m ~8m 4.5x go-postgres 31m ~36s 52x sensor-integration 26m ~2.5m 11x Build compilation step (this PR alone): 100s → 27s (3.7x), with 99.95% cache hit rate (2/4403 packages recompile). Testing and quality CI results are inspected Automated testing added unit tests added e2e tests added regression tests added compatibility tests modified existing tests How I validated my change Verified locally: go-build.sh generates full version, go-test.sh generates stable base tag Build produces correct version strings in binaries Prior CI runs confirmed 4.5-52x test speedup and 3.7x build speedup when combined with mtime fix Operator builds pass CI with the new BUILD_TAG mechanism
Open Graph Description: Problem: -X ldflags break Go's build and test cache Go's build cache keys every action (compile, link, test) on an ActionID — a hash of all inputs that affect the output. The link ActionID ...
X Description: Problem: -X ldflags break Go's build and test cache Go's build cache keys every action (compile, link, test) on an ActionID — a hash of all inputs that affect the output. The link A...
Opengraph URL: https://github.com/stackrox/stackrox/pull/19424
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1c9e485b-eb38-095a-81d3-7b07d088f1e1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AE3E:3073D:13734E0:1BD7566:6A4CC211 |
| html-safe-nonce | 8f433a2c0dcce2ca9e65a7b8f949d9f36811f7c5cf05021dbe71ccccf232ff43 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTNFOjMwNzNEOjEzNzM0RTA6MUJENzU2Njo2QTRDQzIxMSIsInZpc2l0b3JfaWQiOiI0MjQ0NTMxODAxNzY5MTY1MzI5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5b95a171078a2f269d29e0159f6789942342f5291fa974236565831532a8ad96 |
| hovercard-subject-tag | pull_request:3396802721 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/stackrox/stackrox/pull/19424/files |
| twitter:image | https://avatars.githubusercontent.com/u/105243888?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/105243888?s=400&v=4 |
| og:image:alt | Problem: -X ldflags break Go's build and test cache Go's build cache keys every action (compile, link, test) on an ActionID — a hash of all inputs that affect the output. The link ActionID ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/stackrox/stackrox git https://github.com/stackrox/stackrox.git |
| octolytics-dimension-user_id | 40638982 |
| octolytics-dimension-user_login | stackrox |
| octolytics-dimension-repository_id | 434017296 |
| octolytics-dimension-repository_nwo | stackrox/stackrox |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 434017296 |
| octolytics-dimension-repository_network_root_nwo | stackrox/stackrox |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c03e7e569190bc89b638cdd4acb4b6c6b38a170a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width