Skip to content

Commit 73bc825

Browse files
leodidoona-agent
andcommitted
fix: move test coverage collection before packaging phase
Test coverage collection needs access to _deps/ directory to run `go tool cover -func`, which internally calls `go list` for module dependency resolution. Previously (commit cdb2518), test coverage was moved after packaging to maintain ordering with provenance handling. However, the packaging phase removes _deps/ for deterministic builds, causing test coverage to fail with "cannot load module _deps/api-go--lib". This fix moves test coverage back to before packaging, restoring the v0.13.2 behavior. This satisfies all requirements: - Test coverage has access to _deps/ for go list - SBOM generation has access to _deps/ for scanning - Packaging removes _deps/ for deterministic tar.gz - Provenance computes subjects from final artifact (no _deps/) The build order is now: 1. SBOM generation (needs _deps/) 2. Test coverage collection (needs _deps/) 3. Package phase (removes _deps/) 4. Provenance handling (accurate subjects without _deps/) Related commits: - cdb2518: "fix: move provenance handling after packaging phase" - b5584c5: "Fix go coverage collection by removing deps in packaging" Co-authored-by: Ona <[email protected]>
1 parent 27734d1 commit 73bc825

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pkg/leeway/build.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,18 @@ func (p *Package) build(buildctx *buildContext) (err error) {
10581058
}
10591059
}
10601060

1061+
// Handle test coverage if available (before packaging - needs _deps)
1062+
if bld.TestCoverage != nil {
1063+
coverage, funcsWithoutTest, funcsWithTest, err := bld.TestCoverage()
1064+
if err != nil {
1065+
return err
1066+
}
1067+
pkgRep.TestCoverageAvailable = true
1068+
pkgRep.TestCoveragePercentage = coverage
1069+
pkgRep.FunctionsWithoutTest = funcsWithoutTest
1070+
pkgRep.FunctionsWithTest = funcsWithTest
1071+
}
1072+
10611073
// Package the build results
10621074
if len(bld.Commands[PackageBuildPhasePackage]) > 0 {
10631075
if err := executeCommandsForPackage(buildctx, p, builddir, bld.Commands[PackageBuildPhasePackage]); err != nil {
@@ -1080,18 +1092,6 @@ func (p *Package) build(buildctx *buildContext) (err error) {
10801092
}
10811093
}
10821094

1083-
// Handle test coverage if available
1084-
if bld.TestCoverage != nil {
1085-
coverage, funcsWithoutTest, funcsWithTest, err := bld.TestCoverage()
1086-
if err != nil {
1087-
return err
1088-
}
1089-
pkgRep.TestCoverageAvailable = true
1090-
pkgRep.TestCoveragePercentage = coverage
1091-
pkgRep.FunctionsWithoutTest = funcsWithoutTest
1092-
pkgRep.FunctionsWithTest = funcsWithTest
1093-
}
1094-
10951095
// Register newly built package
10961096
return buildctx.RegisterNewlyBuilt(p)
10971097
}

0 commit comments

Comments
 (0)