1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-17 01:42:37 +02:00

Merge pull request #360 from goreleaser/linter

enabled more linters and fixed them
This commit is contained in:
Carlos Alexandro Becker
2017-09-16 14:09:01 -03:00
committed by GitHub
8 changed files with 76 additions and 75 deletions

View File

@ -25,20 +25,7 @@ fmt:
# Run all the linters # Run all the linters
lint: lint:
gometalinter --vendor --disable-all \ gometalinter --vendor ./...
--enable=deadcode \
--enable=ineffassign \
--enable=gosimple \
--enable=staticcheck \
--enable=gofmt \
--enable=goimports \
--enable=dupl \
--enable=misspell \
--enable=errcheck \
--enable=vet \
--enable=vetshadow \
--deadline=10m \
./...
# Run all the tests and code checks # Run all the tests and code checks
ci: test lint ci: test lint

View File

@ -24,7 +24,7 @@ func calculate(hash hash.Hash, path string) (result string, err error) {
return doCalculate(hash, file) return doCalculate(hash, file)
} }
func doCalculate(hash hash.Hash, file *os.File) (result string, err error) { func doCalculate(hash hash.Hash, file io.Reader) (result string, err error) {
_, err = io.Copy(hash, file) _, err = io.Copy(hash, file)
if err != nil { if err != nil {
return return

View File

@ -116,9 +116,6 @@ func TestNameDefaultTemplate(t *testing.T) {
}, },
Version: "1.2.3", Version: "1.2.3",
} }
type buildTarget struct {
goos, goarch, goarm string
}
for key, target := range map[string]buildtarget.Target{ for key, target := range map[string]buildtarget.Target{
"test_1.2.3_darwin_amd64": buildtarget.New("darwin", "amd64", ""), "test_1.2.3_darwin_amd64": buildtarget.New("darwin", "amd64", ""),
"test_1.2.3_linux_arm64": buildtarget.New("linux", "arm64", ""), "test_1.2.3_linux_arm64": buildtarget.New("linux", "arm64", ""),

View File

@ -57,7 +57,17 @@ func (Pipe) Run(ctx *context.Context) error {
} }
ctx.Config.Brew.Install = strings.Join(installs, "\n") ctx.Config.Brew.Install = strings.Join(installs, "\n")
} }
if len(ctx.Config.Dockers) == 1 {
err := setArchiveDefaults(ctx)
setDockerDefaults(ctx)
log.WithField("config", ctx.Config).Debug("defaults set")
return err
}
func setDockerDefaults(ctx *context.Context) {
if len(ctx.Config.Dockers) != 1 {
return
}
if ctx.Config.Dockers[0].Goos == "" { if ctx.Config.Dockers[0].Goos == "" {
ctx.Config.Dockers[0].Goos = "linux" ctx.Config.Dockers[0].Goos = "linux"
} }
@ -72,11 +82,6 @@ func (Pipe) Run(ctx *context.Context) error {
} }
} }
err := setArchiveDefaults(ctx)
log.WithField("config", ctx.Config).Debug("defaults set")
return err
}
func isBrewBuild(build config.Build) bool { func isBrewBuild(build config.Build) bool {
for _, ignore := range build.Ignore { for _, ignore := range build.Ignore {
if ignore.Goos == "darwin" && ignore.Goarch == "amd64" { if ignore.Goos == "darwin" && ignore.Goarch == "amd64" {

View File

@ -36,6 +36,10 @@ func (Pipe) Run(ctx *context.Context) error {
if err != nil { if err != nil {
return ErrNoDocker return ErrNoDocker
} }
return doRun(ctx)
}
func doRun(ctx *context.Context) error {
for _, docker := range ctx.Config.Dockers { for _, docker := range ctx.Config.Dockers {
var imagePlatform = docker.Goos + docker.Goarch + docker.Goarm var imagePlatform = docker.Goos + docker.Goarch + docker.Goarm
for platform, groups := range ctx.Binaries { for platform, groups := range ctx.Binaries {
@ -47,7 +51,7 @@ func (Pipe) Run(ctx *context.Context) error {
if binary.Name != docker.Binary { if binary.Name != docker.Binary {
continue continue
} }
var err = doRun(ctx, folder, docker, binary) var err = process(ctx, folder, docker, binary)
if err != nil && !pipeline.IsSkip(err) { if err != nil && !pipeline.IsSkip(err) {
return err return err
} }
@ -58,7 +62,7 @@ func (Pipe) Run(ctx *context.Context) error {
return nil return nil
} }
func doRun(ctx *context.Context, folder string, docker config.Docker, binary context.Binary) error { func process(ctx *context.Context, folder string, docker config.Docker, binary context.Binary) error {
var root = filepath.Join(ctx.Config.Dist, folder) var root = filepath.Join(ctx.Config.Dist, folder)
var dockerfile = filepath.Join(root, filepath.Base(docker.Dockerfile)) var dockerfile = filepath.Join(root, filepath.Base(docker.Dockerfile))
var image = fmt.Sprintf("%s:%s", docker.Image, ctx.Version) var image = fmt.Sprintf("%s:%s", docker.Image, ctx.Version)

View File

@ -35,7 +35,10 @@ func (Pipe) Run(ctx *context.Context) error {
if err != nil { if err != nil {
return ErrNoFPM return ErrNoFPM
} }
return doRun(ctx)
}
func doRun(ctx *context.Context) error {
var g errgroup.Group var g errgroup.Group
for _, format := range ctx.Config.FPM.Formats { for _, format := range ctx.Config.FPM.Formats {
for platform, groups := range ctx.Binaries { for platform, groups := range ctx.Binaries {
@ -61,6 +64,41 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex
var log = log.WithField("format", format).WithField("arch", arch) var log = log.WithField("format", format).WithField("arch", arch)
log.WithField("file", file).Info("creating fpm archive") log.WithField("file", file).Info("creating fpm archive")
var options = basicOptions(ctx, format, arch, file)
for _, binary := range binaries {
// This basically tells fpm to put the binary in the /usr/local/bin
// binary=/usr/local/bin/binary
log.WithField("path", binary.Path).
WithField("name", binary.Name).
Debug("added binary to fpm package")
options = append(options, fmt.Sprintf(
"%s=%s",
binary.Path,
filepath.Join("/usr/local/bin", binary.Name),
))
}
for src, dest := range ctx.Config.FPM.Files {
log.WithField("src", src).
WithField("dest", dest).
Debug("added an extra file to the fpm package")
options = append(options, fmt.Sprintf(
"%s=%s",
src,
dest,
))
}
log.WithField("args", options).Debug("creating fpm package")
if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil {
return errors.New(string(out))
}
ctx.AddArtifact(file)
return nil
}
func basicOptions(ctx *context.Context, format, arch, file string) []string {
var options = []string{ var options = []string{
"--input-type", "dir", "--input-type", "dir",
"--output-type", format, "--output-type", format,
@ -97,35 +135,5 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex
if format == "rpm" { if format == "rpm" {
options = append(options, "--rpm-os", "linux") options = append(options, "--rpm-os", "linux")
} }
return options
for _, binary := range binaries {
// This basically tells fpm to put the binary in the /usr/local/bin
// binary=/usr/local/bin/binary
log.WithField("path", binary.Path).
WithField("name", binary.Name).
Debug("added binary to fpm package")
options = append(options, fmt.Sprintf(
"%s=%s",
binary.Path,
filepath.Join("/usr/local/bin", binary.Name),
))
}
for src, dest := range ctx.Config.FPM.Files {
log.WithField("src", src).
WithField("dest", dest).
Debug("added an extra file to the fpm package")
options = append(options, fmt.Sprintf(
"%s=%s",
src,
dest,
))
}
log.WithField("args", options).Debug("creating fpm package")
if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil {
return errors.New(string(out))
}
ctx.AddArtifact(file)
return nil
} }

View File

@ -27,8 +27,8 @@ var ErrNoDescription = errors.New("no description provided for snapcraft")
// ErrNoSummary is shown when no summary provided // ErrNoSummary is shown when no summary provided
var ErrNoSummary = errors.New("no summary provided for snapcraft") var ErrNoSummary = errors.New("no summary provided for snapcraft")
// SnapcraftMetadata to generate the snap package // Metadata to generate the snap package
type SnapcraftMetadata struct { type Metadata struct {
Name string Name string
Version string Version string
Summary string Summary string
@ -99,7 +99,7 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
var file = filepath.Join(primeDir, "meta", "snap.yaml") var file = filepath.Join(primeDir, "meta", "snap.yaml")
log.WithField("file", file).Debug("creating snap metadata") log.WithField("file", file).Debug("creating snap metadata")
var metadata = &SnapcraftMetadata{ var metadata = &Metadata{
Version: ctx.Version, Version: ctx.Version,
Summary: ctx.Config.Snapcraft.Summary, Summary: ctx.Config.Snapcraft.Summary,
Description: ctx.Config.Snapcraft.Description, Description: ctx.Config.Snapcraft.Description,

View File

@ -85,10 +85,10 @@ func TestRunPipeWithName(t *testing.T) {
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(Pipe{}.Run(ctx))
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "testprojectname_linuxamd64", "prime", "meta", "snap.yaml")) yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "testprojectname_linuxamd64", "prime", "meta", "snap.yaml"))
assert.NoError(err) assert.NoError(err)
var snapcraftMetadata SnapcraftMetadata var metadata Metadata
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata) err = yaml.Unmarshal(yamlFile, &metadata)
assert.NoError(err) assert.NoError(err)
assert.Equal(snapcraftMetadata.Name, "testsnapname") assert.Equal(metadata.Name, "testsnapname")
} }
func TestRunPipeWithPlugsAndDaemon(t *testing.T) { func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
@ -119,11 +119,11 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(Pipe{}.Run(ctx))
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml")) yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml"))
assert.NoError(err) assert.NoError(err)
var snapcraftMetadata SnapcraftMetadata var metadata Metadata
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata) err = yaml.Unmarshal(yamlFile, &metadata)
assert.NoError(err) assert.NoError(err)
assert.Equal(snapcraftMetadata.Apps["mybin"].Plugs, []string{"home", "network"}) assert.Equal(metadata.Apps["mybin"].Plugs, []string{"home", "network"})
assert.Equal(snapcraftMetadata.Apps["mybin"].Daemon, "simple") assert.Equal(metadata.Apps["mybin"].Daemon, "simple")
} }
func TestNoSnapcraftInPath(t *testing.T) { func TestNoSnapcraftInPath(t *testing.T) {