1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/release/release_test.go

580 lines
15 KiB
Go
Raw Normal View History

2016-12-29 15:21:50 +02:00
package release
import (
2017-03-26 20:56:35 +02:00
"io/ioutil"
"os"
"path/filepath"
"strings"
"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"
"github.com/goreleaser/goreleaser/internal/client"
2017-08-20 21:50:34 +02:00
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"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) {
assert.NotEmpty(t, Pipe{}.String())
2017-03-26 01:43:42 +02:00
}
2017-03-26 20:56:35 +02:00
func TestRunPipeWithoutIDsThenDoesNotFilter(t *testing.T) {
2017-04-15 19:18:17 +02:00
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(t, err)
2017-04-14 17:18:59 +02:00
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
assert.NoError(t, err)
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"))
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)
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"}
ctx.Artifacts.Add(&artifact.Artifact{
2017-12-18 01:26:03 +02:00
Type: artifact.UploadableArchive,
Name: "bin.tar.gz",
Path: tarfile.Name(),
Extra: map[string]interface{}{
"ID": "foo",
},
2017-12-18 01:26:03 +02:00
})
ctx.Artifacts.Add(&artifact.Artifact{
2017-12-18 01:26:03 +02:00
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",
},
})
ctx.Artifacts.Add(&artifact.Artifact{
Type: artifact.UploadableSourceArchive,
Name: "source.tar.gz",
Path: srcfile.Name(),
Extra: map[string]interface{}{
"Format": "tar.gz",
},
})
client := &DummyClient{}
assert.NoError(t, doPublish(ctx, client))
assert.True(t, client.CreatedRelease)
assert.True(t, client.UploadedFile)
assert.Contains(t, client.UploadedFileNames, "source.tar.gz")
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"},
ExtraFiles: []config.ExtraFile{
{Glob: "./testdata/**/*"},
},
},
}
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))
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")
assert.Contains(t, client.UploadedFileNames, "release1.golden")
assert.Contains(t, client.UploadedFileNames, "release2.golden")
assert.Contains(t, client.UploadedFileNames, "f1")
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))
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"}
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))
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")
assert.NoError(t, err)
2017-04-15 17:18:09 +02:00
tarfile, err := os.Create(filepath.Join(folder, "bin.tar.gz"))
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"}
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,
}
assert.EqualError(t, doPublish(ctx, client), "failed to upload bin.tar.gz after 1 tries: upload failed")
assert.True(t, client.CreatedRelease)
assert.False(t, client.UploadedFile)
2017-04-15 17:18:09 +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"))
}
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"}
ctx.Artifacts.Add(&artifact.Artifact{
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)
}
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))
assert.False(t, client.CreatedRelease)
assert.False(t, client.UploadedFile)
}
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{})
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
assert.NoError(t, Pipe{}.Default(ctx))
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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)
}
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)
}
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",
},
})
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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,
}
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",
},
})
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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",
}
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",
},
})
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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-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,
},
})
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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))
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
}
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",
},
},
},
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
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()
var ctx = &context.Context{
Config: config.Project{},
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
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{},
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
testlib.GitInit(t)
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()
var ctx = &context.Context{
Config: config.Project{},
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
ctx.Snapshot = true
assert.NoError(t, Pipe{}.Default(ctx))
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{},
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
ctx.TokenType = context.TokenTypeGitHub
assert.Error(t, Pipe{}.Default(ctx))
assert.Empty(t, ctx.Config.Release.GitHub.String())
}
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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",
},
Gitea: config.Repo{
Owner: "giteaOwner",
Name: "giteaName",
},
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
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
UploadedFilePaths map[string]string
FailFirstUpload bool
Lock sync.Mutex
2017-03-26 20:56:35 +02:00
}
func (c *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
if c.FailToCreateRelease {
feat: add gitlab for releases (#1038) * outlines gitlab client integration * makes client parameter more explicit * adds gitlab url to config * changes releaseID to string to adapt to gitlab * updates to latest gitlab client lib 0.18 * fixes copy paster in gitlab upload func * fixes gitlab typo in config * adds gitlab token to env and context * release now uses the client factory method * skips brew pipe if it is not a github release * add github tokentype to publish tests * skips scoop pipe if it is not a github release * corrects brew skip msg * adds gitlab token to main test * adds gitlab to release docs * validates config and errors accordingly * adapt release pipe name to include gitlab * fixes gitlab client after testing * moves not-configured brew and scoop pipe checks as first check * adds more debug to gitlab client * adapts changelog generation for gitlab markdown * adds debug log for gitlab changelog * env needs to run before changelog pipe * moves gitlab default download url to default pipe * moves multiple releases check to from config to release pipe * release differs now for github and gitlab * adds debug gitlab release update msgs * moves env pipe as second after before because it determines the token type other pipes depend on * adaptes error check on gitlab release creation * Revert "adaptes error check on gitlab release creation" This reverts commit 032024571c76140f8e2207ee01cc08088f37594b. * simplifies gitlab client logic. removes comments * skips tls verification for gitlab client if specified in config * updates the docs * adds clarification that brew and scoop are not supported if it is a gitlab release * fixes copy paster in release.md * adds missing blob pipe in defaults and publish due to missing in merge * updates comment in gitlab client
2019-06-29 16:02:40 +02:00
return "", errors.New("release failed")
2017-04-15 17:18:09 +02:00
}
c.CreatedRelease = true
2017-03-26 20:56:35 +02:00
return
}
func (c *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
return "", nil
}
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
}
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{}
}
// ensure file is read to better mimic real behavior
_, err := ioutil.ReadAll(file)
if err != nil {
return errors.Wrapf(err, "unexpected error")
}
if c.FailToUpload {
2017-04-15 17:18:09 +02:00
return errors.New("upload failed")
}
if c.FailFirstUpload {
c.FailFirstUpload = false
return client.RetriableError{Err: errors.New("upload failed, should retry")}
}
c.UploadedFile = true
c.UploadedFileNames = append(c.UploadedFileNames, artifact.Name)
c.UploadedFilePaths[artifact.Name] = artifact.Path
return nil
2017-03-26 20:56:35 +02:00
}