1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-28 04:44:34 +02:00

Merge branch 'master' into lint

This commit is contained in:
Carlos Alexandro Becker 2017-09-27 08:43:52 -03:00 committed by GitHub
commit fe36819fe7
8 changed files with 80 additions and 21 deletions

View File

@ -13,6 +13,13 @@ import (
yaml "gopkg.in/yaml.v2"
)
// GitHubURLs holds the URLs to be used when using github enterprise
type GitHubURLs struct {
API string `yaml:"api,omitempty"`
Upload string `yaml:"upload,omitempty"`
Download string `yaml:"download,omitempty"`
}
// Repo represents any kind of repo (github, gitlab, etc)
type Repo struct {
Owner string `yaml:",omitempty"`
@ -190,6 +197,9 @@ type Project struct {
// this is a hack ¯\_(ツ)_/¯
SingleBuild Build `yaml:"build,omitempty"`
// should be set if using github enterprise
GitHubURLs GitHubURLs `yaml:"github_urls,omitempty"`
// test only property indicating the path to the dist folder
Dist string `yaml:"-"`

View File

@ -0,0 +1,16 @@
---
title: GitHub Enterprise Support
---
You can use GitHub Enteprise within GoReleaser by providing its URLs in
the `.goreleaer.yml` configuration file:
```yaml
# .goreleaser.yml
github_urls:
api: api.github.foo.bar
upload: uploads.github.foo.bar
download: github.foo.bar
```
If none is set, it will default to the public GitHub's URLs.

View File

@ -2,6 +2,7 @@ package client
import (
"bytes"
"net/url"
"os"
"github.com/apex/log"
@ -15,13 +16,25 @@ type githubClient struct {
}
// NewGitHub returns a github client implementation
func NewGitHub(ctx *context.Context) Client {
func NewGitHub(ctx *context.Context) (Client, error) {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ctx.Token},
)
return &githubClient{
client: github.NewClient(oauth2.NewClient(ctx, ts)),
client := github.NewClient(oauth2.NewClient(ctx, ts))
if ctx.Config.GitHubURLs.API != "" {
api, err := url.Parse(ctx.Config.GitHubURLs.API)
if err != nil {
return &githubClient{}, err
}
upload, err := url.Parse(ctx.Config.GitHubURLs.Upload)
if err != nil {
return &githubClient{}, err
}
client.BaseURL = api
client.UploadURL = upload
}
return &githubClient{client}, nil
}
func (c *githubClient) CreateFile(

View File

@ -33,7 +33,11 @@ func (Pipe) Description() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
return doRun(ctx, client.NewGitHub(ctx))
client, err := client.NewGitHub(ctx)
if err != nil {
return err
}
return doRun(ctx, client)
}
func doRun(ctx *context.Context, client client.Client) error {
@ -93,8 +97,13 @@ func dataFor(ctx *context.Context, client client.Client, folder string) (result
if err != nil {
return
}
var url = "https://github.com"
if ctx.Config.GitHubURLs.Download != "" {
url = ctx.Config.GitHubURLs.Download
}
return templateData{
Name: formulaNameFor(ctx.Config.ProjectName),
DownloadURL: url,
Desc: ctx.Config.Brew.Description,
Homepage: ctx.Config.Brew.Homepage,
Repo: ctx.Config.Release.GitHub,

View File

@ -30,9 +30,10 @@ func TestSimpleName(t *testing.T) {
}
var defaultTemplateData = templateData{
Desc: "Some desc",
Homepage: "https://google.com",
Name: "Test",
Desc: "Some desc",
Homepage: "https://google.com",
DownloadURL: "https://github.com",
Name: "Test",
Repo: config.Repo{
Owner: "caarlos0",
Name: "test",
@ -45,10 +46,10 @@ var defaultTemplateData = templateData{
func assertDefaultTemplateData(t *testing.T, formulae string) {
assert.Contains(t, formulae, "class Test < Formula")
assert.Contains(t, formulae, "homepage \"https://google.com\"")
assert.Contains(t, formulae, "url \"https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz\"")
assert.Contains(t, formulae, "sha256 \"1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68\"")
assert.Contains(t, formulae, "version \"0.1.3\"")
assert.Contains(t, formulae, `homepage "https://google.com"`)
assert.Contains(t, formulae, `url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`)
assert.Contains(t, formulae, `sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`)
assert.Contains(t, formulae, `version "0.1.3"`)
}
func TestFullFormulae(t *testing.T) {
@ -63,11 +64,10 @@ func TestFullFormulae(t *testing.T) {
assert.NoError(t, err)
formulae := out.String()
f, err := os.Open("testdata/test.rb")
bts, err := ioutil.ReadFile("testdata/test.rb")
assert.NoError(t, err)
bts, err := ioutil.ReadAll(f)
assert.NoError(t, err)
// ioutil.WriteFile("testdata/test.rb", []byte(formulae), 0644)
assert.Equal(t, string(bts), formulae)
}
@ -100,6 +100,12 @@ func TestRunPipe(t *testing.T) {
Archive: config.Archive{
Format: "tar.gz",
},
Release: config.Release{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
@ -128,10 +134,10 @@ func TestRunPipe(t *testing.T) {
assert.NoError(t, doRun(ctx, client))
assert.True(t, client.CreatedFile)
f, err := os.Open("testdata/run_pipe.rb")
assert.NoError(t, err)
bts, err := ioutil.ReadAll(f)
bts, err := ioutil.ReadFile("testdata/run_pipe.rb")
assert.NoError(t, err)
// assert.NoError(ioutil.WriteFile("testdata/run_pipe.rb", []byte(client.Content), 0644))
assert.Equal(t, string(bts), client.Content)
}

View File

@ -6,6 +6,7 @@ type templateData struct {
Name string
Desc string
Homepage string
DownloadURL string
Repo config.Repo // FIXME: will not work for anything but github right now.
Tag string
Version string
@ -22,7 +23,7 @@ type templateData struct {
const formulaTemplate = `class {{ .Name }} < Formula
desc "{{ .Desc }}"
homepage "{{ .Homepage }}"
url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
url "{{ .DownloadURL }}/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}"
version "{{ .Version }}"
sha256 "{{ .SHA256 }}"

View File

@ -1,7 +1,7 @@
class RunPipe < Formula
desc "A run pipe test formula"
homepage "https://github.com/goreleaser"
url "https://github.com///releases/download/v1.0.1/bin.tar.gz"
url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz"
version "1.0.1"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

View File

@ -23,7 +23,11 @@ func (Pipe) Description() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
return doRun(ctx, client.NewGitHub(ctx))
client, err := client.NewGitHub(ctx)
if err != nil {
return err
}
return doRun(ctx, client)
}
func doRun(ctx *context.Context, client client.Client) error {