Skip to content

Commit bf79483

Browse files
author
Christian Weichel
committed
Add global dont-test command-line flag
Using `--dont-test` one can now disable package-level tests. The effect is the same as if one were to set `dontTest` on all packages. Using this flag does not affect a packages version.
1 parent 77b9901 commit bf79483

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

cmd/build.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ var buildCmd = &cobra.Command{
9797
reporter = leeway.NewConsoleReporter()
9898
}
9999

100+
dontTest, err := cmd.Flags().GetBool("dont-test")
101+
if err != nil {
102+
log.Fatal(err)
103+
}
104+
100105
err = leeway.Build(pkg,
101106
leeway.WithLocalCache(localCache),
102107
leeway.WithRemoteCache(remoteCache),
103108
leeway.WithDryRun(dryrun),
104109
leeway.WithBuildPlan(planOutlet),
105110
leeway.WithReporter(reporter),
111+
leeway.WithDontTest(dontTest),
106112
)
107113
if err != nil {
108114
log.Fatal(err)
@@ -176,6 +182,7 @@ func init() {
176182
buildCmd.Flags().String("save", "", "After a successful build this saves the build result as tar.gz file in the local filesystem (e.g. --save build-result.tar.gz)")
177183
buildCmd.Flags().String("dump-plan", "", "Writes the build plan as JSON to a file. Use \"-\" to write the build plan to stderr.")
178184
buildCmd.Flags().Bool("werft", false, "Produce werft CI compatible output")
185+
buildCmd.Flags().Bool("dont-test", false, "Disable all package-level tests (defaults to false)")
179186
}
180187

181188
type pushOnlyRemoteCache struct {

pkg/leeway/build.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ type packageDuringBuild struct {
4444
}
4545

4646
type buildContext struct {
47-
LocalCache Cache
48-
Reporter Reporter
49-
47+
buildOptions
5048
buildDir string
5149

5250
mu sync.Mutex
@@ -82,15 +80,14 @@ var buildProcessVersions = map[PackageType]int{
8280
GenericPackage: 1,
8381
}
8482

85-
func newBuildContext(localCache Cache, reporter Reporter) (ctx *buildContext, err error) {
83+
func newBuildContext(options buildOptions) (ctx *buildContext, err error) {
8684
buildDir := os.Getenv(EnvvarBuildDir)
8785
if buildDir == "" {
8886
buildDir = filepath.Join(os.TempDir(), "build")
8987
}
9088

9189
ctx = &buildContext{
92-
LocalCache: localCache,
93-
Reporter: reporter,
90+
buildOptions: options,
9491
buildDir: buildDir,
9592
newlyBuiltPackages: make(map[string]*Package),
9693
pkgLockCond: sync.NewCond(&sync.Mutex{}),
@@ -174,6 +171,7 @@ type buildOptions struct {
174171
Reporter Reporter
175172
DryRun bool
176173
BuildPlan io.Writer
174+
DontTest bool
177175
}
178176

179177
// BuildOption configures the build behaviour
@@ -219,6 +217,14 @@ func WithBuildPlan(out io.Writer) BuildOption {
219217
}
220218
}
221219

220+
// WithDontTest disables package-level tests
221+
func WithDontTest(dontTest bool) BuildOption {
222+
return func(opts *buildOptions) error {
223+
opts.DontTest = dontTest
224+
return nil
225+
}
226+
}
227+
222228
// Build builds the packages in the order they're given. It's the callers responsibility to ensure the dependencies are built
223229
// in order.
224230
func Build(pkg *Package, opts ...BuildOption) (err error) {
@@ -237,7 +243,7 @@ func Build(pkg *Package, opts ...BuildOption) (err error) {
237243
return xerrors.Errorf("cannot build without local cache. Use WithLocalCache() to configure one")
238244
}
239245

240-
ctx, err := newBuildContext(options.LocalCache, options.Reporter)
246+
ctx, err := newBuildContext(options)
241247

242248
requirements := pkg.GetTransitiveDependencies()
243249
allpkg := append(requirements, pkg)
@@ -686,7 +692,7 @@ func (p *Package) buildTypescript(buildctx *buildContext, wd, result string) (er
686692
} else {
687693
commands = append(commands, cfg.Commands.Build)
688694
}
689-
if !cfg.DontTest {
695+
if !cfg.DontTest && !buildctx.DontTest {
690696
if len(cfg.Commands.Test) == 0 {
691697
commands = append(commands, []string{"yarn", "test"})
692698
} else {
@@ -785,7 +791,7 @@ func (p *Package) buildGo(buildctx *buildContext, wd, result string) (err error)
785791
if cfg.Generate {
786792
commands = append(commands, []string{"go", "generate", "-v", "./..."})
787793
}
788-
if !cfg.DontTest {
794+
if !cfg.DontTest && !buildctx.DontTest {
789795
commands = append(commands, [][]string{
790796
// we build the test binaries in addition to running the tests regularly, so that downstream packages can run the tests in different environments
791797
{"sh", "-c", "mkdir _tests; for i in $(go list ./...); do go test -c $i; [ -e $(basename $i).test ] && mv $(basename $i).test _tests; true; done"},

0 commit comments

Comments
 (0)