2016-12-29 15:21:50 +02:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
2017-03-26 20:56:35 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-02-11 21:10:41 +02:00
|
|
|
"strings"
|
2018-02-24 22:31:07 +02:00
|
|
|
"sync"
|
2016-12-30 16:03:43 +02:00
|
|
|
"testing"
|
2017-01-02 14:47:19 +02:00
|
|
|
|
2017-12-18 01:26:03 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2020-03-22 22:03:31 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2017-08-20 21:50:34 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-12-28 23:17:40 +02:00
|
|
|
"github.com/pkg/errors"
|
2017-01-02 14:47:19 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-12-29 15:21:50 +02:00
|
|
|
)
|
|
|
|
|
2017-03-26 01:46:02 +02:00
|
|
|
func TestPipeDescription(t *testing.T) {
|
2017-12-02 23:53:19 +02:00
|
|
|
assert.NotEmpty(t, Pipe{}.String())
|
2017-03-26 01:43:42 +02:00
|
|
|
}
|
2017-03-26 20:56:35 +02:00
|
|
|
|
2019-10-19 21:01:11 +02:00
|
|
|
func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
|
2017-04-15 19:18:17 +02:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-04-14 17:18:59 +02:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2020-04-12 16:47:46 +02:00
|
|
|
srcfile, err := os.Create(filepath.Join(folder, "source.tar.gz"))
|
|
|
|
assert.NoError(t, err)
|
2017-04-14 17:18:59 +02:00
|
|
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2019-10-19 21:01:11 +02:00
|
|
|
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-03-26 20:56:35 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-18 01:26:03 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
2019-10-19 21:01:11 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "foo",
|
|
|
|
},
|
2017-12-18 01:26:03 +02:00
|
|
|
})
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-18 01:26:03 +02:00
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "bin.deb",
|
|
|
|
Path: debfile.Name(),
|
2019-10-19 21:01:11 +02:00
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "filtered.tar.gz",
|
|
|
|
Path: filteredtarfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "bar",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "filtered.deb",
|
|
|
|
Path: filtereddebfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "bar",
|
|
|
|
},
|
|
|
|
})
|
2020-04-12 16:47:46 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableSourceArchive,
|
|
|
|
Name: "source.tar.gz",
|
|
|
|
Path: srcfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"Format": "tar.gz",
|
|
|
|
},
|
|
|
|
})
|
2019-10-19 21:01:11 +02:00
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(t, doPublish(ctx, client))
|
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.True(t, client.UploadedFile)
|
2020-04-12 16:47:46 +02:00
|
|
|
assert.Contains(t, client.UploadedFileNames, "source.tar.gz")
|
2019-10-19 21:01:11 +02:00
|
|
|
assert.Contains(t, client.UploadedFileNames, "bin.deb")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "filtered.deb")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "filtered.tar.gz")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeWithIDsThenFilters(t *testing.T) {
|
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
debfile, err := os.Create(filepath.Join(folder, "bin.deb"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
filteredtarfile, err := os.Create(filepath.Join(folder, "filtered.tar.gz"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
filtereddebfile, err := os.Create(filepath.Join(folder, "filtered.deb"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
var config = config.Project{
|
|
|
|
Dist: folder,
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
IDs: []string{"foo"},
|
2020-02-11 21:10:41 +02:00
|
|
|
ExtraFiles: []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/**/*"},
|
|
|
|
},
|
2019-10-19 21:01:11 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "bin.deb",
|
|
|
|
Path: debfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "filtered.tar.gz",
|
|
|
|
Path: filteredtarfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "bar",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
|
|
|
Type: artifact.LinuxPackage,
|
|
|
|
Name: "filtered.deb",
|
|
|
|
Path: filtereddebfile.Name(),
|
|
|
|
Extra: map[string]interface{}{
|
|
|
|
"ID": "bar",
|
|
|
|
},
|
2017-12-18 01:26:03 +02:00
|
|
|
})
|
2017-03-26 20:56:35 +02:00
|
|
|
client := &DummyClient{}
|
2018-10-17 01:39:10 +02:00
|
|
|
assert.NoError(t, doPublish(ctx, client))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.True(t, client.UploadedFile)
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "bin.deb")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "bin.tar.gz")
|
2020-02-11 21:10:41 +02:00
|
|
|
assert.Contains(t, client.UploadedFileNames, "release1.golden")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "release2.golden")
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "f1")
|
2019-10-19 21:01:11 +02:00
|
|
|
assert.NotContains(t, client.UploadedFileNames, "filtered.deb")
|
|
|
|
assert.NotContains(t, client.UploadedFileNames, "filtered.tar.gz")
|
2017-03-26 20:56:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 17:18:09 +02:00
|
|
|
func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 17:18:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
2017-04-15 17:18:09 +02:00
|
|
|
client := &DummyClient{
|
|
|
|
FailToCreateRelease: true,
|
|
|
|
}
|
2018-10-17 01:39:10 +02:00
|
|
|
assert.Error(t, doPublish(ctx, client))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.False(t, client.CreatedRelease)
|
|
|
|
assert.False(t, client.UploadedFile)
|
2017-04-15 17:18:09 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 20:53:36 +02:00
|
|
|
func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-14 20:53:36 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-18 01:26:03 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: "/nope/nope/nope",
|
|
|
|
})
|
2017-04-14 20:53:36 +02:00
|
|
|
client := &DummyClient{}
|
2018-10-17 01:39:10 +02:00
|
|
|
assert.Error(t, doPublish(ctx, client))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.False(t, client.UploadedFile)
|
2017-04-14 20:53:36 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 17:18:09 +02:00
|
|
|
func TestRunPipeUploadFailure(t *testing.T) {
|
2017-04-15 19:18:17 +02:00
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-04-15 17:18:09 +02:00
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.NoError(t, err)
|
2017-07-15 21:49:52 +02:00
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
2017-04-15 17:18:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-07-15 21:49:52 +02:00
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2017-12-18 01:26:03 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
})
|
2017-04-15 17:18:09 +02:00
|
|
|
client := &DummyClient{
|
|
|
|
FailToUpload: true,
|
|
|
|
}
|
2020-03-22 22:03:31 +02:00
|
|
|
assert.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.False(t, client.UploadedFile)
|
2017-04-15 17:18:09 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 21:10:41 +02:00
|
|
|
func TestRunPipeExtraFileNotFound(t *testing.T) {
|
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
ExtraFiles: []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/release2.golden"},
|
|
|
|
{Glob: "./nope"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: file does not exist")
|
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.False(t, client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunPipeExtraOverride(t *testing.T) {
|
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
ExtraFiles: []config.ExtraFile{
|
|
|
|
{Glob: "./testdata/**/*"},
|
|
|
|
{Glob: "./testdata/upload_same_name/f1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
|
|
|
client := &DummyClient{}
|
|
|
|
assert.NoError(t, doPublish(ctx, client))
|
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.True(t, client.UploadedFile)
|
|
|
|
assert.Contains(t, client.UploadedFileNames, "f1")
|
|
|
|
assert.True(t, strings.HasSuffix(client.UploadedFilePaths["f1"], "testdata/upload_same_name/f1"))
|
|
|
|
}
|
|
|
|
|
2018-12-28 23:17:40 +02:00
|
|
|
func TestRunPipeUploadRetry(t *testing.T) {
|
|
|
|
folder, err := ioutil.TempDir("", "goreleasertest")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
var config = config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "test",
|
|
|
|
Name: "test",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
var ctx = context.New(config)
|
|
|
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
2019-08-12 22:44:48 +02:00
|
|
|
ctx.Artifacts.Add(&artifact.Artifact{
|
2018-12-28 23:17:40 +02:00
|
|
|
Type: artifact.UploadableArchive,
|
|
|
|
Name: "bin.tar.gz",
|
|
|
|
Path: tarfile.Name(),
|
|
|
|
})
|
|
|
|
client := &DummyClient{
|
|
|
|
FailFirstUpload: true,
|
|
|
|
}
|
|
|
|
assert.NoError(t, doPublish(ctx, client))
|
|
|
|
assert.True(t, client.CreatedRelease)
|
|
|
|
assert.True(t, client.UploadedFile)
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:36:05 +02:00
|
|
|
func TestPipeDisabled(t *testing.T) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Disable: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
client := &DummyClient{}
|
2018-10-17 01:39:10 +02:00
|
|
|
testlib.AssertSkipped(t, doPublish(ctx, client))
|
2017-09-27 00:24:49 +02:00
|
|
|
assert.False(t, client.CreatedRelease)
|
|
|
|
assert.False(t, client.UploadedFile)
|
2017-04-18 18:10:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 03:21:13 +02:00
|
|
|
func TestDefault(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
2018-04-25 05:57:19 +02:00
|
|
|
var ctx = context.New(config.Project{})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2017-12-03 03:21:13 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
|
|
|
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
func TestDefaultWithGitlab(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitlab.com:gitlabowner/gitlabrepo.git")
|
|
|
|
|
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
ctx.TokenType = context.TokenTypeGitLab
|
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, "gitlabrepo", ctx.Config.Release.GitLab.Name)
|
|
|
|
assert.Equal(t, "gitlabowner", ctx.Config.Release.GitLab.Owner)
|
|
|
|
}
|
|
|
|
|
2019-08-26 09:31:38 +02:00
|
|
|
func TestDefaultWithGitea(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@gitea.example.com:giteaowner/gitearepo.git")
|
|
|
|
|
|
|
|
var ctx = context.New(config.Project{})
|
|
|
|
ctx.TokenType = context.TokenTypeGitea
|
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, "gitearepo", ctx.Config.Release.Gitea.Name)
|
|
|
|
assert.Equal(t, "giteaowner", ctx.Config.Release.Gitea.Owner)
|
|
|
|
}
|
|
|
|
|
2018-11-29 20:42:14 +02:00
|
|
|
func TestDefaultPreReleaseAuto(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
|
|
|
t.Run("auto-release", func(t *testing.T) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Prerelease: "auto",
|
|
|
|
},
|
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2019-01-19 20:57:58 +02:00
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 0,
|
|
|
|
}
|
2018-11-29 20:42:14 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, false, ctx.PreRelease)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("auto-rc", func(t *testing.T) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Prerelease: "auto",
|
|
|
|
},
|
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2019-01-19 20:57:58 +02:00
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 0,
|
|
|
|
Prerelease: "rc1",
|
|
|
|
}
|
2018-11-29 20:42:14 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, true, ctx.PreRelease)
|
|
|
|
})
|
2019-01-10 21:08:08 +02:00
|
|
|
|
2019-01-19 20:57:58 +02:00
|
|
|
t.Run("auto-rc-github-setup", func(t *testing.T) {
|
2019-01-10 21:08:08 +02:00
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "foo",
|
|
|
|
},
|
|
|
|
Prerelease: "auto",
|
|
|
|
},
|
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2019-01-19 20:57:58 +02:00
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: 1,
|
|
|
|
Minor: 0,
|
|
|
|
Patch: 0,
|
|
|
|
Prerelease: "rc1",
|
|
|
|
}
|
2019-01-10 21:08:08 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, true, ctx.PreRelease)
|
|
|
|
})
|
2018-11-29 20:42:14 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:57:19 +02:00
|
|
|
func TestDefaultPipeDisabled(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
Disable: true,
|
|
|
|
},
|
|
|
|
})
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2018-04-25 05:57:19 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
2018-11-03 20:18:04 +02:00
|
|
|
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
|
|
|
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
2018-04-25 05:57:19 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 03:21:13 +02:00
|
|
|
func TestDefaultFilled(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
testlib.GitInit(t)
|
|
|
|
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
|
|
|
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Name: "foo",
|
|
|
|
Owner: "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2017-12-03 03:21:13 +02:00
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
|
|
|
assert.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultNotAGitRepo(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
2018-02-26 01:17:45 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2018-02-26 01:17:45 +02:00
|
|
|
assert.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
|
|
|
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2017-12-03 03:21:13 +02:00
|
|
|
testlib.GitInit(t)
|
2018-02-26 01:17:45 +02:00
|
|
|
assert.EqualError(t, Pipe{}.Default(ctx), "repository doesn't have an `origin` remote")
|
|
|
|
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
2017-12-03 03:21:13 +02:00
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2018-02-26 01:17:45 +02:00
|
|
|
ctx.Snapshot = true
|
|
|
|
assert.NoError(t, Pipe{}.Default(ctx))
|
2017-12-03 03:21:13 +02:00
|
|
|
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
|
|
|
_, back := testlib.Mktmp(t)
|
|
|
|
defer back()
|
|
|
|
var ctx = &context.Context{
|
|
|
|
Config: config.Project{},
|
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
ctx.TokenType = context.TokenTypeGitHub
|
2017-12-03 03:21:13 +02:00
|
|
|
assert.Error(t, Pipe{}.Default(ctx))
|
|
|
|
assert.Empty(t, ctx.Config.Release.GitHub.String())
|
|
|
|
}
|
|
|
|
|
2019-06-29 16:02:40 +02:00
|
|
|
func TestDefaultMultipleReleasesDefined(t *testing.T) {
|
|
|
|
var ctx = context.New(config.Project{
|
|
|
|
Release: config.Release{
|
|
|
|
GitHub: config.Repo{
|
|
|
|
Owner: "githubName",
|
|
|
|
Name: "githubName",
|
|
|
|
},
|
|
|
|
GitLab: config.Repo{
|
|
|
|
Owner: "gitlabOwner",
|
|
|
|
Name: "gitlabName",
|
|
|
|
},
|
2019-08-26 09:31:38 +02:00
|
|
|
Gitea: config.Repo{
|
|
|
|
Owner: "giteaOwner",
|
|
|
|
Name: "giteaName",
|
|
|
|
},
|
2019-06-29 16:02:40 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.EqualError(t, Pipe{}.Default(ctx), ErrMultipleReleases.Error())
|
|
|
|
}
|
|
|
|
|
2017-03-26 20:56:35 +02:00
|
|
|
type DummyClient struct {
|
2017-04-15 17:18:09 +02:00
|
|
|
FailToCreateRelease bool
|
|
|
|
FailToUpload bool
|
|
|
|
CreatedRelease bool
|
|
|
|
UploadedFile bool
|
2017-07-05 02:28:21 +02:00
|
|
|
UploadedFileNames []string
|
2020-02-11 21:10:41 +02:00
|
|
|
UploadedFilePaths map[string]string
|
2018-12-28 23:17:40 +02:00
|
|
|
FailFirstUpload bool
|
2018-02-24 22:31:07 +02:00
|
|
|
Lock sync.Mutex
|
2017-03-26 20:56:35 +02:00
|
|
|
}
|
|
|
|
|
2020-03-22 22:03:31 +02:00
|
|
|
func (c *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
|
|
|
|
if c.FailToCreateRelease {
|
2019-06-29 16:02:40 +02:00
|
|
|
return "", errors.New("release failed")
|
2017-04-15 17:18:09 +02:00
|
|
|
}
|
2020-03-22 22:03:31 +02:00
|
|
|
c.CreatedRelease = true
|
2017-03-26 20:56:35 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-06 15:48:17 +02:00
|
|
|
func (c *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:12:41 +02:00
|
|
|
func (c *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
|
2017-03-26 20:56:35 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-22 22:03:31 +02:00
|
|
|
func (c *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error {
|
|
|
|
c.Lock.Lock()
|
|
|
|
defer c.Lock.Unlock()
|
|
|
|
if c.UploadedFilePaths == nil {
|
|
|
|
c.UploadedFilePaths = map[string]string{}
|
2020-02-11 21:10:41 +02:00
|
|
|
}
|
2018-12-28 23:17:40 +02:00
|
|
|
// ensure file is read to better mimic real behavior
|
|
|
|
_, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "unexpected error")
|
|
|
|
}
|
2020-03-22 22:03:31 +02:00
|
|
|
if c.FailToUpload {
|
2017-04-15 17:18:09 +02:00
|
|
|
return errors.New("upload failed")
|
|
|
|
}
|
2020-03-22 22:03:31 +02:00
|
|
|
if c.FailFirstUpload {
|
|
|
|
c.FailFirstUpload = false
|
2020-07-06 22:12:41 +02:00
|
|
|
return client.RetriableError{Err: errors.New("upload failed, should retry")}
|
2018-12-28 23:17:40 +02:00
|
|
|
}
|
2020-03-22 22:03:31 +02:00
|
|
|
c.UploadedFile = true
|
|
|
|
c.UploadedFileNames = append(c.UploadedFileNames, artifact.Name)
|
|
|
|
c.UploadedFilePaths[artifact.Name] = artifact.Path
|
2018-12-28 23:17:40 +02:00
|
|
|
return nil
|
2017-03-26 20:56:35 +02:00
|
|
|
}
|