mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix(pipe/brew): Default to GitHub (#1483)
This commit is contained in:
parent
39a7dc2ad1
commit
6f8db25ec6
@ -26,8 +26,20 @@ var ErrNoArchivesFound = errors.New("no linux/macos archives found")
|
||||
// for linux or windows.
|
||||
var ErrMultipleArchivesSameOS = errors.New("one tap can handle only archive of an OS/Arch combination. Consider using ids in the brew section")
|
||||
|
||||
// ErrEmptyTokenType indicates unknown token type
|
||||
var ErrEmptyTokenType = errors.New("no token type found")
|
||||
|
||||
// ErrTokenTypeNotImplementedForBrew indicates that a new token type was not implemented for this pipe
|
||||
var ErrTokenTypeNotImplementedForBrew = errors.New("token type not implemented for brew pipe")
|
||||
type ErrTokenTypeNotImplementedForBrew struct {
|
||||
TokenType context.TokenType
|
||||
}
|
||||
|
||||
func (e ErrTokenTypeNotImplementedForBrew) Error() string {
|
||||
if e.TokenType != "" {
|
||||
return fmt.Sprintf("token type %q not implemented for brew pipe", e.TokenType)
|
||||
}
|
||||
return "token type not implemented for brew pipe"
|
||||
}
|
||||
|
||||
// Pipe for brew deployment
|
||||
type Pipe struct{}
|
||||
@ -165,7 +177,10 @@ func doRun(ctx *context.Context, brew config.Homebrew, client client.Client) err
|
||||
case context.TokenTypeGitLab:
|
||||
repo = brew.GitLab
|
||||
default:
|
||||
return ErrTokenTypeNotImplementedForBrew
|
||||
if string(ctx.TokenType) == "" {
|
||||
return ErrEmptyTokenType
|
||||
}
|
||||
return ErrTokenTypeNotImplementedForBrew{ctx.TokenType}
|
||||
}
|
||||
|
||||
var gpath = buildFormulaPath(brew.Folder, filename)
|
||||
@ -226,7 +241,8 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, tokenType context.TokenT
|
||||
|
||||
if cfg.URLTemplate == "" {
|
||||
switch tokenType {
|
||||
case context.TokenTypeGitHub:
|
||||
// we keep GitHub as default for now, in line with releases
|
||||
case context.TokenTypeGitHub, "":
|
||||
cfg.URLTemplate = fmt.Sprintf(
|
||||
"%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
ctx.Config.GitHubURLs.Download,
|
||||
@ -241,7 +257,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, tokenType context.TokenT
|
||||
ctx.Config.Release.GitLab.Name,
|
||||
)
|
||||
default:
|
||||
return result, ErrTokenTypeNotImplementedForBrew
|
||||
return result, ErrTokenTypeNotImplementedForBrew{tokenType}
|
||||
}
|
||||
}
|
||||
url, err := tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).Apply(cfg.URLTemplate)
|
||||
|
@ -643,7 +643,7 @@ func TestRunPipeNoUpload(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
||||
func TestRunEmptyTokenType(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(t, err)
|
||||
var ctx = context.New(config.Project{
|
||||
@ -675,7 +675,43 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
||||
},
|
||||
})
|
||||
client := &DummyClient{}
|
||||
assert.Equal(t, ErrTokenTypeNotImplementedForBrew, doRun(ctx, ctx.Config.Brews[0], client))
|
||||
assert.Equal(t, ErrEmptyTokenType, doRun(ctx, ctx.Config.Brews[0], client))
|
||||
}
|
||||
|
||||
func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(t, err)
|
||||
var ctx = context.New(config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Release: config.Release{},
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitea
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||
var path = filepath.Join(folder, "whatever.tar.gz")
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(t, err)
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "bin",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
"ID": "foo",
|
||||
"Format": "tar.gz",
|
||||
},
|
||||
})
|
||||
client := &DummyClient{}
|
||||
assert.Equal(t, ErrTokenTypeNotImplementedForBrew{TokenType: "gitea"}, doRun(ctx, ctx.Config.Brews[0], client))
|
||||
}
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user