mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
allow to overwrite the snap name
This commit is contained in:
parent
d856c0f9db
commit
58ab671b57
@ -470,6 +470,9 @@ You can read more about it in the [snapcraft docs](https://snapcraft.io/docs/).
|
||||
# .goreleaser.yml
|
||||
snapcraft:
|
||||
|
||||
# The name of the snap. This is optional and defaults to the project name.
|
||||
name: drumroll
|
||||
|
||||
# Single-line elevator pitch for your amazing snap.
|
||||
# 79 char long at most.
|
||||
summary: Software to create fast and easy drum rolls.
|
||||
|
@ -131,6 +131,7 @@ type SnapcraftAppMetadata struct {
|
||||
|
||||
// Snapcraft config
|
||||
type Snapcraft struct {
|
||||
Name string `yaml:",omitempty"`
|
||||
Summary string `yaml:",omitempty"`
|
||||
Description string `yaml:",omitempty"`
|
||||
Grade string `yaml:",omitempty"`
|
||||
|
@ -104,7 +104,6 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
||||
log.WithField("file", file).Info("creating snap metadata")
|
||||
|
||||
var metadata = &SnapcraftMetadata{
|
||||
Name: ctx.Config.ProjectName,
|
||||
Version: ctx.Version,
|
||||
Summary: ctx.Config.Snapcraft.Summary,
|
||||
Description: ctx.Config.Snapcraft.Description,
|
||||
@ -113,6 +112,11 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
||||
Architectures: []string{arch},
|
||||
Apps: make(map[string]AppMetadata),
|
||||
}
|
||||
if ctx.Config.Snapcraft.Name != "" {
|
||||
metadata.Name = ctx.Config.Snapcraft.Name
|
||||
} else {
|
||||
metadata.Name = ctx.Config.ProjectName
|
||||
}
|
||||
|
||||
for _, binary := range binaries {
|
||||
log.WithField("path", binary.Path).
|
||||
@ -141,7 +145,7 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
||||
|
||||
snap := filepath.Join(
|
||||
ctx.Config.Dist,
|
||||
metadata.Name+"_"+metadata.Version+"_"+arch+".snap",
|
||||
ctx.Config.ProjectName+"_"+metadata.Version+"_"+arch+".snap",
|
||||
)
|
||||
cmd := exec.Command("snapcraft", "snap", primeDir, "--output", snap)
|
||||
if out, err = cmd.CombinedOutput(); err != nil {
|
||||
|
@ -67,6 +67,41 @@ func TestRunPipe(t *testing.T) {
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeWithName(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
assert.NoError(err)
|
||||
var dist = filepath.Join(folder, "dist")
|
||||
assert.NoError(os.Mkdir(dist, 0755))
|
||||
assert.NoError(err)
|
||||
var ctx = &context.Context{
|
||||
Version: "testversion",
|
||||
Config: config.Project{
|
||||
ProjectName: "testprojectname",
|
||||
Dist: dist,
|
||||
Snapcraft: config.Snapcraft{
|
||||
Name: "testsnapname",
|
||||
Summary: "test summary",
|
||||
Description: "test description",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, plat := range []string{"linuxamd64", "linux386", "darwinamd64", "linuxarm64", "linuxarmhf"} {
|
||||
var folder = "testprojectname_" + plat
|
||||
assert.NoError(os.Mkdir(filepath.Join(dist, folder), 0755))
|
||||
var binPath = filepath.Join(dist, folder, "testprojectname")
|
||||
_, err = os.Create(binPath)
|
||||
ctx.AddBinary(plat, folder, "testprojectname", binPath)
|
||||
}
|
||||
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)
|
||||
assert.NoError(err)
|
||||
assert.Equal(snapcraftMetadata.Name, "testsnapname")
|
||||
}
|
||||
|
||||
func TestRunPipeWithPlugsAndDaemon(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, err := ioutil.TempDir("", "archivetest")
|
||||
|
Loading…
Reference in New Issue
Block a user