2017-07-27 00:30:48 +00:00
|
|
|
// Package snapcraft implements the Pipe interface providing Snapcraft bindings.
|
|
|
|
package snapcraft
|
|
|
|
|
|
|
|
import (
|
2020-09-21 14:47:51 -03:00
|
|
|
"errors"
|
2017-08-02 09:06:28 -03:00
|
|
|
"fmt"
|
2017-07-28 01:05:43 +00:00
|
|
|
"os"
|
2017-07-27 00:30:48 +00:00
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2018-06-24 21:12:53 -03:00
|
|
|
"strings"
|
2017-12-17 17:25:04 -02:00
|
|
|
|
2017-07-27 00:30:48 +00:00
|
|
|
"github.com/apex/log"
|
2019-12-27 17:31:03 -03:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
|
2017-12-18 09:00:19 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2021-07-24 19:59:43 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/gio"
|
2019-05-29 09:13:52 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/ids"
|
2018-09-12 14:18:01 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
2018-07-09 22:08:22 -07:00
|
|
|
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
2018-07-08 20:47:30 -07:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2019-05-27 12:47:05 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2017-07-27 00:30:48 +00:00
|
|
|
)
|
|
|
|
|
2021-07-24 05:23:59 +02:00
|
|
|
const releasesExtra = "releases"
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// ErrNoSnapcraft is shown when snapcraft cannot be found in $PATH.
|
2017-07-27 00:30:48 +00:00
|
|
|
var ErrNoSnapcraft = errors.New("snapcraft not present in $PATH")
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// ErrNoDescription is shown when no description provided.
|
2017-08-17 18:41:08 -03:00
|
|
|
var ErrNoDescription = errors.New("no description provided for snapcraft")
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// ErrNoSummary is shown when no summary provided.
|
2017-08-17 18:41:08 -03:00
|
|
|
var ErrNoSummary = errors.New("no summary provided for snapcraft")
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Metadata to generate the snap package.
|
2017-09-14 21:19:56 -03:00
|
|
|
type Metadata struct {
|
2017-07-27 00:30:48 +00:00
|
|
|
Name string
|
|
|
|
Version string
|
|
|
|
Summary string
|
|
|
|
Description string
|
2019-04-18 23:21:40 +03:00
|
|
|
Base string `yaml:",omitempty"`
|
2019-04-17 23:26:30 +03:00
|
|
|
License string `yaml:",omitempty"`
|
2017-07-27 00:30:48 +00:00
|
|
|
Grade string `yaml:",omitempty"`
|
|
|
|
Confinement string `yaml:",omitempty"`
|
|
|
|
Architectures []string
|
2021-03-17 21:18:56 +08:00
|
|
|
Layout map[string]LayoutMetadata `yaml:",omitempty"`
|
2017-08-04 05:42:55 +00:00
|
|
|
Apps map[string]AppMetadata
|
2019-03-14 09:56:11 -03:00
|
|
|
Plugs map[string]interface{} `yaml:",omitempty"`
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// AppMetadata for the binaries that will be in the snap package.
|
2017-08-04 05:42:55 +00:00
|
|
|
type AppMetadata struct {
|
2020-10-06 10:59:53 -03:00
|
|
|
Command string
|
|
|
|
Plugs []string `yaml:",omitempty"`
|
|
|
|
Daemon string `yaml:",omitempty"`
|
|
|
|
Completer string `yaml:",omitempty"`
|
|
|
|
RestartCondition string `yaml:"restart-condition,omitempty"`
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 21:18:56 +08:00
|
|
|
type LayoutMetadata struct {
|
|
|
|
Symlink string `yaml:",omitempty"`
|
|
|
|
Bind string `yaml:",omitempty"`
|
|
|
|
BindFile string `yaml:"bind-file,omitempty"`
|
|
|
|
Type string `yaml:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:08:18 -03:00
|
|
|
const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}"
|
2017-12-26 21:44:11 -02:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Pipe for snapcraft packaging.
|
2017-07-27 00:30:48 +00:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) String() string { return "snapcraft packages" }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Snapcrafts) == 0 }
|
2017-07-27 00:30:48 +00:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Default sets the pipe defaults.
|
2017-12-26 21:44:11 -02:00
|
|
|
func (Pipe) Default(ctx *context.Context) error {
|
2021-04-25 14:20:49 -03:00
|
|
|
ids := ids.New("snapcrafts")
|
2019-05-27 12:47:05 -03:00
|
|
|
for i := range ctx.Config.Snapcrafts {
|
2021-04-25 14:20:49 -03:00
|
|
|
snap := &ctx.Config.Snapcrafts[i]
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.NameTemplate == "" {
|
|
|
|
snap.NameTemplate = defaultNameTemplate
|
|
|
|
}
|
2021-07-24 05:23:59 +02:00
|
|
|
if len(snap.ChannelTemplates) == 0 {
|
|
|
|
switch snap.Grade {
|
|
|
|
case "devel":
|
|
|
|
snap.ChannelTemplates = []string{"edge", "beta"}
|
|
|
|
default:
|
|
|
|
snap.ChannelTemplates = []string{"edge", "beta", "candidate", "stable"}
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 12:47:05 -03:00
|
|
|
if len(snap.Builds) == 0 {
|
|
|
|
for _, b := range ctx.Config.Builds {
|
|
|
|
snap.Builds = append(snap.Builds, b.ID)
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 09:13:52 -03:00
|
|
|
ids.Inc(snap.ID)
|
2017-12-26 21:44:11 -02:00
|
|
|
}
|
2019-05-29 09:13:52 -03:00
|
|
|
return ids.Validate()
|
2017-12-26 21:44:11 -02:00
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Run the pipe.
|
2017-07-27 00:30:48 +00:00
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
2019-05-27 12:47:05 -03:00
|
|
|
for _, snap := range ctx.Config.Snapcrafts {
|
|
|
|
// TODO: deal with pipe.skip?
|
|
|
|
if err := doRun(ctx, snap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func doRun(ctx *context.Context, snap config.Snapcraft) error {
|
|
|
|
if snap.Summary == "" && snap.Description == "" {
|
2018-09-12 14:18:01 -03:00
|
|
|
return pipe.Skip("no summary nor description were provided")
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.Summary == "" {
|
2017-08-17 18:41:08 -03:00
|
|
|
return ErrNoSummary
|
|
|
|
}
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.Description == "" {
|
2017-08-17 18:41:08 -03:00
|
|
|
return ErrNoDescription
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
|
|
|
_, err := exec.LookPath("snapcraft")
|
|
|
|
if err != nil {
|
|
|
|
return ErrNoSnapcraft
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:20:49 -03:00
|
|
|
g := semerrgroup.New(ctx.Parallelism)
|
2017-12-17 17:25:04 -02:00
|
|
|
for platform, binaries := range ctx.Artifacts.Filter(
|
|
|
|
artifact.And(
|
|
|
|
artifact.ByGoos("linux"),
|
|
|
|
artifact.ByType(artifact.Binary),
|
2019-05-27 12:47:05 -03:00
|
|
|
artifact.ByIDs(snap.Builds...),
|
2017-12-17 17:25:04 -02:00
|
|
|
),
|
|
|
|
).GroupByPlatform() {
|
2021-11-13 22:23:11 -03:00
|
|
|
arch := linuxArch(platform)
|
2020-02-05 22:08:18 -03:00
|
|
|
if !isValidArch(arch) {
|
2018-06-20 09:39:10 -03:00
|
|
|
log.WithField("arch", arch).Warn("ignored unsupported arch")
|
|
|
|
continue
|
|
|
|
}
|
2017-12-17 17:25:04 -02:00
|
|
|
binaries := binaries
|
|
|
|
g.Go(func() error {
|
2019-05-27 12:47:05 -03:00
|
|
|
return create(ctx, snap, arch, binaries)
|
2017-12-17 17:25:04 -02:00
|
|
|
})
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
|
|
|
return g.Wait()
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:08:18 -03:00
|
|
|
func isValidArch(arch string) bool {
|
|
|
|
// https://snapcraft.io/docs/architectures
|
|
|
|
for _, a := range []string{"s390x", "ppc64el", "arm64", "armhf", "amd64", "i386"} {
|
|
|
|
if arch == a {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Publish packages.
|
2018-10-20 14:25:46 -03:00
|
|
|
func (Pipe) Publish(ctx *context.Context) error {
|
2020-03-04 01:14:40 -03:00
|
|
|
if ctx.SkipPublish {
|
|
|
|
return pipe.ErrSkipPublishEnabled
|
|
|
|
}
|
2018-10-20 14:25:46 -03:00
|
|
|
snaps := ctx.Artifacts.Filter(artifact.ByType(artifact.PublishableSnapcraft)).List()
|
2021-04-25 14:20:49 -03:00
|
|
|
g := semerrgroup.New(ctx.Parallelism)
|
2018-10-20 14:25:46 -03:00
|
|
|
for _, snap := range snaps {
|
|
|
|
snap := snap
|
|
|
|
g.Go(func() error {
|
2018-10-20 14:26:49 -03:00
|
|
|
return push(ctx, snap)
|
2018-10-20 14:25:46 -03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return g.Wait()
|
|
|
|
}
|
|
|
|
|
2019-08-12 17:44:48 -03:00
|
|
|
func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries []*artifact.Artifact) error {
|
2021-04-25 14:20:49 -03:00
|
|
|
log := log.WithField("arch", arch)
|
2018-07-08 20:47:30 -07:00
|
|
|
folder, err := tmpl.New(ctx).
|
2019-05-27 12:47:05 -03:00
|
|
|
WithArtifact(binaries[0], snap.Replacements).
|
|
|
|
Apply(snap.NameTemplate)
|
2017-12-17 17:25:04 -02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-26 07:23:08 -08:00
|
|
|
|
2021-07-24 05:23:59 +02:00
|
|
|
channels, err := processChannelsTemplates(ctx, snap)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-07-28 01:05:43 +00:00
|
|
|
// prime is the directory that then will be compressed to make the .snap package.
|
2021-04-25 14:20:49 -03:00
|
|
|
folderDir := filepath.Join(ctx.Config.Dist, folder)
|
|
|
|
primeDir := filepath.Join(folderDir, "prime")
|
|
|
|
metaDir := filepath.Join(primeDir, "meta")
|
2017-11-26 12:09:12 -02:00
|
|
|
// #nosec
|
2021-04-25 14:20:49 -03:00
|
|
|
if err = os.MkdirAll(metaDir, 0o755); err != nil {
|
2017-07-28 01:05:43 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-06 21:07:18 +03:00
|
|
|
for _, file := range snap.Files {
|
|
|
|
if file.Destination == "" {
|
|
|
|
file.Destination = file.Source
|
|
|
|
}
|
|
|
|
if file.Mode == 0 {
|
2021-04-25 14:20:49 -03:00
|
|
|
file.Mode = 0o644
|
2020-06-06 21:07:18 +03:00
|
|
|
}
|
2021-07-24 05:23:59 +02:00
|
|
|
destinationDir := filepath.Join(primeDir, filepath.Dir(file.Destination))
|
|
|
|
if err := os.MkdirAll(destinationDir, 0o755); err != nil {
|
|
|
|
return fmt.Errorf("failed to create directory '%s': %w", destinationDir, err)
|
2020-06-06 21:07:18 +03:00
|
|
|
}
|
2021-07-24 19:59:43 -03:00
|
|
|
if err := gio.CopyWithMode(file.Source, filepath.Join(primeDir, file.Destination), os.FileMode(file.Mode)); err != nil {
|
2020-09-21 14:47:51 -03:00
|
|
|
return fmt.Errorf("failed to link extra file '%s': %w", file.Source, err)
|
2020-06-06 21:07:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:20:49 -03:00
|
|
|
file := filepath.Join(primeDir, "meta", "snap.yaml")
|
2018-10-26 16:31:06 -06:00
|
|
|
log.WithField("file", file).Debug("creating snap metadata")
|
2017-07-27 00:30:48 +00:00
|
|
|
|
2021-04-25 14:20:49 -03:00
|
|
|
metadata := &Metadata{
|
2017-07-27 00:30:48 +00:00
|
|
|
Version: ctx.Version,
|
2019-05-27 12:47:05 -03:00
|
|
|
Summary: snap.Summary,
|
|
|
|
Description: snap.Description,
|
|
|
|
Grade: snap.Grade,
|
|
|
|
Confinement: snap.Confinement,
|
2017-07-27 00:30:48 +00:00
|
|
|
Architectures: []string{arch},
|
2021-03-17 21:18:56 +08:00
|
|
|
Layout: map[string]LayoutMetadata{},
|
2018-12-12 18:24:22 -02:00
|
|
|
Apps: map[string]AppMetadata{},
|
2017-07-27 00:30:48 +00:00
|
|
|
}
|
2018-02-16 10:35:44 -02:00
|
|
|
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.Base != "" {
|
|
|
|
metadata.Base = snap.Base
|
2019-04-18 23:21:40 +03:00
|
|
|
}
|
|
|
|
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.License != "" {
|
|
|
|
metadata.License = snap.License
|
2019-04-17 23:26:30 +03:00
|
|
|
}
|
|
|
|
|
2018-02-16 10:35:44 -02:00
|
|
|
metadata.Name = ctx.Config.ProjectName
|
2019-05-27 12:47:05 -03:00
|
|
|
if snap.Name != "" {
|
|
|
|
metadata.Name = snap.Name
|
2017-08-07 16:28:04 +00:00
|
|
|
}
|
2017-07-27 00:30:48 +00:00
|
|
|
|
2021-03-17 21:18:56 +08:00
|
|
|
for targetPath, layout := range snap.Layout {
|
|
|
|
metadata.Layout[targetPath] = LayoutMetadata{
|
|
|
|
Symlink: layout.Symlink,
|
|
|
|
Bind: layout.Bind,
|
|
|
|
BindFile: layout.BindFile,
|
|
|
|
Type: layout.Type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-26 07:23:08 -08:00
|
|
|
// if the user didn't specify any apps then
|
|
|
|
// default to the main binary being the command:
|
|
|
|
if len(snap.Apps) == 0 {
|
2021-04-25 14:20:49 -03:00
|
|
|
name := snap.Name
|
2020-01-30 10:57:07 -03:00
|
|
|
if name == "" {
|
2021-06-26 16:57:10 +00:00
|
|
|
name = filepath.Base(binaries[0].Name)
|
2017-08-20 16:35:46 -03:00
|
|
|
}
|
2020-01-30 10:57:07 -03:00
|
|
|
metadata.Apps[name] = AppMetadata{
|
2021-06-26 16:57:10 +00:00
|
|
|
Command: filepath.Base(filepath.Base(binaries[0].Name)),
|
2017-08-04 05:42:55 +00:00
|
|
|
}
|
2020-01-26 07:23:08 -08:00
|
|
|
}
|
2017-07-28 01:05:43 +00:00
|
|
|
|
2020-01-26 07:23:08 -08:00
|
|
|
for _, binary := range binaries {
|
|
|
|
// build the binaries and link resources
|
2017-07-28 01:05:43 +00:00
|
|
|
destBinaryPath := filepath.Join(primeDir, filepath.Base(binary.Path))
|
2018-12-13 10:09:36 -02:00
|
|
|
log.WithField("src", binary.Path).
|
|
|
|
WithField("dst", destBinaryPath).
|
2021-07-24 19:59:43 -03:00
|
|
|
Debug("copying")
|
2020-01-26 07:23:08 -08:00
|
|
|
|
2021-07-24 19:59:43 -03:00
|
|
|
if err = gio.CopyWithMode(binary.Path, destBinaryPath, 0o555); err != nil {
|
|
|
|
return fmt.Errorf("failed to copy binary: %w", err)
|
2018-12-12 18:32:22 -02:00
|
|
|
}
|
2020-07-20 10:36:09 -03:00
|
|
|
}
|
2019-06-23 03:37:55 +02:00
|
|
|
|
2020-07-20 10:36:09 -03:00
|
|
|
// setup the apps: directive for each binary
|
|
|
|
for name, config := range snap.Apps {
|
|
|
|
command := name
|
|
|
|
if config.Command != "" {
|
|
|
|
command = config.Command
|
|
|
|
}
|
2020-01-26 07:23:08 -08:00
|
|
|
|
2020-07-20 10:36:09 -03:00
|
|
|
// TODO: test that the correct binary is used in Command
|
|
|
|
// See https://github.com/goreleaser/goreleaser/pull/1449
|
|
|
|
appMetadata := AppMetadata{
|
|
|
|
Command: strings.TrimSpace(strings.Join([]string{
|
|
|
|
command,
|
|
|
|
config.Args,
|
|
|
|
}, " ")),
|
2020-10-06 10:59:53 -03:00
|
|
|
Plugs: config.Plugs,
|
|
|
|
Daemon: config.Daemon,
|
|
|
|
RestartCondition: config.RestartCondition,
|
2020-07-20 10:36:09 -03:00
|
|
|
}
|
2020-06-06 21:07:18 +03:00
|
|
|
|
2020-07-20 10:36:09 -03:00
|
|
|
if config.Completer != "" {
|
|
|
|
destCompleterPath := filepath.Join(primeDir, config.Completer)
|
2021-04-25 14:20:49 -03:00
|
|
|
if err := os.MkdirAll(filepath.Dir(destCompleterPath), 0o755); err != nil {
|
2020-09-21 14:47:51 -03:00
|
|
|
return fmt.Errorf("failed to create folder: %w", err)
|
2020-01-30 10:57:07 -03:00
|
|
|
}
|
2020-07-20 10:36:09 -03:00
|
|
|
log.WithField("src", config.Completer).
|
|
|
|
WithField("dst", destCompleterPath).
|
2021-07-24 05:23:59 +02:00
|
|
|
Debug("copy")
|
|
|
|
|
2021-07-24 19:59:43 -03:00
|
|
|
if err := gio.CopyWithMode(config.Completer, destCompleterPath, 0o644); err != nil {
|
2021-07-24 05:23:59 +02:00
|
|
|
return fmt.Errorf("failed to copy completer: %w", err)
|
2020-07-20 10:36:09 -03:00
|
|
|
}
|
2021-07-24 05:23:59 +02:00
|
|
|
|
2020-07-20 10:36:09 -03:00
|
|
|
appMetadata.Completer = config.Completer
|
2020-01-26 07:23:08 -08:00
|
|
|
}
|
2020-07-20 10:36:09 -03:00
|
|
|
|
|
|
|
metadata.Apps[name] = appMetadata
|
|
|
|
metadata.Plugs = snap.Plugs
|
2018-08-15 15:38:42 +03:00
|
|
|
}
|
|
|
|
|
2017-07-27 00:30:48 +00:00
|
|
|
out, err := yaml.Marshal(metadata)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-03-19 21:45:08 -03:00
|
|
|
log.WithField("file", file).Debugf("writing metadata file")
|
2021-04-25 14:20:49 -03:00
|
|
|
if err = os.WriteFile(file, out, 0o644); err != nil { //nolint: gosec
|
2017-07-27 00:30:48 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:20:49 -03:00
|
|
|
snapFile := filepath.Join(ctx.Config.Dist, folder+".snap")
|
2019-05-27 12:47:05 -03:00
|
|
|
log.WithField("snap", snapFile).Info("creating")
|
2017-11-26 12:09:12 -02:00
|
|
|
/* #nosec */
|
2021-04-25 14:20:49 -03:00
|
|
|
cmd := exec.CommandContext(ctx, "snapcraft", "pack", primeDir, "--output", snapFile)
|
2017-07-27 03:43:53 +00:00
|
|
|
if out, err = cmd.CombinedOutput(); err != nil {
|
2021-07-24 21:32:04 -03:00
|
|
|
return fmt.Errorf("failed to generate snap package: %w: %s", err, string(out))
|
2017-07-27 03:43:53 +00:00
|
|
|
}
|
2019-05-27 12:47:05 -03:00
|
|
|
if !snap.Publish {
|
2018-10-20 15:13:31 -03:00
|
|
|
return nil
|
|
|
|
}
|
2019-08-12 17:44:48 -03:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2018-10-20 14:25:46 -03:00
|
|
|
Type: artifact.PublishableSnapcraft,
|
2017-12-17 17:25:04 -02:00
|
|
|
Name: folder + ".snap",
|
2019-05-27 12:47:05 -03:00
|
|
|
Path: snapFile,
|
2017-12-17 17:25:04 -02:00
|
|
|
Goos: binaries[0].Goos,
|
|
|
|
Goarch: binaries[0].Goarch,
|
|
|
|
Goarm: binaries[0].Goarm,
|
2021-07-24 05:23:59 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
releasesExtra: channels,
|
|
|
|
},
|
2017-12-17 17:25:04 -02:00
|
|
|
})
|
2017-07-27 00:30:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-10-20 14:26:49 -03:00
|
|
|
|
2021-05-21 02:53:22 +00:00
|
|
|
const (
|
|
|
|
reviewWaitMsg = `Waiting for previous upload(s) to complete their review process.`
|
|
|
|
humanReviewMsg = `A human will soon review your snap`
|
2021-05-26 14:39:11 +00:00
|
|
|
needsReviewMsg = `(NEEDS REVIEW)`
|
2021-05-21 02:53:22 +00:00
|
|
|
)
|
2019-07-20 18:31:04 -03:00
|
|
|
|
2019-08-12 17:44:48 -03:00
|
|
|
func push(ctx *context.Context, snap *artifact.Artifact) error {
|
2021-04-25 14:20:49 -03:00
|
|
|
log := log.WithField("snap", snap.Name)
|
2021-07-24 05:23:59 +02:00
|
|
|
releases := snap.Extra[releasesExtra].([]string)
|
2018-10-20 15:16:14 -03:00
|
|
|
/* #nosec */
|
2021-07-24 05:23:59 +02:00
|
|
|
cmd := exec.CommandContext(ctx, "snapcraft", "upload", "--release="+strings.Join(releases, ","), snap.Path)
|
|
|
|
log.WithField("args", cmd.Args).Info("pushing snap")
|
2018-10-20 14:26:49 -03:00
|
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
2021-05-26 14:39:11 +00:00
|
|
|
if strings.Contains(string(out), reviewWaitMsg) || strings.Contains(string(out), humanReviewMsg) || strings.Contains(string(out), needsReviewMsg) {
|
2019-07-20 18:31:04 -03:00
|
|
|
log.Warn(reviewWaitMsg)
|
|
|
|
} else {
|
2021-07-24 21:32:04 -03:00
|
|
|
return fmt.Errorf("failed to push %s package: %w: %s", snap.Path, err, string(out))
|
2019-07-20 18:31:04 -03:00
|
|
|
}
|
2018-10-20 14:26:49 -03:00
|
|
|
}
|
|
|
|
snap.Type = artifact.Snapcraft
|
|
|
|
ctx.Artifacts.Add(snap)
|
|
|
|
return nil
|
|
|
|
}
|
2020-06-06 21:07:18 +03:00
|
|
|
|
2021-07-24 05:23:59 +02:00
|
|
|
func processChannelsTemplates(ctx *context.Context, snap config.Snapcraft) ([]string, error) {
|
|
|
|
// nolint:prealloc
|
|
|
|
var channels []string
|
|
|
|
for _, channeltemplate := range snap.ChannelTemplates {
|
|
|
|
channel, err := tmpl.New(ctx).Apply(channeltemplate)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to execute channel template '%s': %w", err, err)
|
|
|
|
}
|
|
|
|
if channel == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
channels = append(channels, channel)
|
|
|
|
}
|
|
|
|
|
|
|
|
return channels, nil
|
|
|
|
}
|
2021-11-13 22:23:11 -03:00
|
|
|
|
|
|
|
var archToSnap = map[string]string{
|
|
|
|
"386": "i386",
|
|
|
|
"arm": "armhf",
|
|
|
|
"arm6": "armhf",
|
|
|
|
"arm7": "armhf",
|
|
|
|
"ppc64le": "ppc64el",
|
|
|
|
}
|
|
|
|
|
|
|
|
func linuxArch(key string) string {
|
|
|
|
// XXX: list of all linux arches: `go tool dist list | grep linux`
|
|
|
|
arch := strings.TrimPrefix(key, "linux")
|
|
|
|
for _, suffix := range []string{"hardfloat", "softfloat"} {
|
|
|
|
arch = strings.TrimSuffix(arch, suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
if got, ok := archToSnap[arch]; ok {
|
|
|
|
return got
|
|
|
|
}
|
|
|
|
|
|
|
|
return arch
|
|
|
|
}
|