1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

Merge branch 'pull-369' into github-enterprise

This commit is contained in:
Carlos Alexandro Becker 2017-09-24 14:17:31 -03:00
commit 632d206848
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
9 changed files with 42 additions and 21 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ dist/
vendor
coverage.txt
goreleaser
.idea/

View File

@ -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"`

View File

@ -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

View File

@ -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.

View File

@ -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
}

View File

@ -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
}

View File

@ -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 }}"

View File

@ -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 {

View File

@ -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
}