mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
Allow plugs and daemon to the snaps
This commit is contained in:
parent
8a0936f8cd
commit
0591ab4538
@ -123,12 +123,19 @@ type FPM struct {
|
||||
XXX map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
// AppsMetadata for the binaries that will be in the snap package
|
||||
type SnapcraftAppMetadata struct {
|
||||
Plugs []string
|
||||
Daemon string
|
||||
}
|
||||
|
||||
// Snapcraft config
|
||||
type Snapcraft struct {
|
||||
Summary string `yaml:",omitempty"`
|
||||
Description string `yaml:",omitempty"`
|
||||
Grade string `yaml:",omitempty"`
|
||||
Confinement string `yaml:",omitempty"`
|
||||
Summary string `yaml:",omitempty"`
|
||||
Description string `yaml:",omitempty"`
|
||||
Grade string `yaml:",omitempty"`
|
||||
Confinement string `yaml:",omitempty"`
|
||||
Apps map[string]SnapcraftAppMetadata `yaml:",omitempty"`
|
||||
|
||||
// Capture all undefined fields and should be empty after loading
|
||||
XXX map[string]interface{} `yaml:",inline"`
|
||||
|
@ -28,14 +28,14 @@ type SnapcraftMetadata struct {
|
||||
Grade string `yaml:",omitempty"`
|
||||
Confinement string `yaml:",omitempty"`
|
||||
Architectures []string
|
||||
Apps map[string]AppsMetadata
|
||||
Apps map[string]AppMetadata
|
||||
}
|
||||
|
||||
// AppsMetadata for the binaries that will be in the snap package
|
||||
type AppsMetadata struct {
|
||||
// AppMetadata for the binaries that will be in the snap package
|
||||
type AppMetadata struct {
|
||||
Command string
|
||||
// Plugs []string
|
||||
// Daemon string
|
||||
Plugs []string `yaml:",omitempty"`
|
||||
Daemon string `yaml:",omitempty"`
|
||||
}
|
||||
|
||||
// Pipe for snapcraft packaging
|
||||
@ -111,14 +111,19 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
||||
Grade: ctx.Config.Snapcraft.Grade,
|
||||
Confinement: ctx.Config.Snapcraft.Confinement,
|
||||
Architectures: []string{arch},
|
||||
Apps: make(map[string]AppsMetadata),
|
||||
Apps: make(map[string]AppMetadata),
|
||||
}
|
||||
|
||||
for _, binary := range binaries {
|
||||
log.WithField("path", binary.Path).
|
||||
WithField("name", binary.Name).
|
||||
Info("passed binary to snapcraft")
|
||||
metadata.Apps[binary.Name] = AppsMetadata{Command: binary.Name}
|
||||
appMetadata := AppMetadata{Command: binary.Name}
|
||||
if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok {
|
||||
appMetadata.Plugs = configAppMetadata.Plugs
|
||||
appMetadata.Daemon = configAppMetadata.Daemon
|
||||
}
|
||||
metadata.Apps[binary.Name] = appMetadata
|
||||
|
||||
destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path))
|
||||
if err := os.Link(binary.Path, destBinaryPath); err != nil {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/stretchr/testify/assert"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
@ -66,6 +67,47 @@ func TestRunPipe(t *testing.T) {
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunPipeWithPlugsAndDaemon(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: "mybin",
|
||||
Dist: dist,
|
||||
Snapcraft: config.Snapcraft{
|
||||
Summary: "test summary",
|
||||
Description: "test description",
|
||||
Apps: map[string]config.SnapcraftAppMetadata{
|
||||
"mybin": config.SnapcraftAppMetadata{
|
||||
Plugs: []string{"home", "network"},
|
||||
Daemon: "simple",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
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))
|
||||
yamlFile, err := ioutil.ReadFile(filepath.Join(dist, "mybin_linuxamd64", "prime", "meta", "snap.yaml"))
|
||||
assert.NoError(err)
|
||||
var snapcraftMetadata SnapcraftMetadata
|
||||
err = yaml.Unmarshal(yamlFile, &snapcraftMetadata)
|
||||
assert.NoError(err)
|
||||
assert.Equal(snapcraftMetadata.Apps["mybin"].Plugs, []string{"home", "network"})
|
||||
assert.Equal(snapcraftMetadata.Apps["mybin"].Daemon, "simple")
|
||||
}
|
||||
|
||||
func TestNoSnapcraftInPath(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var path = os.Getenv("PATH")
|
||||
|
Loading…
Reference in New Issue
Block a user