mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
refactor: fixed sign and snap pipe
This commit is contained in:
parent
906c8b08e3
commit
24f186a63c
@ -48,6 +48,7 @@ func New(config config.Project) *Context {
|
||||
Config: config,
|
||||
Env: splitEnv(os.Environ()),
|
||||
Parallelism: 4,
|
||||
Artifacts: artifact.New(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,10 @@ const (
|
||||
LinuxPackage
|
||||
// DockerImage is a docker image
|
||||
DockerImage
|
||||
// Checksum is a checksum file
|
||||
// Checksum is a checksums file
|
||||
Checksum
|
||||
// Signature is a signature file
|
||||
Signature
|
||||
)
|
||||
|
||||
// Artifact represents an artifact and its relevant info
|
||||
|
@ -17,7 +17,6 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/archiveformat"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
||||
)
|
||||
|
||||
// Pipe for archive
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
)
|
||||
|
||||
@ -39,9 +40,14 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
switch ctx.Config.Sign.Artifacts {
|
||||
case "checksum":
|
||||
return sign(ctx, ctx.Checksums)
|
||||
return sign(ctx, ctx.Artifacts.Filter(artifact.ByType(artifact.Checksum)).List())
|
||||
case "all":
|
||||
return sign(ctx, ctx.Artifacts)
|
||||
return sign(ctx, ctx.Artifacts.Filter(
|
||||
artifact.Or(
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
artifact.ByType(artifact.UploadableBinary),
|
||||
artifact.ByType(artifact.LinuxPackage),
|
||||
)).List())
|
||||
case "none":
|
||||
return pipeline.Skip("artifact signing disabled")
|
||||
default:
|
||||
@ -49,7 +55,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
func sign(ctx *context.Context, artifacts []string) error {
|
||||
func sign(ctx *context.Context, artifacts []artifact.Artifact) error {
|
||||
var sigs []string
|
||||
for _, a := range artifacts {
|
||||
sig, err := signone(ctx, a)
|
||||
@ -59,17 +65,20 @@ func sign(ctx *context.Context, artifacts []string) error {
|
||||
sigs = append(sigs, sig)
|
||||
}
|
||||
for _, sig := range sigs {
|
||||
ctx.AddArtifact(sig)
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.Signature,
|
||||
Name: sig,
|
||||
Path: filepath.Join(ctx.Config.Dist, sig),
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func signone(ctx *context.Context, artifact string) (string, error) {
|
||||
func signone(ctx *context.Context, artifact artifact.Artifact) (string, error) {
|
||||
cfg := ctx.Config.Sign
|
||||
|
||||
artifact = filepath.Join(ctx.Config.Dist, artifact)
|
||||
env := map[string]string{
|
||||
"artifact": artifact,
|
||||
"artifact": artifact.Path,
|
||||
}
|
||||
env["signature"] = expand(cfg.Signature, env)
|
||||
|
||||
|
@ -8,7 +8,9 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
@ -70,23 +72,30 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
var g errgroup.Group
|
||||
for platform, groups := range ctx.Binaries {
|
||||
if !strings.Contains(platform, "linux") {
|
||||
log.WithField("platform", platform).Debug("skipped non-linux builds for snapcraft")
|
||||
continue
|
||||
}
|
||||
for platform, binaries := range ctx.Artifacts.Filter(
|
||||
artifact.And(
|
||||
artifact.ByGoos("linux"),
|
||||
artifact.ByType(artifact.Binary),
|
||||
),
|
||||
).GroupByPlatform() {
|
||||
// TODO: could use artifact.goarch here
|
||||
arch := linux.Arch(platform)
|
||||
for folder, binaries := range groups {
|
||||
binaries := binaries
|
||||
g.Go(func() error {
|
||||
return create(ctx, folder, arch, binaries)
|
||||
return create(ctx, arch, binaries)
|
||||
})
|
||||
}
|
||||
}
|
||||
return g.Wait()
|
||||
}
|
||||
|
||||
func create(ctx *context.Context, folder, arch string, binaries []context.Binary) error {
|
||||
func create(ctx *context.Context, arch string, binaries []artifact.Artifact) error {
|
||||
var log = log.WithField("arch", arch)
|
||||
// TODO: should add template support here probably... for now, let's use
|
||||
// archive's template
|
||||
folder, err := nametemplate.Apply(ctx, binaries[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// prime is the directory that then will be compressed to make the .snap package.
|
||||
var folderDir = filepath.Join(ctx.Config.Dist, folder)
|
||||
var primeDir = filepath.Join(folderDir, "prime")
|
||||
@ -147,6 +156,13 @@ func create(ctx *context.Context, folder, arch string, binaries []context.Binary
|
||||
if out, err = cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to generate snap package: %s", string(out))
|
||||
}
|
||||
ctx.AddArtifact(snap)
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.LinuxPackage,
|
||||
Name: folder + ".snap",
|
||||
Path: snap,
|
||||
Goos: binaries[0].Goos,
|
||||
Goarch: binaries[0].Goarch,
|
||||
Goarm: binaries[0].Goarm,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user