diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c1776c7ec1..7b484665118 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: make ci - name: Upload coverage - uses: codecov/codecov-action@v1.0.13 + uses: codecov/codecov-action@v1.0.14 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.txt @@ -76,9 +76,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GH_PAT }} run: | if [[ $GITHUB_REF == refs/tags/v* ]]; then - ./goreleaser --parallelism 2 + ./goreleaser else - ./goreleaser --snapshot --parallelism 2 + ./goreleaser --snapshot fi - name: Clear diff --git a/.github/workflows/gosum.yml b/.github/workflows/gosum.yml index cd346ba0165..0e33f748a9c 100644 --- a/.github/workflows/gosum.yml +++ b/.github/workflows/gosum.yml @@ -26,7 +26,7 @@ jobs: run: | rm -f go.sum go mod tidy - - uses: stefanzweifel/git-auto-commit-action@v4.5.1 + - uses: stefanzweifel/git-auto-commit-action@v4.6.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/cmd/completion.go b/cmd/completion.go new file mode 100644 index 00000000000..38383039db9 --- /dev/null +++ b/cmd/completion.go @@ -0,0 +1,34 @@ +package cmd + +import "github.com/spf13/cobra" + +type completionCmd struct { + cmd *cobra.Command +} + +func newCompletionCmd() *completionCmd { + var root = &completionCmd{} + var cmd = &cobra.Command{ + Use: "completion", + Short: "Print shell autocompletion scripts for goreleaser", + SilenceUsage: true, + ValidArgs: []string{"bash", "zsh", "fish"}, + Args: cobra.ExactValidArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + var err error + switch args[0] { + case "bash": + err = cmd.Root().GenBashCompletion(cmd.OutOrStdout()) + case "zsh": + err = cmd.Root().GenZshCompletion(cmd.OutOrStdout()) + case "fish": + err = cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true) + } + + return err + }, + } + + root.cmd = cmd + return root +} diff --git a/cmd/completion_test.go b/cmd/completion_test.go new file mode 100644 index 00000000000..f619716366f --- /dev/null +++ b/cmd/completion_test.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCompletionGeneration(t *testing.T) { + for _, shell := range []string{"bash", "zsh", "fish"} { + t.Run(shell, func(t *testing.T) { + completionCmd := newCompletionCmd().cmd + stdout := bytes.NewBufferString("") + stderr := bytes.NewBufferString("") + completionCmd.SetOut(stdout) + completionCmd.SetErr(stderr) + completionCmd.SetArgs([]string{shell}) + err := completionCmd.Execute() + require.NoError(t, err, shell+" arg experienced error with goreleaser completion:\n"+stderr.String()) + require.Equal(t, "", stderr.String(), shell+" arg experienced error with goreleaser completion:\n"+stderr.String()) + require.NotEmpty(t, stdout.String(), shell+" arg reported nothing to stdout with goreleaser completion") + }) + } +} diff --git a/cmd/root.go b/cmd/root.go index d258aa716f9..e1bfdc0b9de 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,6 +74,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd { newReleaseCmd().cmd, newCheckCmd().cmd, newInitCmd().cmd, + newCompletionCmd().cmd, ) root.cmd = cmd @@ -88,8 +89,8 @@ func shouldPrependRelease(cmd *cobra.Command, args []string) bool { return false } - // allow help command. - if len(args) > 0 && args[0] == "help" { + // allow help and __complete commands. + if len(args) > 0 && (args[0] == "help" || args[0] == "__complete") { return false } diff --git a/cmd/root_test.go b/cmd/root_test.go index f991debd10b..0e5ad0544f5 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -88,4 +88,8 @@ func TestShouldPrependRelease(t *testing.T) { t.Run("help", func(t *testing.T) { require.False(t, result([]string{"help"})) }) + + t.Run("__complete", func(t *testing.T) { + require.False(t, result([]string{"help"})) + }) } diff --git a/go.mod b/go.mod index 4466cd72c3e..3de74be86c0 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/mattn/go-shellwords v1.0.10 github.com/mattn/go-zglob v0.0.3 github.com/mitchellh/go-homedir v1.1.0 - github.com/spf13/cobra v1.0.0 + github.com/spf13/cobra v1.1.1 github.com/stretchr/testify v1.6.1 github.com/ulikunitz/xz v0.5.8 github.com/xanzy/go-gitlab v0.38.1 diff --git a/go.sum b/go.sum index 16051483e65..22651a51081 100644 --- a/go.sum +++ b/go.sum @@ -593,6 +593,8 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= +github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index 7cac6d1231a..64e89d4a2a0 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -97,7 +97,7 @@ func (Pipe) Run(ctx *context.Context) error { artifact.ByIDs(archive.Builds...), ), ).GroupByPlatform() - if err := checkArtifacts(artifacts); err != nil { + if err := checkArtifacts(artifacts); err != nil && !archive.AllowDifferentBinaryCount { return fmt.Errorf("invalid archive: %d: %w", i, ErrArchiveDifferentBinaryCount) } for group, artifacts := range artifacts { @@ -119,7 +119,7 @@ func checkArtifacts(artifacts map[string][]*artifact.Artifact) error { for _, v := range artifacts { lens[len(v)] = true } - if len(lens) == 1 { + if len(lens) <= 1 { return nil } return ErrArchiveDifferentBinaryCount diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index 71eb0e8f864..82a9e39381c 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -241,7 +241,31 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) { ctx.Artifacts.Add(linuxArmBuild) ctx.Version = "0.0.1" ctx.Git.CurrentTag = "v0.0.1" - require.EqualError(t, Pipe{}.Run(ctx), "invalid archive: 0: "+ErrArchiveDifferentBinaryCount.Error()) + + t.Run("check enabled", func(t *testing.T) { + ctx.Config.Archives[0].AllowDifferentBinaryCount = false + require.EqualError(t, Pipe{}.Run(ctx), "invalid archive: 0: "+ErrArchiveDifferentBinaryCount.Error()) + }) + + t.Run("check disabled", func(t *testing.T) { + ctx.Config.Archives[0].AllowDifferentBinaryCount = true + require.NoError(t, Pipe{}.Run(ctx)) + }) +} + +func TestRunPipeNoBinaries(t *testing.T) { + folder, back := testlib.Mktmp(t) + defer back() + var dist = filepath.Join(folder, "dist") + require.NoError(t, os.Mkdir(dist, 0755)) + var ctx = context.New(config.Project{ + Dist: dist, + ProjectName: "foobar", + Archives: []config.Archive{{}}, + }) + ctx.Version = "0.0.1" + ctx.Git.CurrentTag = "v0.0.1" + require.NoError(t, Pipe{}.Run(ctx)) } func zipFiles(t *testing.T, path string) []string { diff --git a/pkg/config/config.go b/pkg/config/config.go index bc81feb5561..499a2578f86 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -261,14 +261,15 @@ type FormatOverride struct { // Archive config used for the archive. type Archive struct { - ID string `yaml:",omitempty"` - Builds []string `yaml:",omitempty"` - NameTemplate string `yaml:"name_template,omitempty"` - Replacements map[string]string `yaml:",omitempty"` - Format string `yaml:",omitempty"` - FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"` - WrapInDirectory string `yaml:"wrap_in_directory,omitempty"` - Files []string `yaml:",omitempty"` + ID string `yaml:",omitempty"` + Builds []string `yaml:",omitempty"` + NameTemplate string `yaml:"name_template,omitempty"` + Replacements map[string]string `yaml:",omitempty"` + Format string `yaml:",omitempty"` + FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"` + WrapInDirectory string `yaml:"wrap_in_directory,omitempty"` + Files []string `yaml:",omitempty"` + AllowDifferentBinaryCount bool `yaml:"allow_different_binary_count"` } // Release config used for the GitHub/GitLab release. diff --git a/www/docs/customization/archive.md b/www/docs/customization/archive.md index 946dc2bad89..615700abe0f 100644 --- a/www/docs/customization/archive.md +++ b/www/docs/customization/archive.md @@ -69,6 +69,10 @@ archives: - docs/* - design/*.png - templates/**/* + + # Disables the binary count check. + # Default: false + allow_different_binary_count: true ``` !!! tip