mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
skip release and skip validations as separated flags
This commit is contained in:
parent
d9032917a9
commit
e10e1aa141
@ -32,6 +32,8 @@ type Context struct {
|
||||
Archives map[string]string
|
||||
Artifacts []string
|
||||
Version string
|
||||
Validate bool
|
||||
Publish bool
|
||||
}
|
||||
|
||||
var lock sync.Mutex
|
||||
|
57
main.go
57
main.go
@ -25,6 +25,22 @@ var (
|
||||
date = "unknown"
|
||||
)
|
||||
|
||||
var pipes = []pipeline.Pipe{
|
||||
defaults.Pipe{}, // load default configs
|
||||
git.Pipe{}, // get and validate git repo state
|
||||
env.Pipe{}, // load and validate environment variables
|
||||
build.Pipe{}, // build
|
||||
archive.Pipe{}, // archive (tar.gz, zip, etc)
|
||||
fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
|
||||
checksums.Pipe{}, // checksums of the files
|
||||
release.Pipe{}, // release to github
|
||||
brew.Pipe{}, // push to brew tap
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var app = cli.NewApp()
|
||||
app.Name = "goreleaser"
|
||||
@ -37,8 +53,12 @@ func main() {
|
||||
Value: "goreleaser.yml",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "build-only, skip-release, no-release, nr",
|
||||
Usage: "Skip all the release processes and run only the build and packaging steps",
|
||||
Name: "skip-validate",
|
||||
Usage: "Skip all the validations against the release",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-publish",
|
||||
Usage: "Skip all publishing pipes of the release",
|
||||
},
|
||||
}
|
||||
app.Action = func(c *cli.Context) (err error) {
|
||||
@ -53,8 +73,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
var ctx = context.New(cfg)
|
||||
log.SetFlags(0)
|
||||
for _, pipe := range pipes(c.Bool("build-only")) {
|
||||
ctx.Validate = !c.Bool("skip-validate")
|
||||
ctx.Publish = !c.Bool("skip-publish")
|
||||
for _, pipe := range pipes {
|
||||
log.Println(pipe.Description())
|
||||
log.SetPrefix(" -> ")
|
||||
if err := pipe.Run(ctx); err != nil {
|
||||
@ -69,31 +90,3 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func pipes(buildOnly bool) []pipeline.Pipe {
|
||||
var pipes = []pipeline.Pipe{
|
||||
defaults.Pipe{}, // load default configs
|
||||
}
|
||||
if !buildOnly {
|
||||
pipes = append(
|
||||
pipes,
|
||||
git.Pipe{}, // get and validate git repo state
|
||||
env.Pipe{}, // load and validate environment variables
|
||||
)
|
||||
}
|
||||
pipes = append(
|
||||
pipes,
|
||||
build.Pipe{}, // build
|
||||
archive.Pipe{}, // archive (tar.gz, zip, etc)
|
||||
fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
|
||||
checksums.Pipe{}, // checksums of the files
|
||||
)
|
||||
if !buildOnly {
|
||||
pipes = append(
|
||||
pipes,
|
||||
release.Pipe{}, // release to github
|
||||
brew.Pipe{}, // push to brew tap
|
||||
)
|
||||
}
|
||||
return pipes
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
Name: ss[1],
|
||||
}
|
||||
}
|
||||
if ctx.Config.Brew.GitHub.Name == "" {
|
||||
if ctx.Config.Brew.GitHub.Name == "" || !ctx.Publish {
|
||||
return nil
|
||||
}
|
||||
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb")
|
||||
|
@ -109,6 +109,7 @@ func TestRunPipe(t *testing.T) {
|
||||
Archives: map[string]string{
|
||||
"darwinamd64": "bin",
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.NoError(doRun(ctx, client))
|
||||
@ -129,6 +130,7 @@ func TestRunPipeBrewNotSetup(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.Equal(ErrNoDarwin64Build, doRun(ctx, client))
|
||||
@ -143,6 +145,16 @@ func TestRunPipeNoDarwinBuild(t *testing.T) {
|
||||
assert.False(client.CreatedFile)
|
||||
}
|
||||
|
||||
func TestRunPipeNoPublish(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: false,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.NoError(doRun(ctx, client))
|
||||
assert.False(client.CreatedFile)
|
||||
}
|
||||
|
||||
type DummyClient struct {
|
||||
CreatedFile bool
|
||||
}
|
||||
|
3
pipeline/env/env.go
vendored
3
pipeline/env/env.go
vendored
@ -22,6 +22,9 @@ func (Pipe) Description() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
if !ctx.Validate {
|
||||
return nil
|
||||
}
|
||||
ctx.Token = os.Getenv("GITHUB_TOKEN")
|
||||
if ctx.Token == "" {
|
||||
return ErrMissingToken
|
||||
|
15
pipeline/env/env_test.go
vendored
15
pipeline/env/env_test.go
vendored
@ -17,7 +17,8 @@ func TestValidEnv(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
}
|
||||
@ -26,7 +27,17 @@ func TestInvalidEnv(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert.NoError(os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
assert.Error(Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestSkipValidate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: false,
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
}
|
||||
|
@ -59,6 +59,9 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
}
|
||||
// removes usual `v` prefix
|
||||
ctx.Version = strings.TrimPrefix(tag, "v")
|
||||
if !ctx.Validate {
|
||||
return nil
|
||||
}
|
||||
return validate(commit, tag, ctx.Version)
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,8 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
gitCommit(t, "commit2")
|
||||
gitTag(t, "sadasd")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
assert.EqualError(Pipe{}.Run(ctx), "sadasd is not in a valid version format")
|
||||
assert.Equal("sadasd", ctx.Git.CurrentTag)
|
||||
@ -76,7 +77,8 @@ func TestDirty(t *testing.T) {
|
||||
gitTag(t, "v0.0.1")
|
||||
assert.NoError(ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
@ -92,13 +94,30 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit4")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
err := Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "git tag v0.0.1 was not made against commit")
|
||||
}
|
||||
|
||||
func TestNoValidate(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := createAndChdir(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitAdd(t)
|
||||
gitCommit(t, "commit5")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit6")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: false,
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
|
@ -26,6 +26,9 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context, client client.Client) error {
|
||||
if !ctx.Publish {
|
||||
return nil
|
||||
}
|
||||
log.Println("Creating or updating release", ctx.Git.CurrentTag, "on", ctx.Config.Release.GitHub.String())
|
||||
releaseID, err := client.CreateRelease(ctx)
|
||||
if err != nil {
|
||||
|
@ -39,6 +39,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
ctx.AddArtifact(tarfile.Name())
|
||||
ctx.AddArtifact(debfile.Name())
|
||||
@ -62,6 +63,7 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{
|
||||
FailToCreateRelease: true,
|
||||
@ -85,6 +87,7 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
ctx.AddArtifact("this-file-wont-exist-hopefuly")
|
||||
client := &DummyClient{}
|
||||
@ -112,6 +115,7 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
ctx.AddArtifact(tarfile.Name())
|
||||
client := &DummyClient{
|
||||
@ -122,6 +126,17 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
||||
assert.False(client.UploadedFile)
|
||||
}
|
||||
|
||||
func TestSkipPublish(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var ctx = &context.Context{
|
||||
Publish: false,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.NoError(doRun(ctx, client))
|
||||
assert.False(client.CreatedRelease)
|
||||
assert.False(client.UploadedFile)
|
||||
}
|
||||
|
||||
type DummyClient struct {
|
||||
FailToCreateRelease bool
|
||||
FailToUpload bool
|
||||
|
Loading…
x
Reference in New Issue
Block a user