Skip to content

Commit

Permalink
fix(pipe/brew): Default to GitHub (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed May 3, 2020
1 parent 39a7dc2 commit 6f8db25
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
24 changes: 20 additions & 4 deletions internal/pipe/brew/brew.go
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
38 changes: 37 additions & 1 deletion internal/pipe/brew/brew_test.go
Expand Up @@ -643,6 +643,41 @@ func TestRunPipeNoUpload(t *testing.T) {
})
}

func TestRunEmptyTokenType(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.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, ErrEmptyTokenType, doRun(ctx, ctx.Config.Brews[0], client))
}

func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(t, err)
Expand All @@ -659,6 +694,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
},
},
})
ctx.TokenType = context.TokenTypeGitea
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
var path = filepath.Join(folder, "whatever.tar.gz")
_, err = os.Create(path)
Expand All @@ -675,7 +711,7 @@ func TestRunTokenTypeNotImplementedForBrew(t *testing.T) {
},
})
client := &DummyClient{}
assert.Equal(t, ErrTokenTypeNotImplementedForBrew, doRun(ctx, ctx.Config.Brews[0], client))
assert.Equal(t, ErrTokenTypeNotImplementedForBrew{TokenType: "gitea"}, doRun(ctx, ctx.Config.Brews[0], client))
}

func TestDefault(t *testing.T) {
Expand Down

0 comments on commit 6f8db25

Please sign in to comment.