mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
Merge pull request #360 from goreleaser/linter
enabled more linters and fixed them
This commit is contained in:
commit
5ac2918380
15
Makefile
15
Makefile
@ -25,20 +25,7 @@ fmt:
|
||||
|
||||
# Run all the linters
|
||||
lint:
|
||||
gometalinter --vendor --disable-all \
|
||||
--enable=deadcode \
|
||||
--enable=ineffassign \
|
||||
--enable=gosimple \
|
||||
--enable=staticcheck \
|
||||
--enable=gofmt \
|
||||
--enable=goimports \
|
||||
--enable=dupl \
|
||||
--enable=misspell \
|
||||
--enable=errcheck \
|
||||
--enable=vet \
|
||||
--enable=vetshadow \
|
||||
--deadline=10m \
|
||||
./...
|
||||
gometalinter --vendor ./...
|
||||
|
||||
# Run all the tests and code checks
|
||||
ci: test lint
|
||||
|
@ -24,7 +24,7 @@ func calculate(hash hash.Hash, path string) (result string, err error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -116,9 +116,6 @@ func TestNameDefaultTemplate(t *testing.T) {
|
||||
},
|
||||
Version: "1.2.3",
|
||||
}
|
||||
type buildTarget struct {
|
||||
goos, goarch, goarm string
|
||||
}
|
||||
for key, target := range map[string]buildtarget.Target{
|
||||
"test_1.2.3_darwin_amd64": buildtarget.New("darwin", "amd64", ""),
|
||||
"test_1.2.3_linux_arm64": buildtarget.New("linux", "arm64", ""),
|
||||
|
@ -57,7 +57,17 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
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 == "" {
|
||||
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 {
|
||||
for _, ignore := range build.Ignore {
|
||||
if ignore.Goos == "darwin" && ignore.Goarch == "amd64" {
|
||||
|
@ -36,6 +36,10 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if err != nil {
|
||||
return ErrNoDocker
|
||||
}
|
||||
return doRun(ctx)
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context) error {
|
||||
for _, docker := range ctx.Config.Dockers {
|
||||
var imagePlatform = docker.Goos + docker.Goarch + docker.Goarm
|
||||
for platform, groups := range ctx.Binaries {
|
||||
@ -47,7 +51,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if binary.Name != docker.Binary {
|
||||
continue
|
||||
}
|
||||
var err = doRun(ctx, folder, docker, binary)
|
||||
var err = process(ctx, folder, docker, binary)
|
||||
if err != nil && !pipeline.IsSkip(err) {
|
||||
return err
|
||||
}
|
||||
@ -58,7 +62,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
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 dockerfile = filepath.Join(root, filepath.Base(docker.Dockerfile))
|
||||
var image = fmt.Sprintf("%s:%s", docker.Image, ctx.Version)
|
||||
|
@ -35,7 +35,10 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
if err != nil {
|
||||
return ErrNoFPM
|
||||
}
|
||||
return doRun(ctx)
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context) error {
|
||||
var g errgroup.Group
|
||||
for _, format := range ctx.Config.FPM.Formats {
|
||||
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)
|
||||
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{
|
||||
"--input-type", "dir",
|
||||
"--output-type", format,
|
||||
@ -97,35 +135,5 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex
|
||||
if format == "rpm" {
|
||||
options = append(options, "--rpm-os", "linux")
|
||||
}
|
||||
|
||||
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
|
||||
return options
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ var ErrNoDescription = errors.New("no description provided for snapcraft")
|
||||
// ErrNoSummary is shown when no summary provided
|
||||
var ErrNoSummary = errors.New("no summary provided for snapcraft")
|
||||
|
||||
// SnapcraftMetadata to generate the snap package
|
||||
type SnapcraftMetadata struct {
|
||||
// Metadata to generate the snap package
|
||||
type Metadata struct {
|
||||
Name string
|
||||
Version 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")
|
||||
log.WithField("file", file).Debug("creating snap metadata")
|
||||
|
||||
var metadata = &SnapcraftMetadata{
|
||||
var metadata = &Metadata{
|
||||
Version: ctx.Version,
|
||||
Summary: ctx.Config.Snapcraft.Summary,
|
||||
Description: ctx.Config.Snapcraft.Description,
|
||||
|
@ -85,10 +85,10 @@ func TestRunPipeWithName(t *testing.T) {
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "testprojectname_linuxamd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(err)
|
||||
var snapcraftMetadata SnapcraftMetadata
|
||||
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata)
|
||||
var metadata Metadata
|
||||
err = yaml.Unmarshal(yamlFile, &metadata)
|
||||
assert.NoError(err)
|
||||
assert.Equal(snapcraftMetadata.Name, "testsnapname")
|
||||
assert.Equal(metadata.Name, "testsnapname")
|
||||
}
|
||||
|
||||
func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
|
||||
@ -119,11 +119,11 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(err)
|
||||
var snapcraftMetadata SnapcraftMetadata
|
||||
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata)
|
||||
var metadata Metadata
|
||||
err = yaml.Unmarshal(yamlFile, &metadata)
|
||||
assert.NoError(err)
|
||||
assert.Equal(snapcraftMetadata.Apps["mybin"].Plugs, []string{"home", "network"})
|
||||
assert.Equal(snapcraftMetadata.Apps["mybin"].Daemon, "simple")
|
||||
assert.Equal(metadata.Apps["mybin"].Plugs, []string{"home", "network"})
|
||||
assert.Equal(metadata.Apps["mybin"].Daemon, "simple")
|
||||
}
|
||||
|
||||
func TestNoSnapcraftInPath(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user