Skip to content

Commit 5128bc1

Browse files
committed
feat: generate coverage for the integration tests
Use all canonical module paths to generate `coverpkg`. Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
1 parent 5c988d4 commit 5128bc1

5 files changed

Lines changed: 38 additions & 6 deletions

File tree

internal/project/auto/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ type CustomSteps struct {
2828

2929
// CustomStep defines a custom step to be built.
3030
type CustomStep struct {
31-
Name string `yaml:"name"`
32-
Inputs []string `yaml:"inputs"`
33-
Toplevel bool `yaml:"toplevel"`
31+
Name string `yaml:"name"`
32+
Inputs []string `yaml:"inputs"`
33+
Dependants []string `yaml:"dependants"`
34+
Toplevel bool `yaml:"toplevel"`
3435
}
3536

3637
// CI defines CI settings.

internal/project/auto/custom.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ func (builder *builder) BuildCustom() error {
4949
step.AddInput(input)
5050
}
5151

52+
for _, dependantName := range spec.Dependants {
53+
dependant := dag.FindByName(dependantName, append(builder.targets, createdSteps...)...)
54+
55+
if dependant == nil {
56+
return fmt.Errorf("failed to find dependant node %q for custom step %q", dependantName, spec.Name)
57+
}
58+
59+
dependant.AddInput(step)
60+
}
61+
5262
createdSteps = append(createdSteps, step)
5363
}
5464

internal/project/auto/golang.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (builder *builder) BuildGolang() error {
262262
builder.targets = append(builder.targets, unitTests)
263263
allUnitTests = append(allUnitTests, unitTests)
264264

265-
coverage.InputPaths = append(coverage.InputPaths, fmt.Sprintf("coverage-%s.txt", unitTests.Name()))
265+
coverage.AddDiscoveredInputs(fmt.Sprintf("coverage-%s.txt", unitTests.Name()))
266266
}
267267

268268
builder.targets = append(builder.targets, coverage)

internal/project/auto/integration_tests.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
package auto
66

77
import (
8+
"fmt"
9+
"path/filepath"
10+
"strings"
11+
812
"github.com/siderolabs/gen/maps"
13+
"github.com/siderolabs/gen/xslices"
914

1015
"github.com/siderolabs/kres/internal/project/common"
1116
"github.com/siderolabs/kres/internal/project/golang"
@@ -31,7 +36,17 @@ func (builder *builder) BuildIntegrationTests() error {
3136
}
3237

3338
for _, spec := range integrationTests.Tests {
34-
build := golang.NewBuild(builder.meta, spec.Name, spec.Path, "go test -c -covermode=atomic")
39+
build := golang.NewBuild(builder.meta, spec.Name, spec.Path,
40+
fmt.Sprintf(
41+
"go test -c -covermode=atomic -coverpkg=%s",
42+
strings.Join(
43+
xslices.Map(builder.meta.CanonicalPaths, func(s string) string {
44+
return filepath.Join(s, "/...")
45+
}),
46+
",",
47+
),
48+
),
49+
)
3550

3651
build.Outputs = maps.Map(spec.Outputs, func(k string, m map[string]string) (string, golang.CompileConfig) {
3752
return k, golang.CompileConfig(m)

internal/project/service/codecov.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type CodeCov struct {
2525

2626
meta *meta.Options
2727

28+
discoveredPaths []string
2829
InputPaths []string `yaml:"inputPaths"`
2930
TargetThreshold int `yaml:"targetThreshold"`
3031
Enabled bool `yaml:"enabled"`
@@ -42,6 +43,11 @@ func NewCodeCov(meta *meta.Options) *CodeCov {
4243
}
4344
}
4445

46+
// AddDiscoveredInputs sets automatically discovered codecov.txt files.
47+
func (coverage *CodeCov) AddDiscoveredInputs(inputs ...string) {
48+
coverage.discoveredPaths = append(coverage.discoveredPaths, inputs...)
49+
}
50+
4551
// CompileDrone implements drone.Compiler.
4652
func (coverage *CodeCov) CompileDrone(output *drone.Output) error {
4753
if !coverage.Enabled {
@@ -62,7 +68,7 @@ func (coverage *CodeCov) CompileGitHubWorkflow(output *ghworkflow.Output) error
6268
return nil
6369
}
6470

65-
paths := xslices.Map(coverage.InputPaths, func(path string) string {
71+
paths := xslices.Map(append(coverage.discoveredPaths, coverage.InputPaths...), func(path string) string {
6672
return fmt.Sprintf("%s/%s", coverage.meta.ArtifactsPath, path)
6773
})
6874

0 commit comments

Comments
 (0)