2017-04-15 20:26:05 +02:00
|
|
|
package archive
|
|
|
|
|
|
|
|
import (
|
2017-10-02 18:43:03 +02:00
|
|
|
"archive/tar"
|
2018-07-25 02:33:31 +02:00
|
|
|
"archive/zip"
|
2017-10-02 18:43:03 +02:00
|
|
|
"compress/gzip"
|
|
|
|
"io"
|
2018-11-11 23:02:45 +02:00
|
|
|
"io/ioutil"
|
2017-04-15 20:26:05 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2017-12-17 22:40:19 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2017-07-23 21:27:46 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-11-11 23:02:45 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-07-09 05:54:42 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2017-04-15 20:26:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDescription(t *testing.T) {
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NotEmpty(t, Pipe{}.String())
|
2017-04-15 20:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipe(t *testing.T) {
|
2017-07-23 21:27:46 +02:00
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
2017-12-19 01:32:44 +02:00
|
|
|
for _, format := range []string{"tar.gz", "zip"} {
|
|
|
|
t.Run("Archive format "+format, func(tt *testing.T) {
|
2018-11-11 22:17:44 +02:00
|
|
|
var dist = filepath.Join(folder, format+"_dist")
|
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
|
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = os.Create(filepath.Join(folder, "README.md"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, os.MkdirAll(filepath.Join(folder, "foo", "bar", "foobar"), 0755))
|
|
|
|
_, err = os.Create(filepath.Join(filepath.Join(folder, "foo", "bar", "foobar", "blah.txt")))
|
|
|
|
require.NoError(t, err)
|
2017-12-19 01:32:44 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
ProjectName: "foobar",
|
|
|
|
Archive: config.Archive{
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Files: []string{
|
|
|
|
"README.*",
|
2018-07-25 02:33:31 +02:00
|
|
|
"./foo/**/*",
|
2017-12-19 01:32:44 +02:00
|
|
|
},
|
|
|
|
FormatOverrides: []config.FormatOverride{
|
|
|
|
{
|
|
|
|
Goos: "windows",
|
|
|
|
Format: "zip",
|
|
|
|
},
|
|
|
|
},
|
2017-04-21 21:01:19 +02:00
|
|
|
},
|
|
|
|
},
|
2017-12-19 01:32:44 +02:00
|
|
|
)
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin.exe",
|
|
|
|
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
"Extension": ".exe",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Version = "0.0.1"
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2017-04-15 20:26:05 +02:00
|
|
|
ctx.Config.Archive.Format = format
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(tt, Pipe{}.Run(ctx))
|
2017-12-19 01:32:44 +02:00
|
|
|
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
|
2018-07-09 05:54:42 +02:00
|
|
|
require.Len(tt, archives.List(), 2)
|
2017-12-19 01:32:44 +02:00
|
|
|
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
|
|
|
|
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
|
2018-11-11 22:17:44 +02:00
|
|
|
require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
|
|
|
|
require.Equal(tt, "foobar_0.0.1_windows_amd64.zip", windows.Name)
|
|
|
|
|
|
|
|
if format == "tar.gz" {
|
|
|
|
// Check archive contents
|
|
|
|
require.Equal(
|
|
|
|
t,
|
|
|
|
[]string{
|
|
|
|
"README.md",
|
|
|
|
"foo/bar",
|
|
|
|
"foo/bar/foobar",
|
|
|
|
"foo/bar/foobar/blah.txt",
|
|
|
|
"mybin",
|
|
|
|
},
|
|
|
|
tarFiles(t, filepath.Join(dist, "foobar_0.0.1_darwin_amd64.tar.gz")),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if format == "zip" {
|
|
|
|
require.Equal(
|
|
|
|
t,
|
|
|
|
[]string{
|
|
|
|
"README.md",
|
|
|
|
"foo/bar/foobar/blah.txt",
|
|
|
|
"mybin.exe",
|
|
|
|
},
|
|
|
|
zipFiles(t, filepath.Join(dist, "foobar_0.0.1_windows_amd64.zip")),
|
|
|
|
)
|
|
|
|
}
|
2017-04-15 20:26:05 +02:00
|
|
|
})
|
|
|
|
}
|
2018-07-25 02:33:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func zipFiles(t *testing.T, path string) []string {
|
|
|
|
f, err := os.Open(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
info, err := f.Stat()
|
|
|
|
require.NoError(t, err)
|
|
|
|
r, err := zip.NewReader(f, info.Size())
|
|
|
|
require.NoError(t, err)
|
|
|
|
var paths = make([]string, len(r.File))
|
|
|
|
for i, zf := range r.File {
|
|
|
|
paths[i] = zf.Name
|
|
|
|
}
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
|
|
|
func tarFiles(t *testing.T, path string) []string {
|
|
|
|
f, err := os.Open(path)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer f.Close()
|
2017-10-02 18:43:03 +02:00
|
|
|
gr, err := gzip.NewReader(f)
|
2018-07-25 02:33:31 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer gr.Close()
|
|
|
|
var r = tar.NewReader(gr)
|
|
|
|
var paths []string
|
|
|
|
for {
|
|
|
|
next, err := r.Next()
|
2017-10-02 18:43:03 +02:00
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2018-07-25 02:33:31 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
paths = append(paths, next.Name)
|
2017-10-02 18:43:03 +02:00
|
|
|
}
|
2018-07-25 02:33:31 +02:00
|
|
|
return paths
|
2017-04-15 20:26:05 +02:00
|
|
|
}
|
2017-04-21 21:03:36 +02:00
|
|
|
|
2017-06-08 11:41:09 +02:00
|
|
|
func TestRunPipeBinary(t *testing.T) {
|
2017-07-23 21:27:46 +02:00
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
2017-06-05 16:38:59 +02:00
|
|
|
var dist = filepath.Join(folder, "dist")
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
|
2017-12-17 22:40:19 +02:00
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-12-17 22:40:19 +02:00
|
|
|
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-06-05 16:38:59 +02:00
|
|
|
_, err = os.Create(filepath.Join(folder, "README.md"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-12-17 22:40:19 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
2017-06-05 16:38:59 +02:00
|
|
|
Dist: dist,
|
|
|
|
Archive: config.Archive{
|
2017-12-19 01:32:44 +02:00
|
|
|
Format: "binary",
|
2017-12-27 01:19:58 +02:00
|
|
|
NameTemplate: defaultBinaryNameTemplate,
|
2017-06-05 16:38:59 +02:00
|
|
|
},
|
|
|
|
},
|
2017-12-17 22:40:19 +02:00
|
|
|
)
|
2017-12-19 01:32:44 +02:00
|
|
|
ctx.Version = "0.0.1"
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2017-12-17 22:40:19 +02:00
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin.exe",
|
|
|
|
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
2017-12-19 01:32:44 +02:00
|
|
|
"Ext": ".exe",
|
2017-12-17 22:40:19 +02:00
|
|
|
},
|
|
|
|
})
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2017-12-17 22:40:19 +02:00
|
|
|
var binaries = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
|
2017-12-19 01:32:44 +02:00
|
|
|
darwin := binaries.Filter(artifact.ByGoos("darwin")).List()[0]
|
|
|
|
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
2018-11-11 22:17:44 +02:00
|
|
|
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwin.Name)
|
|
|
|
require.Equal(t, "mybin_0.0.1_windows_amd64.exe", windows.Name)
|
|
|
|
require.Len(t, binaries.List(), 2)
|
2017-06-05 16:38:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-22 15:29:53 +02:00
|
|
|
func TestRunPipeDistRemoved(t *testing.T) {
|
2017-12-17 22:40:19 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
2017-04-22 15:29:53 +02:00
|
|
|
Dist: "/path/nope",
|
|
|
|
Archive: config.Archive{
|
2017-12-17 22:40:19 +02:00
|
|
|
NameTemplate: "nope",
|
|
|
|
Format: "zip",
|
2017-04-22 15:29:53 +02:00
|
|
|
},
|
|
|
|
},
|
2017-12-17 22:40:19 +02:00
|
|
|
)
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2017-12-17 22:40:19 +02:00
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin.exe",
|
|
|
|
Path: filepath.Join("/path/to/nope", "windowsamd64", "mybin.exe"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
2017-12-19 01:32:44 +02:00
|
|
|
"Binary": "mybin",
|
|
|
|
"Extension": ".exe",
|
2017-05-11 05:05:51 +02:00
|
|
|
},
|
2017-12-17 22:40:19 +02:00
|
|
|
})
|
2018-11-11 22:17:44 +02:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), `failed to create directory /path/nope/nope.zip: open /path/nope/nope.zip: no such file or directory`)
|
2017-05-11 05:05:51 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 22:40:19 +02:00
|
|
|
func TestRunPipeInvalidGlob(t *testing.T) {
|
2017-07-23 21:27:46 +02:00
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
2017-12-17 22:40:19 +02:00
|
|
|
var dist = filepath.Join(folder, "dist")
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
2017-12-17 22:40:19 +02:00
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-12-17 22:40:19 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
|
|
|
Dist: dist,
|
2017-05-11 05:05:51 +02:00
|
|
|
Archive: config.Archive{
|
2017-12-17 22:40:19 +02:00
|
|
|
NameTemplate: "foo",
|
|
|
|
Format: "zip",
|
2017-05-11 05:05:51 +02:00
|
|
|
Files: []string{
|
2017-12-17 22:40:19 +02:00
|
|
|
"[x-]",
|
2017-05-11 05:05:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-12-17 22:40:19 +02:00
|
|
|
)
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2017-12-17 22:40:19 +02:00
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join("dist", "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
2018-11-11 22:17:44 +02:00
|
|
|
require.EqualError(t, Pipe{}.Run(ctx), `failed to find files to archive: globbing failed for pattern [x-]: file does not exist`)
|
2017-05-11 05:05:51 +02:00
|
|
|
}
|
2018-11-11 16:12:48 +02:00
|
|
|
|
2017-10-02 18:43:03 +02:00
|
|
|
func TestRunPipeWrap(t *testing.T) {
|
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
2017-12-17 22:40:19 +02:00
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-10-02 18:43:03 +02:00
|
|
|
_, err = os.Create(filepath.Join(folder, "README.md"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2017-12-17 22:40:19 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
2017-10-02 18:43:03 +02:00
|
|
|
Dist: dist,
|
|
|
|
Archive: config.Archive{
|
2017-12-17 22:40:19 +02:00
|
|
|
NameTemplate: "foo",
|
2017-10-02 18:43:03 +02:00
|
|
|
WrapInDirectory: true,
|
|
|
|
Format: "tar.gz",
|
|
|
|
Files: []string{
|
|
|
|
"README.*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-12-17 22:40:19 +02:00
|
|
|
)
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2017-12-17 22:40:19 +02:00
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join("dist", "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, Pipe{}.Run(ctx))
|
2017-10-02 18:43:03 +02:00
|
|
|
|
|
|
|
// Check archive contents
|
2017-12-17 22:40:19 +02:00
|
|
|
f, err := os.Open(filepath.Join(dist, "foo.tar.gz"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, f.Close()) }()
|
2017-10-02 18:43:03 +02:00
|
|
|
gr, err := gzip.NewReader(f)
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
defer func() { require.NoError(t, gr.Close()) }()
|
2017-10-02 18:43:03 +02:00
|
|
|
r := tar.NewReader(gr)
|
|
|
|
for _, n := range []string{"README.md", "mybin"} {
|
|
|
|
h, err := r.Next()
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, filepath.Join("foo", n), h.Name)
|
2017-10-02 18:43:03 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-03 04:24:55 +02:00
|
|
|
|
|
|
|
func TestDefault(t *testing.T) {
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Archive: config.Archive{},
|
|
|
|
},
|
|
|
|
}
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.NotEmpty(t, ctx.Config.Archive.NameTemplate)
|
|
|
|
require.Equal(t, "tar.gz", ctx.Config.Archive.Format)
|
|
|
|
require.NotEmpty(t, ctx.Config.Archive.Files)
|
2017-12-03 04:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSet(t *testing.T) {
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Archive: config.Archive{
|
|
|
|
NameTemplate: "foo",
|
|
|
|
Format: "zip",
|
|
|
|
Files: []string{
|
|
|
|
"foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, "foo", ctx.Config.Archive.NameTemplate)
|
|
|
|
require.Equal(t, "zip", ctx.Config.Archive.Format)
|
|
|
|
require.Equal(t, "foo", ctx.Config.Archive.Files[0])
|
2017-12-03 04:24:55 +02:00
|
|
|
}
|
2017-12-19 01:15:32 +02:00
|
|
|
|
2017-12-27 01:19:58 +02:00
|
|
|
func TestDefaultFormatBinary(t *testing.T) {
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Archive: config.Archive{
|
|
|
|
Format: "binary",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
require.Equal(t, defaultBinaryNameTemplate, ctx.Config.Archive.NameTemplate)
|
2017-12-27 01:19:58 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 01:15:32 +02:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-11-11 22:17:44 +02:00
|
|
|
require.Equal(t, "zip", packageFormat(ctx, "windows"))
|
|
|
|
require.Equal(t, "tar.gz", packageFormat(ctx, "linux"))
|
2017-12-19 01:15:32 +02:00
|
|
|
}
|
2018-03-17 03:52:04 +02:00
|
|
|
|
|
|
|
func TestBinaryOverride(t *testing.T) {
|
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
|
2018-03-17 03:52:04 +02:00
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-17 03:52:04 +02:00
|
|
|
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-17 03:52:04 +02:00
|
|
|
_, err = os.Create(filepath.Join(folder, "README.md"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2018-03-17 03:52:04 +02:00
|
|
|
for _, format := range []string{"tar.gz", "zip"} {
|
|
|
|
t.Run("Archive format "+format, func(tt *testing.T) {
|
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
ProjectName: "foobar",
|
|
|
|
Archive: config.Archive{
|
|
|
|
NameTemplate: defaultNameTemplate,
|
|
|
|
Files: []string{
|
|
|
|
"README.*",
|
|
|
|
},
|
|
|
|
FormatOverrides: []config.FormatOverride{
|
|
|
|
{
|
|
|
|
Goos: "windows",
|
|
|
|
Format: "binary",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2018-07-09 05:54:42 +02:00
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
2018-03-17 03:52:04 +02:00
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin.exe",
|
|
|
|
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
"Ext": ".exe",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Version = "0.0.1"
|
|
|
|
ctx.Config.Archive.Format = format
|
|
|
|
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(tt, Pipe{}.Run(ctx))
|
2018-03-17 03:52:04 +02:00
|
|
|
var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive))
|
|
|
|
darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0]
|
2018-11-11 22:17:44 +02:00
|
|
|
require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name)
|
2018-03-17 03:52:04 +02:00
|
|
|
|
|
|
|
archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary))
|
|
|
|
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
|
2018-11-11 22:17:44 +02:00
|
|
|
require.Equal(tt, "foobar_0.0.1_windows_amd64.exe", windows.Name)
|
2018-03-17 03:52:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 16:11:03 +02:00
|
|
|
|
|
|
|
func TestRunPipeSameArchiveFilename(t *testing.T) {
|
|
|
|
folder, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
var dist = filepath.Join(folder, "dist")
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, os.Mkdir(dist, 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "darwinamd64"), 0755))
|
|
|
|
require.NoError(t, os.Mkdir(filepath.Join(dist, "windowsamd64"), 0755))
|
2018-11-11 16:11:03 +02:00
|
|
|
_, err := os.Create(filepath.Join(dist, "darwinamd64", "mybin"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2018-11-11 16:11:03 +02:00
|
|
|
_, err = os.Create(filepath.Join(dist, "windowsamd64", "mybin.exe"))
|
2018-11-11 22:17:44 +02:00
|
|
|
require.NoError(t, err)
|
2018-11-11 16:11:03 +02:00
|
|
|
var ctx = context.New(
|
|
|
|
config.Project{
|
|
|
|
Dist: dist,
|
|
|
|
ProjectName: "foobar",
|
|
|
|
Archive: config.Archive{
|
|
|
|
NameTemplate: "same-filename",
|
|
|
|
Files: []string{
|
|
|
|
"README.*",
|
|
|
|
"./foo/**/*",
|
|
|
|
},
|
|
|
|
Format: "tar.gz",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "darwin",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin",
|
|
|
|
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(artifact.Artifact{
|
|
|
|
Goos: "windows",
|
|
|
|
Goarch: "amd64",
|
|
|
|
Name: "mybin.exe",
|
|
|
|
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
|
|
|
|
Type: artifact.Binary,
|
|
|
|
Extra: map[string]string{
|
|
|
|
"Binary": "mybin",
|
|
|
|
"Extension": ".exe",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Version = "0.0.1"
|
|
|
|
ctx.Git.CurrentTag = "v0.0.1"
|
|
|
|
err = Pipe{}.Run(ctx)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "same-filename.tar.gz already exists. Check your archive name template")
|
|
|
|
}
|
2018-11-11 23:02:45 +02:00
|
|
|
|
|
|
|
func TestDuplicateFilesInsideArchive(t *testing.T) {
|
|
|
|
f, err := ioutil.TempFile("", "")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer f.Close()
|
|
|
|
defer os.Remove(f.Name())
|
|
|
|
|
|
|
|
ff, err := ioutil.TempFile("", "")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ff.Close()
|
|
|
|
defer os.Remove(ff.Name())
|
|
|
|
|
|
|
|
a := NewEnhancedArchive(archive.New(f), "")
|
|
|
|
defer a.Close()
|
|
|
|
require.NoError(t, a.Add("foo", ff.Name()))
|
|
|
|
require.EqualError(t, a.Add("foo", ff.Name()), "file foo already exists in the archive")
|
|
|
|
}
|