Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into latest-nfpm-config
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlloyd committed Oct 21, 2020
2 parents 1449777 + 8c5d936 commit b422197
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gosum.yml
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions 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
}
25 changes: 25 additions & 0 deletions 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")
})
}
}
5 changes: 3 additions & 2 deletions cmd/root.go
Expand Up @@ -74,6 +74,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd {
newReleaseCmd().cmd,
newCheckCmd().cmd,
newInitCmd().cmd,
newCompletionCmd().cmd,
)

root.cmd = cmd
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/root_test.go
Expand Up @@ -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"}))
})
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/archive/archive.go
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion internal/pipe/archive/archive_test.go
Expand Up @@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions pkg/config/config.go
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions www/docs/customization/archive.md
Expand Up @@ -69,6 +69,10 @@ archives:
- docs/*
- design/*.png
- templates/**/*

# Disables the binary count check.
# Default: false
allow_different_binary_count: true
```

!!! tip
Expand Down

0 comments on commit b422197

Please sign in to comment.