mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
refactor: move archiveformat code inside archive pipe
It was being used only in that pipe anyway.
This commit is contained in:
parent
1475343200
commit
3a1f737747
@ -1,20 +0,0 @@
|
|||||||
// Package archiveformat provides functions to get the format of given package
|
|
||||||
// based on the config
|
|
||||||
// TODO: this can be moved inside the archive pipe package
|
|
||||||
package archiveformat
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// For return the archive format, considering overrides and all that
|
|
||||||
func For(ctx *context.Context, platform string) string {
|
|
||||||
for _, override := range ctx.Config.Archive.FormatOverrides {
|
|
||||||
if strings.HasPrefix(platform, override.Goos) {
|
|
||||||
return override.Format
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ctx.Config.Archive.Format
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package archiveformat
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
|
||||||
"github.com/goreleaser/goreleaser/context"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFormatFor(t *testing.T) {
|
|
||||||
var ctx = &context.Context{
|
|
||||||
Config: config.Project{
|
|
||||||
Archive: config.Archive{
|
|
||||||
Format: "tar.gz",
|
|
||||||
FormatOverrides: []config.FormatOverride{
|
|
||||||
{
|
|
||||||
Goos: "windows",
|
|
||||||
Format: "zip",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
assert.Equal(t, "zip", For(ctx, "windowsamd64"))
|
|
||||||
assert.Equal(t, "tar.gz", For(ctx, "linux386"))
|
|
||||||
}
|
|
@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
"github.com/goreleaser/archive"
|
"github.com/goreleaser/archive"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
"github.com/goreleaser/goreleaser/internal/archiveformat"
|
|
||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
||||||
)
|
)
|
||||||
@ -67,7 +66,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
||||||
var format = archiveformat.For(ctx, artifacts[0].Goos)
|
var format = packageFormat(ctx, artifacts[0].Goos)
|
||||||
folder, err := nametemplate.Apply(ctx, artifacts[0], ctx.Config.ProjectName)
|
folder, err := nametemplate.Apply(ctx, artifacts[0], ctx.Config.ProjectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -140,3 +139,12 @@ func wrap(ctx *context.Context, name, folder string) string {
|
|||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func packageFormat(ctx *context.Context, platform string) string {
|
||||||
|
for _, override := range ctx.Config.Archive.FormatOverrides {
|
||||||
|
if strings.HasPrefix(platform, override.Goos) {
|
||||||
|
return override.Format
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ctx.Config.Archive.Format
|
||||||
|
}
|
||||||
|
@ -284,3 +284,21 @@ func TestDefaultSet(t *testing.T) {
|
|||||||
assert.Equal(t, "zip", ctx.Config.Archive.Format)
|
assert.Equal(t, "zip", ctx.Config.Archive.Format)
|
||||||
assert.Equal(t, "foo", ctx.Config.Archive.Files[0])
|
assert.Equal(t, "foo", ctx.Config.Archive.Files[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFormatFor(t *testing.T) {
|
||||||
|
var ctx = &context.Context{
|
||||||
|
Config: config.Project{
|
||||||
|
Archive: config.Archive{
|
||||||
|
Format: "tar.gz",
|
||||||
|
FormatOverrides: []config.FormatOverride{
|
||||||
|
{
|
||||||
|
Goos: "windows",
|
||||||
|
Format: "zip",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Equal(t, "zip", packageFormat(ctx, "windows"))
|
||||||
|
assert.Equal(t, "tar.gz", packageFormat(ctx, "linux"))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user