mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-23 21:19:17 +02:00
Merge pull request #321 from goreleaser/improvements
small improvements
This commit is contained in:
commit
8a0936f8cd
@ -179,11 +179,11 @@ func LoadReader(fd io.Reader) (config Project, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return config, err
|
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")
|
log.WithField("config", config).Debug("loaded config file")
|
||||||
|
return config, checkOverflows(config)
|
||||||
err = checkOverflows(config)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkOverflows(config Project) error {
|
func checkOverflows(config Project) error {
|
||||||
|
@ -60,3 +60,9 @@ func TestInvalidFields(t *testing.T) {
|
|||||||
_, err := Load("testdata/invalid_config.yml")
|
_, 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")
|
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
1
config/testdata/invalid.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
this_is_not_valid: [
|
@ -3,6 +3,7 @@ package snapcraft
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -51,7 +52,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
log.Error("no snapcraft summary defined, skipping")
|
log.Error("no snapcraft summary defined, skipping")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ctx.Config.Snapcraft.Summary == "" {
|
if ctx.Config.Snapcraft.Description == "" {
|
||||||
log.Error("no snapcraft description defined, skipping")
|
log.Error("no snapcraft description defined, skipping")
|
||||||
return nil
|
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}
|
metadata.Apps[binary.Name] = AppsMetadata{Command: binary.Name}
|
||||||
|
|
||||||
destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path))
|
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)
|
out, err := yaml.Marshal(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -131,12 +134,14 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
snap := metadata.Name + "_" + metadata.Version + "_" + arch + ".snap"
|
snap := filepath.Join(
|
||||||
cmd := exec.Command("snapcraft", "snap", "prime", "--output", snap)
|
ctx.Config.Dist,
|
||||||
cmd.Dir = folderDir
|
metadata.Name+"_"+metadata.Version+"_"+arch+".snap",
|
||||||
|
)
|
||||||
|
cmd := exec.Command("snapcraft", "snap", primeDir, "--output", snap)
|
||||||
if out, err = cmd.CombinedOutput(); err != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,28 +15,27 @@ func TestDescription(t *testing.T) {
|
|||||||
assert.NotEmpty(t, Pipe{}.Description())
|
assert.NotEmpty(t, Pipe{}.Description())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeNoSummary(t *testing.T) {
|
func TestRunPipeMissingInfo(t *testing.T) {
|
||||||
|
for name, snap := range map[string]config.Snapcraft{
|
||||||
|
"missing summary": {
|
||||||
|
Description: "dummy desc",
|
||||||
|
},
|
||||||
|
"missing description": {
|
||||||
|
Summary: "dummy summary",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
var assert = assert.New(t)
|
var assert = assert.New(t)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
Snapcraft: config.Snapcraft{
|
Snapcraft: snap,
|
||||||
Description: "dummy",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// 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 TestRunPipeNoDescription(t *testing.T) {
|
|
||||||
var assert = assert.New(t)
|
|
||||||
var ctx = &context.Context{
|
|
||||||
Config: config.Project{
|
|
||||||
Snapcraft: config.Snapcraft{
|
|
||||||
Summary: "dummy",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
assert.NoError(Pipe{}.Run(ctx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe(t *testing.T) {
|
func TestRunPipe(t *testing.T) {
|
||||||
@ -45,9 +44,6 @@ func TestRunPipe(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
var dist = filepath.Join(folder, "dist")
|
var dist = filepath.Join(folder, "dist")
|
||||||
assert.NoError(os.Mkdir(dist, 0755))
|
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)
|
assert.NoError(err)
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Version: "testversion",
|
Version: "testversion",
|
||||||
@ -60,8 +56,12 @@ func TestRunPipe(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64"} {
|
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64", "linuxarm64", "linuxarmhf"} {
|
||||||
ctx.AddBinary(plat, "mybin", "mybin", binPath)
|
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))
|
assert.NoError(Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user