mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-27 01:33:39 +02:00
parent
ac40ce8a80
commit
f5c4fce822
@ -15,6 +15,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/v2/internal/middleware/errhandler"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/middleware/logging"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/middleware/skip"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipe/git"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipeline"
|
||||
"github.com/goreleaser/goreleaser/v2/internal/skips"
|
||||
"github.com/goreleaser/goreleaser/v2/pkg/config"
|
||||
@ -31,6 +32,7 @@ type buildOpts struct {
|
||||
config string
|
||||
ids []string
|
||||
snapshot bool
|
||||
autoSnapshot bool
|
||||
clean bool
|
||||
deprecated bool
|
||||
parallelism int
|
||||
@ -72,6 +74,7 @@ When using ` + "`--single-target`" + `, the ` + "`GOOS`" + ` and ` + "`GOARCH`"
|
||||
cmd.Flags().StringVarP(&root.opts.config, "config", "f", "", "Load configuration from file")
|
||||
_ = cmd.MarkFlagFilename("config", "yaml", "yml")
|
||||
cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot build, skipping all validations")
|
||||
cmd.Flags().BoolVar(&root.opts.autoSnapshot, "auto-snapshot", false, "Automatically sets --snapshot if the repository is dirty")
|
||||
cmd.Flags().BoolVar(&root.opts.clean, "clean", false, "Removes the 'dist' directory before building")
|
||||
cmd.Flags().IntVarP(&root.opts.parallelism, "parallelism", "p", 0, "Number of tasks to run concurrently (default: number of CPUs)")
|
||||
_ = cmd.RegisterFlagCompletionFunc("parallelism", cobra.NoFileCompletions)
|
||||
@ -153,6 +156,11 @@ func setupBuildContext(ctx *context.Context, options buildOpts) error {
|
||||
log.Debugf("parallelism: %v", ctx.Parallelism)
|
||||
ctx.Snapshot = options.snapshot
|
||||
|
||||
if options.autoSnapshot && git.CheckDirty(ctx) != nil {
|
||||
log.Info("git repository is dirty and --auto-snapshot is set, implying --snapshot")
|
||||
ctx.Snapshot = true
|
||||
}
|
||||
|
||||
if err := skips.SetBuild(ctx, options.skips...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/v2/internal/pipeline"
|
||||
@ -18,6 +19,29 @@ func TestBuild(t *testing.T) {
|
||||
require.NoError(t, cmd.cmd.Execute())
|
||||
}
|
||||
|
||||
func TestBuildAutoSnapshot(t *testing.T) {
|
||||
t.Run("clean", func(t *testing.T) {
|
||||
setup(t)
|
||||
cmd := newBuildCmd()
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot"})
|
||||
require.NoError(t, cmd.cmd.Execute())
|
||||
matches, err := filepath.Glob("./dist/fake_*/fake")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, matches, 1)
|
||||
})
|
||||
|
||||
t.Run("dirty", func(t *testing.T) {
|
||||
setup(t)
|
||||
createFile(t, "foo", "force dirty tree")
|
||||
cmd := newBuildCmd()
|
||||
cmd.cmd.SetArgs([]string{"--auto-snapshot"})
|
||||
require.NoError(t, cmd.cmd.Execute())
|
||||
matches, err := filepath.Glob("./dist/fake_*/fake_snapshot")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, matches, 1)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBuildSingleTarget(t *testing.T) {
|
||||
setup(t)
|
||||
cmd := newBuildCmd()
|
||||
|
@ -69,7 +69,7 @@ go 1.22
|
||||
func createGoReleaserYaml(tb testing.TB) {
|
||||
tb.Helper()
|
||||
yaml := `builds:
|
||||
- binary: fake
|
||||
- binary: 'fake{{if .IsSnapshot}}_snapshot{{end}}'
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
|
Loading…
Reference in New Issue
Block a user