From 229c8f54a51a8b25313a752016983c44e47e0214 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 11 Oct 2020 13:00:42 -0300 Subject: [PATCH 1/8] fix: archive check when project is a library Signed-off-by: Carlos Alexandro Becker --- internal/pipe/archive/archive.go | 2 +- internal/pipe/archive/archive_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index 7cac6d1231a..14641188e44 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -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..b89fa325a19 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -244,6 +244,21 @@ func TestRunPipeDifferentBinaryCount(t *testing.T) { require.EqualError(t, Pipe{}.Run(ctx), "invalid archive: 0: "+ErrArchiveDifferentBinaryCount.Error()) } +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 { f, err := os.Open(path) require.NoError(t, err) From 4657a61f0dcdbcf485b96479bed8e7369436ed78 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 09:03:40 -0300 Subject: [PATCH 2/8] chore(deps): bump stefanzweifel/git-auto-commit-action (#1851) Bumps [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) from v4.5.1 to v4.6.0. - [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases) - [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.5.1...5c9bfe7477fd67ca1ffc9fed4a69fb7a6a46dcfe) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/gosum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From e3a408bf1e1e76aeb3c8efc9efc654ac5b89d117 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 12 Oct 2020 09:15:17 -0300 Subject: [PATCH 3/8] chore(ci): parallelism Signed-off-by: Carlos Alexandro Becker --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c1776c7ec1..d382a733971 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 From ff2495fbd1578347efe00d70d80a05d93976fadb Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 13 Oct 2020 17:57:08 -0300 Subject: [PATCH 4/8] feat: allow to disable archive binary count check (#1856) closes #1855 Signed-off-by: Carlos Alexandro Becker --- internal/pipe/archive/archive.go | 2 +- internal/pipe/archive/archive_test.go | 11 ++++++++++- pkg/config/config.go | 17 +++++++++-------- www/docs/customization/archive.md | 4 ++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index 14641188e44..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 { diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index b89fa325a19..82a9e39381c 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -241,7 +241,16 @@ 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) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 83d58f2601f..7959f299e23 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 From f1bd471526a763bb4c0e573caf24a67f7daf176e Mon Sep 17 00:00:00 2001 From: Daniel Helfand Date: Thu, 15 Oct 2020 14:49:15 -0500 Subject: [PATCH 5/8] feat: add shell autocompletion to goreleaser for bash and zsh (#1859) --- cmd/completion.go | 34 ++++++++++++++++++++++++++++++++++ cmd/completion_test.go | 23 +++++++++++++++++++++++ cmd/root.go | 1 + 3 files changed, 58 insertions(+) create mode 100644 cmd/completion.go create mode 100644 cmd/completion_test.go diff --git a/cmd/completion.go b/cmd/completion.go new file mode 100644 index 00000000000..b238d38a02e --- /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 for bash and zsh", + SilenceUsage: true, + ValidArgs: []string{"bash", "zsh"}, + 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()) + } + + 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..33dfe11b44f --- /dev/null +++ b/cmd/completion_test.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCompletionGeneration(t *testing.T) { + for _, shell := range []string{"bash", "zsh"} { + 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..f7adcb256aa 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 From afda24a1e980082a0c401cd724327daba4c95781 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 16 Oct 2020 08:01:36 -0300 Subject: [PATCH 6/8] feat: add fish completion (#1860) refs #1858 # #1859 Signed-off-by: Carlos Alexandro Becker --- cmd/completion.go | 10 +++++----- cmd/completion_test.go | 24 +++++++++++++----------- cmd/root.go | 4 ++-- cmd/root_test.go | 4 ++++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cmd/completion.go b/cmd/completion.go index b238d38a02e..38383039db9 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -1,8 +1,6 @@ package cmd -import ( - "github.com/spf13/cobra" -) +import "github.com/spf13/cobra" type completionCmd struct { cmd *cobra.Command @@ -12,9 +10,9 @@ func newCompletionCmd() *completionCmd { var root = &completionCmd{} var cmd = &cobra.Command{ Use: "completion", - Short: "Print shell autocompletion scripts for goreleaser for bash and zsh", + Short: "Print shell autocompletion scripts for goreleaser", SilenceUsage: true, - ValidArgs: []string{"bash", "zsh"}, + ValidArgs: []string{"bash", "zsh", "fish"}, Args: cobra.ExactValidArgs(1), RunE: func(cmd *cobra.Command, args []string) error { var err error @@ -23,6 +21,8 @@ func newCompletionCmd() *completionCmd { 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 diff --git a/cmd/completion_test.go b/cmd/completion_test.go index 33dfe11b44f..f619716366f 100644 --- a/cmd/completion_test.go +++ b/cmd/completion_test.go @@ -8,16 +8,18 @@ import ( ) func TestCompletionGeneration(t *testing.T) { - for _, shell := range []string{"bash", "zsh"} { - 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") + 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 f7adcb256aa..e1bfdc0b9de 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -89,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"})) + }) } From 037ccbe388db39bfb77ed49cc13adc50795c256e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2020 09:58:37 -0300 Subject: [PATCH 7/8] chore(deps): bump github.com/spf13/cobra from 1.0.0 to 1.1.1 (#1864) Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from 1.0.0 to 1.1.1. - [Release notes](https://github.com/spf13/cobra/releases) - [Changelog](https://github.com/spf13/cobra/blob/master/CHANGELOG.md) - [Commits](https://github.com/spf13/cobra/compare/v1.0.0...v1.1.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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= From 8c5d93630820ed7d55734be2f4f93578522040b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2020 09:58:53 -0300 Subject: [PATCH 8/8] chore(deps): bump codecov/codecov-action from v1.0.13 to v1.0.14 (#1863) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from v1.0.13 to v1.0.14. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Commits](https://github.com/codecov/codecov-action/compare/v1.0.13...7d5dfa54903bd909319c580a00535b483d1efcf3) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d382a733971..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