1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

Merge pull request #321 from goreleaser/improvements

small improvements
This commit is contained in:
Carlos Alexandro Becker 2017-08-03 22:44:25 -03:00 committed by GitHub
commit 8a0936f8cd
5 changed files with 47 additions and 35 deletions

View File

@ -179,11 +179,11 @@ func LoadReader(fd io.Reader) (config Project, err error) {
if err != nil {
return config, err
}
err = yaml.Unmarshal(data, &config)
if err := yaml.Unmarshal(data, &config); err != nil {
return config, err
}
log.WithField("config", config).Debug("loaded config file")
err = checkOverflows(config)
return
return config, checkOverflows(config)
}
func checkOverflows(config Project) error {

View File

@ -60,3 +60,9 @@ func TestInvalidFields(t *testing.T) {
_, err := Load("testdata/invalid_config.yml")
assert.EqualError(err, "unknown fields in the config file: invalid_root, archive.invalid_archive, archive.format_overrides[0].invalid_archive_fmtoverrides, brew.invalid_brew, brew.github.invalid_brew_github, builds[0].invalid_builds, builds[0].hooks.invalid_builds_hooks, builds[0].ignored_builds[0].invalid_builds_ignore, fpm.invalid_fpm, release.invalid_release, release.github.invalid_release_github, build.invalid_build, builds.hooks.invalid_build_hook, builds.ignored_builds[0].invalid_build_ignore, snapshot.invalid_snapshot")
}
func TestInvalidYaml(t *testing.T) {
var assert = assert.New(t)
_, err := Load("testdata/invalid.yml")
assert.EqualError(err, "yaml: line 1: did not find expected node content")
}

1
config/testdata/invalid.yml vendored Normal file
View File

@ -0,0 +1 @@
this_is_not_valid: [

View File

@ -3,6 +3,7 @@ package snapcraft
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
@ -51,7 +52,7 @@ func (Pipe) Run(ctx *context.Context) error {
log.Error("no snapcraft summary defined, skipping")
return nil
}
if ctx.Config.Snapcraft.Summary == "" {
if ctx.Config.Snapcraft.Description == "" {
log.Error("no snapcraft description defined, skipping")
return nil
}
@ -120,7 +121,9 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
metadata.Apps[binary.Name] = AppsMetadata{Command: binary.Name}
destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path))
os.Link(binary.Path, destBinaryPath)
if err := os.Link(binary.Path, destBinaryPath); err != nil {
return err
}
}
out, err := yaml.Marshal(metadata)
if err != nil {
@ -131,12 +134,14 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
return err
}
snap := metadata.Name + "_" + metadata.Version + "_" + arch + ".snap"
cmd := exec.Command("snapcraft", "snap", "prime", "--output", snap)
cmd.Dir = folderDir
snap := filepath.Join(
ctx.Config.Dist,
metadata.Name+"_"+metadata.Version+"_"+arch+".snap",
)
cmd := exec.Command("snapcraft", "snap", primeDir, "--output", snap)
if out, err = cmd.CombinedOutput(); err != nil {
return errors.New(string(out))
return fmt.Errorf("failed to generate snap package: %s", string(out))
}
ctx.AddArtifact(filepath.Join(folderDir, snap))
ctx.AddArtifact(snap)
return nil
}

View File

@ -15,28 +15,27 @@ func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
func TestRunPipeNoSummary(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Snapcraft: config.Snapcraft{
Description: "dummy",
},
func TestRunPipeMissingInfo(t *testing.T) {
for name, snap := range map[string]config.Snapcraft{
"missing summary": {
Description: "dummy desc",
},
}
assert.NoError(Pipe{}.Run(ctx))
}
func TestRunPipeNoDescription(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Snapcraft: config.Snapcraft{
Summary: "dummy",
},
"missing description": {
Summary: "dummy summary",
},
} {
t.Run(name, func(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{
Snapcraft: snap,
},
}
// FIXME: there is no way to tell here if the pipe actually ran
// or if it was indeed skipped.
assert.NoError(Pipe{}.Run(ctx))
})
}
assert.NoError(Pipe{}.Run(ctx))
}
func TestRunPipe(t *testing.T) {
@ -45,9 +44,6 @@ func TestRunPipe(t *testing.T) {
assert.NoError(err)
var dist = filepath.Join(folder, "dist")
assert.NoError(os.Mkdir(dist, 0755))
assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755))
var binPath = filepath.Join(dist, "mybin", "mybin")
_, err = os.Create(binPath)
assert.NoError(err)
var ctx = &context.Context{
Version: "testversion",
@ -60,8 +56,12 @@ func TestRunPipe(t *testing.T) {
},
},
}
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
ctx.AddBinary(plat, "mybin", "mybin", binPath)
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64", "linuxarm64", "linuxarmhf"} {
var folder = "mybin_" + plat
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755))
var binPath = filepath.Join(dist, folder, "mybin")
_, err = os.Create(binPath)
ctx.AddBinary(plat, folder, "mybin", binPath)
}
assert.NoError(Pipe{}.Run(ctx))
}