diff --git a/.gitignore b/.gitignore index 0cc6ddfa7..5985e6dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist/ vendor coverage.txt goreleaser +.idea/ diff --git a/config/config.go b/config/config.go index e293781c7..883d53dc0 100644 --- a/config/config.go +++ b/config/config.go @@ -15,10 +15,11 @@ import ( // Repo represents any kind of repo (github, gitlab, etc) type Repo struct { - Owner string `yaml:",omitempty"` - Name string `yaml:",omitempty"` - APIURL string `yaml:api_url",omitempty"` - UploadsURL string `yaml:uploads_url",omitempty"` + Owner string `yaml:",omitempty"` + Name string `yaml:",omitempty"` + APIURL string `yaml:"api_url,omitempty"` + UploadsURL string `yaml:"uploads_url,omitempty"` + DownloadsURL string `yaml:"downloads_url,omitempty"` // Capture all undefined fields and should be empty after loading XXX map[string]interface{} `yaml:",inline"` diff --git a/docs/115-release.md b/docs/115-release.md index 10ae7e288..09896b6a9 100644 --- a/docs/115-release.md +++ b/docs/115-release.md @@ -16,6 +16,11 @@ release: github: owner: user name: repo + # endpoint urls for enterprise github. + # Default is github.com. + api_url: github api endpoint + uploads_url: github file uploads url + download_url github download url # If set to true, will not auto-publish the release. # Default is false diff --git a/docs/120-homebrew.md b/docs/120-homebrew.md index 183cd3dca..d7f8770eb 100644 --- a/docs/120-homebrew.md +++ b/docs/120-homebrew.md @@ -19,6 +19,11 @@ brew: github: owner: user name: homebrew-tap + # endpoint urls for enterprise github. + # Default is github.com. + api_url: github api endpoint + uploads_url: github file uploads url + download_url github download url # Folder inside the repository to put the formula. # Default is the root folder. diff --git a/internal/client/github.go b/internal/client/github.go index 8daf09c06..c1bff213c 100644 --- a/internal/client/github.go +++ b/internal/client/github.go @@ -7,6 +7,7 @@ import ( "github.com/apex/log" "github.com/google/go-github/github" + "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "golang.org/x/oauth2" ) @@ -16,25 +17,26 @@ type githubClient struct { } // NewGitHub returns a github client implementation -func NewGitHub(ctx *context.Context, api, upload string) (Client, error) { +func NewGitHub(ctx *context.Context, repo config.Repo) (Client, error) { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: ctx.Token}, ) client := github.NewClient(oauth2.NewClient(ctx, ts)) - if api != "" { - apiURL, err := url.Parse(api) + if repo.ApiURL != "" { + url, err := url.Parse(repo.ApiURL) if err != nil { return &githubClient{}, err } - client.BaseURL = apiURL + client.BaseURL = url } - if upload != "" { - uploadURL, err := url.Parse(upload) + if repo.UploadsURL != "" { + url, err := url.Parse(repo.UploadsURL) if err != nil { return &githubClient{}, err } - client.UploadURL = uploadURL + client.UploadURL = url } + return &githubClient{client}, nil } diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index f8ca7e65a..c0e56630f 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -33,7 +33,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - client, err := client.NewGitHub(ctx, ctx.Config.Brew.GitHub.APIURL, ctx.Config.Brew.GitHub.UploadsURL) + client, err := client.NewGitHub(ctx, ctx.Config.Brew.GitHub) if err != nil { return err } diff --git a/pipeline/brew/template.go b/pipeline/brew/template.go index 87e5b74de..9c50b5a74 100644 --- a/pipeline/brew/template.go +++ b/pipeline/brew/template.go @@ -22,7 +22,13 @@ type templateData struct { const formulaTemplate = `class {{ .Name }} < Formula desc "{{ .Desc }}" homepage "{{ .Homepage }}" - url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + + {{ if .Repo.DownloadURL }} + url "{{ .Repo.DownloadURL }}{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + {{ else }} + url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + {{ end }} + version "{{ .Version }}" sha256 "{{ .SHA256 }}" diff --git a/pipeline/docker/docker.go b/pipeline/docker/docker.go index 28a6dd089..b6bb9e011 100644 --- a/pipeline/docker/docker.go +++ b/pipeline/docker/docker.go @@ -80,7 +80,7 @@ func process(ctx *context.Context, folder string, docker config.Docker, binary c } } - // TODO: improve this so it can log into to stdout + // TODO: improve this so it can log it to stdout if !ctx.Publish { return pipeline.Skip("--skip-publish is set") } @@ -90,13 +90,14 @@ func process(ctx *context.Context, folder string, docker config.Docker, binary c if err := dockerPush(image); err != nil { return err } - if docker.Latest { - if err := dockerTag(image, latest); err != nil { - return err - } - } ctx.AddDocker(image) - return nil + if !docker.Latest { + return nil + } + if err := dockerTag(image, latest); err != nil { + return err + } + return dockerPush(latest) } func dockerBuild(root, dockerfile, image string) error { diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 0740a09d4..542c348c0 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -23,7 +23,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - client, err := client.NewGitHub(ctx, ctx.Config.Release.GitHub.APIURL, ctx.Config.Release.GitHub.UploadsURL) + client, err := client.NewGitHub(ctx, ctx.Config.Release.GitHub) if err != nil { return err }