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

Merge pull request #203 from goreleaser/draft2

allowing draft releases
This commit is contained in:
Carlos Alexandro Becker 2017-04-21 20:41:06 -03:00 committed by GitHub
commit 3aebff9d86
5 changed files with 46 additions and 12 deletions

View File

@ -262,6 +262,10 @@ release:
github: github:
owner: user owner: user
name: repo name: repo
# If set to true, will not auto-publish the release.
# Default is false
draft: true
``` ```
You can also specify a release notes file in markdown format using the You can also specify a release notes file in markdown format using the

View File

@ -2,6 +2,7 @@ package client
import ( import (
"bytes" "bytes"
"log"
"os" "os"
"github.com/google/go-github/github" "github.com/google/go-github/github"
@ -68,34 +69,37 @@ func (c *githubClient) CreateFile(
} }
func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
data := &github.RepositoryRelease{ var release *github.RepositoryRelease
var data = &github.RepositoryRelease{
Name: github.String(ctx.Git.CurrentTag), Name: github.String(ctx.Git.CurrentTag),
TagName: github.String(ctx.Git.CurrentTag), TagName: github.String(ctx.Git.CurrentTag),
Body: github.String(body), Body: github.String(body),
Draft: github.Bool(ctx.Config.Release.Draft),
} }
r, _, err := c.client.Repositories.GetReleaseByTag( release, _, err = c.client.Repositories.GetReleaseByTag(
ctx, ctx,
ctx.Config.Release.GitHub.Owner, ctx.Config.Release.GitHub.Owner,
ctx.Config.Release.GitHub.Name, ctx.Config.Release.GitHub.Name,
ctx.Git.CurrentTag, ctx.Git.CurrentTag,
) )
if err != nil { if err != nil {
r, _, err = c.client.Repositories.CreateRelease( release, _, err = c.client.Repositories.CreateRelease(
ctx, ctx,
ctx.Config.Release.GitHub.Owner, ctx.Config.Release.GitHub.Owner,
ctx.Config.Release.GitHub.Name, ctx.Config.Release.GitHub.Name,
data, data,
) )
return r.GetID(), err } else {
release, _, err = c.client.Repositories.EditRelease(
ctx,
ctx.Config.Release.GitHub.Owner,
ctx.Config.Release.GitHub.Name,
release.GetID(),
data,
)
} }
r, _, err = c.client.Repositories.EditRelease( log.Printf("Release updated: %v\n", release.GetHTMLURL())
ctx, return release.GetID(), err
ctx.Config.Release.GitHub.Owner,
ctx.Config.Release.GitHub.Name,
r.GetID(),
data,
)
return r.GetID(), err
} }
func (c *githubClient) Upload( func (c *githubClient) Upload(

View File

@ -67,6 +67,7 @@ type Archive struct {
// Release config used for the GitHub release // Release config used for the GitHub release
type Release struct { type Release struct {
GitHub Repo GitHub Repo
Draft bool
} }
// FPM config // FPM config

View File

@ -102,6 +102,10 @@ func doRun(ctx *context.Context, client client.Client) error {
log.Println("Skipped because brew section is not configured") log.Println("Skipped because brew section is not configured")
return nil return nil
} }
if ctx.Config.Release.Draft {
log.Println("Skipped because release is marked as draft")
return nil
}
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb") path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String()) log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String())
content, err := buildFormula(ctx, client) content, err := buildFormula(ctx, client)

View File

@ -165,6 +165,27 @@ func TestRunPipeNoPublish(t *testing.T) {
assert.False(client.CreatedFile) assert.False(client.CreatedFile)
} }
func TestRunPipeDraftRelease(t *testing.T) {
assert := assert.New(t)
var ctx = &context.Context{
Publish: true,
Config: config.Project{
Release: config.Release{
Draft: true,
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
}
client := &DummyClient{}
assert.NoError(doRun(ctx, client))
assert.False(client.CreatedFile)
}
type DummyClient struct { type DummyClient struct {
CreatedFile bool CreatedFile bool
} }