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

1049 lines
26 KiB
Go
Raw Normal View History

2018-02-10 15:04:49 +02:00
package scoop
import (
ctx "context"
2018-02-15 04:22:07 +02:00
"flag"
2018-02-10 15:04:49 +02:00
"io/ioutil"
"os"
2018-09-06 12:20:12 +02:00
"path/filepath"
"testing"
2018-09-06 12:20:12 +02:00
2018-02-10 15:04:49 +02:00
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
2018-09-12 19:18:01 +02:00
"github.com/goreleaser/goreleaser/internal/pipe"
2018-02-10 15:37:22 +02:00
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
2018-08-21 03:20:04 +02:00
"github.com/stretchr/testify/require"
2018-02-10 15:04:49 +02:00
)
2018-02-15 04:22:07 +02:00
var update = flag.Bool("update", false, "update .golden files")
2018-02-10 15:37:22 +02:00
func TestDescription(t *testing.T) {
require.NotEmpty(t, Pipe{}.String())
2018-02-10 15:37:22 +02:00
}
func TestDefault(t *testing.T) {
_, back := testlib.Mktmp(t)
defer back()
var ctx = &context.Context{
TokenType: context.TokenTypeGitHub,
2018-02-10 15:37:22 +02:00
Config: config.Project{
ProjectName: "barr",
2018-02-10 15:37:22 +02:00
Builds: []config.Build{
{
Binary: "foo",
Goos: []string{"linux", "darwin"},
Goarch: []string{"386", "amd64"},
},
{
Binary: "bar",
Goos: []string{"linux", "darwin"},
Goarch: []string{"386", "amd64"},
Ignore: []config.IgnoredBuild{
{Goos: "darwin", Goarch: "amd64"},
},
},
{
Binary: "foobar",
Goos: []string{"linux"},
Goarch: []string{"amd64"},
},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoop.Name)
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Name)
require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Email)
require.NotEmpty(t, ctx.Config.Scoop.CommitMessageTemplate)
2018-02-10 15:37:22 +02:00
}
2018-02-10 15:55:03 +02:00
func Test_doRun(t *testing.T) {
2018-09-06 12:20:12 +02:00
folder, back := testlib.Mktmp(t)
defer back()
var file = filepath.Join(folder, "archive")
require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
type errChecker func(*testing.T, error)
var shouldErr = func(msg string) errChecker {
return func(t *testing.T, err error) {
require.Error(t, err)
require.EqualError(t, err, msg)
}
}
var shouldNotErr = func(t *testing.T, err error) {
require.NoError(t, err)
}
2018-02-10 15:55:03 +02:00
type args struct {
ctx *context.Context
client client.Client
}
tests := []struct {
name string
args args
artifacts []*artifact.Artifact
assertError errChecker
2018-02-10 15:55:03 +02:00
}{
{
"valid public github",
2018-02-10 15:55:03 +02:00
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
2018-02-10 15:55:03 +02:00
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
2018-02-10 15:55:03 +02:00
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
2018-02-10 15:55:03 +02:00
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
2018-09-06 12:20:12 +02:00
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
2018-02-10 15:55:03 +02:00
},
shouldNotErr,
2018-02-10 15:55:03 +02:00
},
{
"wrap in directory",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz", WrapInDirectory: "true"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"Wrap": "foo_1.0.1_windows_amd64",
},
},
{
Name: "foo_1.0.1_windows_386.tar.gz",
Goos: "windows",
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"Wrap": "foo_1.0.1_windows_386",
},
},
},
shouldNotErr,
},
2018-02-11 18:36:59 +02:00
{
"valid enterprise github",
2018-02-11 18:36:59 +02:00
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
2018-02-11 18:36:59 +02:00
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.github.enterprise.com"},
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
2018-02-11 18:36:59 +02:00
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
2018-02-11 18:36:59 +02:00
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
2018-09-06 12:20:12 +02:00
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
2018-02-11 18:36:59 +02:00
},
shouldNotErr,
2018-02-11 18:36:59 +02:00
},
2018-02-10 15:55:03 +02:00
{
"valid public gitlab",
2018-02-10 15:55:03 +02:00
args{
&context.Context{
TokenType: context.TokenTypeGitLab,
2018-02-10 15:55:03 +02:00
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
2018-02-10 15:55:03 +02:00
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
2018-02-10 15:55:03 +02:00
},
Release: config.Release{
GitLab: config.Repo{
2018-02-10 15:55:03 +02:00
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
2018-02-10 15:55:03 +02:00
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://gitlab.com/goreleaser",
2018-02-10 15:55:03 +02:00
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
},
},
{
Name: "foo_1.0.1_windows_386.tar.gz",
Goos: "windows",
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
},
},
2018-02-10 15:55:03 +02:00
},
shouldNotErr,
2018-02-10 15:55:03 +02:00
},
{
"valid enterprise gitlab",
2018-02-10 15:55:03 +02:00
args{
&context.Context{
TokenType: context.TokenTypeGitLab,
2018-02-10 15:55:03 +02:00
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitHubURLs: config.GitHubURLs{Download: "https://api.custom.gitlab.enterprise.com"},
2018-02-10 15:55:03 +02:00
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
2018-02-10 15:55:03 +02:00
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://gitlab.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
},
},
{
Name: "foo_1.0.1_windows_386.tar.gz",
Goos: "windows",
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
},
},
},
shouldNotErr,
},
{
"token type not implemented for pipe",
args{
&context.Context{
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{NotImplemented: true},
},
[]*artifact.Artifact{
2018-09-06 12:20:12 +02:00
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr(ErrTokenTypeNotImplementedForScoop.Error()),
},
{
"no windows build",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test"},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
2018-02-10 15:55:03 +02:00
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1_linux_amd64.tar.gz", Goos: "linux", Goarch: "amd64"},
{Name: "foo_1.0.1_linux_386.tar.gz", Goos: "linux", Goarch: "386"},
2018-02-11 18:36:59 +02:00
},
shouldErr("scoop requires a windows build"),
2018-02-11 18:36:59 +02:00
},
{
"no scoop",
2018-02-11 18:36:59 +02:00
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
2018-02-11 18:36:59 +02:00
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
2018-02-11 18:36:59 +02:00
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"},
},
shouldErr("scoop section is not configured"),
},
{
"no publish",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
2018-02-11 18:36:59 +02:00
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
2018-02-11 18:36:59 +02:00
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
SkipPublish: true,
2018-02-11 18:36:59 +02:00
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
2018-02-10 15:55:03 +02:00
},
shouldErr(pipe.ErrSkipPublishEnabled.Error()),
2018-02-10 15:55:03 +02:00
},
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
{
"is draft",
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
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
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
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
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
},
Release: config.Release{
Draft: true,
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
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
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr("release is marked as draft"),
},
{
"is prerelease and skip upload set to auto",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1-pre.1",
},
Semver: context.Semver{
Major: 1,
Minor: 0,
Patch: 1,
Prerelease: "-pre.1",
},
Version: "1.0.1-pre.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
SkipUpload: "auto",
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr("release is prerelease"),
},
{
"skip upload set to true",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
SkipUpload: "true",
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr("scoop.skip_upload is true"),
},
{
"release is disabled",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
Disable: true,
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr("release is disabled"),
},
{
"no archive",
args{
&context.Context{
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Builds: []config.Build{
{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "binary"},
},
Release: config.Release{
Draft: 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
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
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
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
},
},
},
&DummyClient{},
},
[]*artifact.Artifact{
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
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
},
shouldErr("archive format is binary"),
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
},
2018-02-10 15:55:03 +02:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2018-08-21 03:20:04 +02:00
var ctx = tt.args.ctx
2018-02-10 15:55:03 +02:00
for _, a := range tt.artifacts {
2018-08-21 03:20:04 +02:00
ctx.Artifacts.Add(a)
2018-02-10 15:55:03 +02:00
}
2018-08-21 03:20:04 +02:00
require.NoError(t, Pipe{}.Default(ctx))
2018-08-21 03:20:04 +02:00
tt.assertError(t, doRun(ctx, tt.args.client))
2018-02-10 15:55:03 +02:00
})
}
}
2018-02-10 15:04:49 +02:00
func Test_buildManifest(t *testing.T) {
2018-09-06 12:20:12 +02:00
folder, err := ioutil.TempDir("", "goreleasertest")
require.NoError(t, err)
var file = filepath.Join(folder, "archive")
require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
2018-02-10 15:04:49 +02:00
tests := []struct {
filename string
ctx *context.Context
2018-02-10 15:04:49 +02:00
}{
{
"testdata/test_buildmanifest.json.golden",
&context.Context{
Context: ctx.Background(),
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitHubURLs: config.GitHubURLs{
Download: "https://github.com",
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
Persist: []string{"data", "config", "test.ini"},
},
},
},
2018-02-10 15:04:49 +02:00
},
{
"testdata/test_buildmanifest_url_template.json.golden",
&context.Context{
Context: ctx.Background(),
TokenType: context.TokenTypeGitHub,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitHubURLs: config.GitHubURLs{
Download: "https://github.com",
},
Builds: []config.Build{
{Binary: "test"},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
URLTemplate: "http://github.mycompany.com/foo/bar/{{ .Tag }}/{{ .ArtifactName }}",
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
Persist: []string{"data.cfg", "etc"},
},
},
},
2018-02-10 15:04:49 +02:00
},
{
"testdata/test_buildmanifest_gitlab_url_template.json.golden",
&context.Context{
Context: ctx.Background(),
TokenType: context.TokenTypeGitLab,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitLabURLs: config.GitLabURLs{
Download: "https://gitlab.com",
},
Builds: []config.Build{
{Binary: "test"},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://gitlab.com/goreleaser",
URLTemplate: "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}",
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
Persist: []string{"data.cfg", "etc"},
},
},
},
},
2018-02-10 15:04:49 +02:00
}
2018-02-10 15:04:49 +02:00
for _, tt := range tests {
t.Run(tt.filename, func(t *testing.T) {
var ctx = tt.ctx
err := Pipe{}.Default(ctx)
require.NoError(t, err)
cl, err := client.New(ctx)
require.NoError(t, err)
mf, err := dataFor(ctx, cl, []*artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
"Builds": []*artifact.Artifact{
{
2020-04-02 23:59:01 +02:00
Name: "foo.exe",
},
{
2020-04-02 23:59:01 +02:00
Name: "bar.exe",
},
},
},
},
{
Name: "foo_1.0.1_windows_386.tar.gz",
Goos: "windows",
Goarch: "386",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
"Builds": []*artifact.Artifact{
{
2020-04-02 23:59:01 +02:00
Name: "foo.exe",
},
{
2020-04-02 23:59:01 +02:00
Name: "bar.exe",
},
},
},
},
})
require.NoError(t, err)
out, err := doBuildManifest(mf)
require.NoError(t, err)
if *update {
require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
}
bts, err := ioutil.ReadFile(tt.filename)
require.NoError(t, err)
require.Equal(t, string(bts), out.String())
})
2018-02-10 15:04:49 +02:00
}
}
func TestWrapInDirectory(t *testing.T) {
folder, err := ioutil.TempDir("", "goreleasertest")
require.NoError(t, err)
var file = filepath.Join(folder, "archive")
require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
var ctx = &context.Context{
TokenType: context.TokenTypeGitLab,
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
GitLabURLs: config.GitLabURLs{
Download: "https://gitlab.com",
},
Builds: []config.Build{
{Binary: "test"},
},
Dist: ".",
ProjectName: "run-pipe",
Archives: []config.Archive{
{Format: "tar.gz", WrapInDirectory: "true"},
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://gitlab.com/goreleaser",
URLTemplate: "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}",
CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
Persist: []string{"data.cfg", "etc"},
},
},
}
require.NoError(t, Pipe{}.Default(ctx))
cl, err := client.New(ctx)
require.NoError(t, err)
mf, err := dataFor(ctx, cl, []*artifact.Artifact{
{
Name: "foo_1.0.1_windows_amd64.tar.gz",
Goos: "windows",
Goarch: "amd64",
Path: file,
Extra: map[string]interface{}{
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
"WrappedIn": "foo_1.0.1_windows_amd64",
"Builds": []*artifact.Artifact{
{
Name: "foo.exe",
},
{
Name: "bar.exe",
},
},
},
},
})
require.NoError(t, err)
out, err := doBuildManifest(mf)
require.NoError(t, err)
var golden = "testdata/test_buildmanifest_wrap.json.golden"
if *update {
require.NoError(t, ioutil.WriteFile(golden, out.Bytes(), 0655))
}
bts, err := ioutil.ReadFile(golden)
require.NoError(t, err)
require.Equal(t, string(bts), out.String())
}
2018-02-10 15:04:49 +02:00
type DummyClient struct {
CreatedFile bool
Content string
NotImplemented bool
2018-02-10 15:04:49 +02:00
}
func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
return nil
}
func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
2018-02-10 15:04:49 +02:00
return
}
func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
if dc.NotImplemented {
return "", client.NotImplementedError{}
}
return "", nil
}
func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
dc.CreatedFile = true
dc.Content = string(content)
2018-02-10 15:04:49 +02:00
return
}
func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
2018-02-10 15:04:49 +02:00
return
}