You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-15 01:34:21 +02:00
refactor: unifying snapshot with skip-validate and skip-publish (#575)
* refactor: removed goreleaserlib: moved all to main * refactor: wip: snapshot * fix: more pipes * fix: more pipes * fix: git tests * fix: some other validate and publish usages * fix: git dirty check when snapshoting * fix: nfpm: use tag instead of version * test: docker: print docker run output if registry fails
This commit is contained in:
committed by
GitHub
parent
2bb509f5a8
commit
fdc032ec15
@ -14,7 +14,7 @@ install:
|
||||
- sudo snap install snapcraft --classic
|
||||
script:
|
||||
- make ci
|
||||
- test -n "$TRAVIS_TAG" || go run main.go --skip-validate --skip-publish
|
||||
- test -n "$TRAVIS_TAG" || go run main.go --snapshot
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
- test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||
|
@ -32,8 +32,6 @@ type Context struct {
|
||||
Artifacts artifact.Artifacts
|
||||
ReleaseNotes string
|
||||
Version string
|
||||
Validate bool
|
||||
Publish bool
|
||||
Snapshot bool
|
||||
RmDist bool
|
||||
Debug bool
|
||||
|
20
main.go
20
main.go
@ -9,11 +9,11 @@ import (
|
||||
|
||||
"github.com/apex/log"
|
||||
lcli "github.com/apex/log/handlers/cli"
|
||||
"github.com/caarlos0/ctrlc"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/caarlos0/ctrlc"
|
||||
"github.com/fatih/color"
|
||||
"github.com/urfave/cli"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
@ -99,21 +99,13 @@ func main() {
|
||||
Name: "release-notes",
|
||||
Usage: "Load custom release notes from a markdown `FILE`",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-validate",
|
||||
Usage: "Skip all the validations against the release",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-publish",
|
||||
Usage: "Skip all publishing pipes of the release",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "snapshot",
|
||||
Usage: "Generate an unversioned snapshot release",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "rm-dist",
|
||||
Usage: "Remove ./dist before building",
|
||||
Usage: "Remove the dist folder before building",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "parallelism, p",
|
||||
@ -184,8 +176,6 @@ func releaseProject(flags Flags) error {
|
||||
ctx.Parallelism = flags.Int("parallelism")
|
||||
ctx.Debug = flags.Bool("debug")
|
||||
log.Debugf("parallelism: %v", ctx.Parallelism)
|
||||
ctx.Validate = !flags.Bool("skip-validate")
|
||||
ctx.Publish = !flags.Bool("skip-publish")
|
||||
if notes != "" {
|
||||
bts, err := ioutil.ReadFile(notes)
|
||||
if err != nil {
|
||||
@ -196,10 +186,6 @@ func releaseProject(flags Flags) error {
|
||||
ctx.ReleaseNotes = string(bts)
|
||||
}
|
||||
ctx.Snapshot = flags.Bool("snapshot")
|
||||
if ctx.Snapshot {
|
||||
log.Info("publishing disabled in snapshot mode")
|
||||
ctx.Publish = false
|
||||
}
|
||||
ctx.RmDist = flags.Bool("rm-dist")
|
||||
return doRelease(ctx)
|
||||
}
|
||||
|
20
main_test.go
20
main_test.go
@ -24,14 +24,6 @@ func TestReleaseProject(t *testing.T) {
|
||||
assert.NoError(t, releaseProject(newFlags(t, testParams())))
|
||||
}
|
||||
|
||||
func TestSnapshotreleaseProject(t *testing.T) {
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
params := testParams()
|
||||
params["snapshot"] = "true"
|
||||
assert.NoError(t, releaseProject(newFlags(t, params)))
|
||||
}
|
||||
|
||||
func TestConfigFileIsSetAndDontExist(t *testing.T) {
|
||||
params := testParams()
|
||||
params["config"] = "/this/wont/exist"
|
||||
@ -67,12 +59,13 @@ func TestReleaseNotesFileDontExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCustomReleaseNotesFile(t *testing.T) {
|
||||
folder, back := setup(t)
|
||||
_, back := setup(t)
|
||||
defer back()
|
||||
var releaseNotes = filepath.Join(folder, "notes.md")
|
||||
createFile(t, releaseNotes, "nothing important at all")
|
||||
releaseNotes, err := ioutil.TempFile("", "")
|
||||
assert.NoError(t, err)
|
||||
createFile(t, releaseNotes.Name(), "nothing important at all")
|
||||
var params = testParams()
|
||||
params["release-notes"] = releaseNotes
|
||||
params["release-notes"] = releaseNotes.Name()
|
||||
assert.NoError(t, releaseProject(newFlags(t, params)))
|
||||
}
|
||||
|
||||
@ -154,8 +147,7 @@ func testParams() map[string]string {
|
||||
return map[string]string{
|
||||
"debug": "true",
|
||||
"parallelism": "4",
|
||||
"skip-publish": "true",
|
||||
"skip-validate": "true",
|
||||
"snapshot": "true",
|
||||
"timeout": "1m",
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context) error {
|
||||
if !ctx.Publish {
|
||||
return pipeline.ErrSkipPublish
|
||||
if ctx.Snapshot {
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
|
||||
// Handle every configured artifactory instance
|
||||
|
@ -192,7 +192,6 @@ func TestRunPipe_ModeBinary(t *testing.T) {
|
||||
"ARTIFACTORY_PRODUCTION-US_SECRET": "deployuser-secret",
|
||||
"ARTIFACTORY_PRODUCTION-EU_SECRET": "productionuser-apikey",
|
||||
}
|
||||
ctx.Publish = true
|
||||
for _, goos := range []string{"linux", "darwin"} {
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "mybin",
|
||||
@ -232,7 +231,6 @@ func TestRunPipe_ModeArchive(t *testing.T) {
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
ctx.Publish = true
|
||||
ctx.Version = "1.0.0"
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
@ -328,7 +326,6 @@ func TestRunPipe_ArtifactoryDown(t *testing.T) {
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
Name: "bin.tar.gz",
|
||||
@ -358,7 +355,6 @@ func TestRunPipe_TargetTemplateError(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -415,7 +411,6 @@ func TestRunPipe_BadCredentials(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -473,7 +468,6 @@ func TestRunPipe_UnparsableErrorResponse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -528,7 +522,6 @@ func TestRunPipe_UnparsableResponse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -556,7 +549,6 @@ func TestRunPipe_FileNotFound(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -594,7 +586,6 @@ func TestRunPipe_UnparsableTarget(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Publish = true
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
@ -623,10 +614,11 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
ctx.Snapshot = true
|
||||
|
||||
err := Pipe{}.Run(ctx)
|
||||
assert.True(t, pipeline.IsSkip(err))
|
||||
assert.EqualError(t, err, pipeline.ErrSkipPublish.Error())
|
||||
assert.EqualError(t, err, pipeline.ErrSnapshotEnabled.Error())
|
||||
}
|
||||
|
||||
func TestRunPipe_DirUpload(t *testing.T) {
|
||||
@ -652,7 +644,6 @@ func TestRunPipe_DirUpload(t *testing.T) {
|
||||
ctx.Env = map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
}
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "mybin",
|
||||
Path: filepath.Dir(binPath),
|
||||
@ -733,7 +724,6 @@ func TestArtifactoriesWithoutSecret(t *testing.T) {
|
||||
|
||||
func TestArtifactoriesWithInvalidMode(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Publish: true,
|
||||
Env: map[string]string{
|
||||
"ARTIFACTORY_PRODUCTION_SECRET": "deployuser-secret",
|
||||
},
|
||||
|
@ -122,8 +122,8 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
if ctx.Config.Brew.SkipUpload {
|
||||
return pipeline.Skip("brew.skip_upload is set")
|
||||
}
|
||||
if !ctx.Publish {
|
||||
return pipeline.ErrSkipPublish
|
||||
if ctx.Snapshot {
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
if ctx.Config.Release.Draft {
|
||||
return pipeline.Skip("release is marked as draft")
|
||||
|
@ -128,7 +128,6 @@ func TestRunPipe(t *testing.T) {
|
||||
Install: `bin.install "foo"`,
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
var path = filepath.Join(folder, "bin.tar.gz")
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
@ -212,7 +211,6 @@ func TestRunPipeNoDarwin64Build(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
assert.Equal(t, ErrNoDarwin64Build, doRun(ctx, client))
|
||||
@ -233,7 +231,6 @@ func TestRunPipeMultipleDarwin64Build(t *testing.T) {
|
||||
},
|
||||
},
|
||||
)
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "bin1",
|
||||
Path: "doesnt mather",
|
||||
@ -256,7 +253,6 @@ func TestRunPipeMultipleDarwin64Build(t *testing.T) {
|
||||
func TestRunPipeBrewNotSetup(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Publish: true,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
testlib.AssertSkipped(t, doRun(ctx, client))
|
||||
@ -277,7 +273,6 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
},
|
||||
},
|
||||
)
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "bin",
|
||||
Path: "doesnt mather",
|
||||
@ -321,16 +316,14 @@ func TestRunPipeNoUpload(t *testing.T) {
|
||||
assert.False(t, client.CreatedFile)
|
||||
}
|
||||
t.Run("skip upload", func(tt *testing.T) {
|
||||
ctx.Publish = true
|
||||
ctx.Config.Brew.SkipUpload = true
|
||||
assertNoPublish(tt)
|
||||
})
|
||||
t.Run("skip publish", func(tt *testing.T) {
|
||||
ctx.Publish = false
|
||||
t.Run("snapshot", func(tt *testing.T) {
|
||||
ctx.Snapshot = true
|
||||
assertNoPublish(tt)
|
||||
})
|
||||
t.Run("draft release", func(tt *testing.T) {
|
||||
ctx.Publish = true
|
||||
ctx.Config.Release.Draft = true
|
||||
assertNoPublish(tt)
|
||||
})
|
||||
|
@ -1,9 +1,13 @@
|
||||
// Package checksums provides a Pipe that creates .checksums files for
|
||||
// each artifact.
|
||||
package checksums
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
"github.com/apex/log"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -79,3 +83,25 @@ func checksums(ctx *context.Context, file *os.File, artifact artifact.Artifact)
|
||||
_, err = file.WriteString(fmt.Sprintf("%v %v\n", sha, artifact.Name))
|
||||
return err
|
||||
}
|
||||
|
||||
func filenameFor(ctx *context.Context) (string, error) {
|
||||
var out bytes.Buffer
|
||||
t, err := template.New("checksums").
|
||||
Option("missingkey=error").
|
||||
Parse(ctx.Config.Checksum.NameTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = t.Execute(&out, struct {
|
||||
ProjectName string
|
||||
Tag string
|
||||
Version string
|
||||
Env map[string]string
|
||||
}{
|
||||
ProjectName: ctx.Config.ProjectName,
|
||||
Tag: ctx.Git.CurrentTag,
|
||||
Version: ctx.Version,
|
||||
Env: ctx.Env,
|
||||
})
|
||||
return out.String(), err
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
// Package checksums provides a Pipe that creates .checksums files for
|
||||
// each artifact.
|
||||
package checksums
|
@ -1,30 +0,0 @@
|
||||
package checksums
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
func filenameFor(ctx *context.Context) (string, error) {
|
||||
var out bytes.Buffer
|
||||
t, err := template.New("checksums").
|
||||
Option("missingkey=error").
|
||||
Parse(ctx.Config.Checksum.NameTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = t.Execute(&out, struct {
|
||||
ProjectName string
|
||||
Tag string
|
||||
Version string
|
||||
Env map[string]string
|
||||
}{
|
||||
ProjectName: ctx.Config.ProjectName,
|
||||
Tag: ctx.Git.CurrentTag,
|
||||
Version: ctx.Version,
|
||||
Env: ctx.Env,
|
||||
})
|
||||
return out.String(), err
|
||||
}
|
@ -195,8 +195,9 @@ func link(src, dest string) error {
|
||||
}
|
||||
|
||||
func publish(ctx *context.Context, docker config.Docker, images []string) error {
|
||||
if !ctx.Publish {
|
||||
log.Warn("skipping push because --skip-publish is set")
|
||||
if ctx.Snapshot {
|
||||
// TODO: this should be better handled
|
||||
log.Warn(pipeline.ErrSnapshotEnabled.Error())
|
||||
return nil
|
||||
}
|
||||
for _, image := range images {
|
||||
|
@ -31,10 +31,10 @@ func start(t *testing.T) {
|
||||
if *it {
|
||||
return
|
||||
}
|
||||
if err := exec.Command(
|
||||
if out, err := exec.Command(
|
||||
"docker", "run", "-d", "-p", "5000:5000", "--name", "registry", "registry:2",
|
||||
).Run(); err != nil {
|
||||
t.Log("failed to start docker registry", err)
|
||||
).CombinedOutput(); err != nil {
|
||||
t.Log("failed to start docker registry", string(out), err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
@ -262,7 +262,8 @@ func TestRunPipe(t *testing.T) {
|
||||
docker.docker,
|
||||
},
|
||||
})
|
||||
ctx.Publish = docker.publish
|
||||
// TODO: ideally refactor this as well
|
||||
ctx.Snapshot = !docker.publish
|
||||
ctx.Env = map[string]string{
|
||||
"FOO": "123",
|
||||
}
|
||||
|
7
pipeline/env/env.go
vendored
7
pipeline/env/env.go
vendored
@ -35,11 +35,8 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
token, err := loadEnv("GITHUB_TOKEN", ctx.Config.EnvFiles.GitHubToken)
|
||||
ctx.Token = token
|
||||
if !ctx.Publish {
|
||||
return pipeline.Skip("publishing is disabled")
|
||||
}
|
||||
if !ctx.Validate {
|
||||
return pipeline.Skip("--skip-validate is set")
|
||||
if ctx.Snapshot {
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
if ctx.Token == "" && err == nil {
|
||||
return ErrMissingToken
|
||||
|
28
pipeline/env/env_test.go
vendored
28
pipeline/env/env_test.go
vendored
@ -38,8 +38,6 @@ func TestValidEnv(t *testing.T) {
|
||||
assert.NoError(t, os.Setenv("GITHUB_TOKEN", "asdf"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
@ -48,8 +46,6 @@ func TestInvalidEnv(t *testing.T) {
|
||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
@ -58,8 +54,6 @@ func TestEmptyFileEnv(t *testing.T) {
|
||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
@ -75,37 +69,17 @@ func TestEmptyEnvFile(t *testing.T) {
|
||||
GitHubToken: f.Name(),
|
||||
},
|
||||
},
|
||||
Validate: true,
|
||||
Publish: true,
|
||||
}
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), fmt.Sprintf("failed to load github token: open %s: permission denied", f.Name()))
|
||||
}
|
||||
|
||||
func TestInvalidEnvChecksSkipped(t *testing.T) {
|
||||
for _, flag := range []struct {
|
||||
Validate, Publish, Snapshot bool
|
||||
}{
|
||||
{
|
||||
Validate: false,
|
||||
Publish: true,
|
||||
}, {
|
||||
Validate: true,
|
||||
Publish: false,
|
||||
}, {
|
||||
Validate: true,
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("%v", flag), func(t *testing.T) {
|
||||
assert.NoError(t, os.Unsetenv("GITHUB_TOKEN"))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: flag.Validate,
|
||||
Publish: flag.Publish,
|
||||
Snapshot: flag.Snapshot,
|
||||
Snapshot: true,
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadEnv(t *testing.T) {
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -38,9 +37,6 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
if err = setVersion(ctx, tag, commit); err != nil {
|
||||
return
|
||||
}
|
||||
if !ctx.Validate {
|
||||
return pipeline.Skip("--skip-validate is set")
|
||||
}
|
||||
return validate(ctx, commit, tag)
|
||||
}
|
||||
|
||||
@ -80,13 +76,13 @@ func getSnapshotName(ctx *context.Context, tag, commit string) (string, error) {
|
||||
}
|
||||
|
||||
func validate(ctx *context.Context, commit, tag string) error {
|
||||
if ctx.Snapshot {
|
||||
return nil
|
||||
}
|
||||
out, err := git.Run("status", "--porcelain")
|
||||
if strings.TrimSpace(out) != "" || err != nil {
|
||||
return ErrDirty{out}
|
||||
}
|
||||
if ctx.Snapshot {
|
||||
return nil
|
||||
}
|
||||
if !regexp.MustCompile("^[0-9.]+").MatchString(ctx.Version) {
|
||||
return ErrInvalidVersionFormat{ctx.Version}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func TestNotAGitFolder(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), "fatal: Not a git repository (or any of the parent directories): .git\n")
|
||||
}
|
||||
|
||||
func TestSingleCommit(t *testing.T) {
|
||||
@ -34,7 +34,7 @@ func TestSingleCommit(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
}
|
||||
|
||||
@ -45,7 +45,8 @@ func TestNewRepository(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
// TODO: improve this error handling
|
||||
assert.Contains(t, Pipe{}.Run(ctx).Error(), `fatal: ambiguous argument 'HEAD'`)
|
||||
}
|
||||
|
||||
func TestNoTagsSnapshot(t *testing.T) {
|
||||
@ -53,16 +54,13 @@ func TestNoTagsSnapshot(t *testing.T) {
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
var ctx = context.New(config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: "SNAPSHOT-{{.Commit}}",
|
||||
},
|
||||
},
|
||||
Snapshot: true,
|
||||
Publish: false,
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Contains(t, ctx.Version, "SNAPSHOT-")
|
||||
}
|
||||
|
||||
@ -71,16 +69,13 @@ func TestNoTagsSnapshotInvalidTemplate(t *testing.T) {
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
var ctx = context.New(config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: "{{",
|
||||
},
|
||||
},
|
||||
Snapshot: true,
|
||||
Publish: false,
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
})
|
||||
ctx.Snapshot = true
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), `failed to generate snapshot name: template: snapshot:1: unexpected unclosed action in command`)
|
||||
}
|
||||
|
||||
// TestNoTagsNoSnapshot covers the situation where a repository
|
||||
@ -91,16 +86,9 @@ func TestNoTagsNoSnapshot(t *testing.T) {
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{
|
||||
Snapshot: config.Snapshot{
|
||||
NameTemplate: "SNAPSHOT-{{.Commit}}",
|
||||
},
|
||||
},
|
||||
Snapshot: false,
|
||||
Publish: false,
|
||||
}
|
||||
assert.Error(t, Pipe{}.Run(ctx))
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = false
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), `git doesn't contain any tags. Either add a tag or use --snapshot`)
|
||||
}
|
||||
|
||||
func TestInvalidTagFormat(t *testing.T) {
|
||||
@ -109,10 +97,7 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit2")
|
||||
testlib.GitTag(t, "sadasd")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
var ctx = context.New(config.Project{})
|
||||
assert.EqualError(t, Pipe{}.Run(ctx), "sadasd is not in a valid version format")
|
||||
assert.Equal(t, "sadasd", ctx.Git.CurrentTag)
|
||||
}
|
||||
@ -127,11 +112,7 @@ func TestDirty(t *testing.T) {
|
||||
testlib.GitCommit(t, "commit2")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
assert.NoError(t, ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
err = Pipe{}.Run(ctx)
|
||||
err = Pipe{}.Run(context.New(config.Project{}))
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git is currently in a dirty state:")
|
||||
}
|
||||
@ -143,11 +124,7 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
||||
testlib.GitCommit(t, "commit3")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit4")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
err := Pipe{}.Run(ctx)
|
||||
err := Pipe{}.Run(context.New(config.Project{}))
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
||||
}
|
||||
@ -160,39 +137,20 @@ func TestValidState(t *testing.T) {
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit4")
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
}
|
||||
var ctx = context.New(config.Project{})
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
|
||||
}
|
||||
|
||||
func TestNoValidate(t *testing.T) {
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitAdd(t)
|
||||
testlib.GitCommit(t, "commit5")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit6")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: false,
|
||||
}
|
||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestSnapshot(t *testing.T) {
|
||||
_, back := testlib.Mktmp(t)
|
||||
defer back()
|
||||
testlib.GitInit(t)
|
||||
testlib.GitAdd(t)
|
||||
testlib.GitCommit(t, "whatever")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
Validate: true,
|
||||
Snapshot: true,
|
||||
}
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.Snapshot = true
|
||||
assert.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
// TODO: missing a test case for a dirty git tree and snapshot
|
||||
|
@ -108,7 +108,7 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif
|
||||
Recommends: ctx.Config.NFPM.Recommends,
|
||||
Suggests: ctx.Config.NFPM.Suggests,
|
||||
Name: ctx.Config.ProjectName,
|
||||
Version: ctx.Version,
|
||||
Version: ctx.Git.CurrentTag,
|
||||
Section: "",
|
||||
Priority: "",
|
||||
Maintainer: ctx.Config.NFPM.Maintainer,
|
||||
|
@ -20,7 +20,9 @@ func TestDescription(t *testing.T) {
|
||||
|
||||
func TestRunPipeNoFormats(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Version: "1.0.0",
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.0",
|
||||
},
|
||||
Config: config.Project{},
|
||||
Parallelism: runtime.NumCPU(),
|
||||
}
|
||||
@ -83,7 +85,7 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Version = "1.0.0"
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||
for _, goos := range []string{"linux", "darwin"} {
|
||||
for _, goarch := range []string{"amd64", "386"} {
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
|
@ -14,9 +14,9 @@ type Piper interface {
|
||||
Run(ctx *context.Context) error
|
||||
}
|
||||
|
||||
// ErrSkipPublish happens when skip publish is set and a pipe is refusing
|
||||
// to proceed because of that.
|
||||
var ErrSkipPublish = Skip("--skip-publish is set")
|
||||
// ErrSnapshotEnabled happens when goreleaser is running in snapshot mode.
|
||||
// It usually means that publishing and maybe some validations were skipped.
|
||||
var ErrSnapshotEnabled = Skip("disabled during snapshot mode")
|
||||
|
||||
// IsSkip returns true if the error is an ErrSkip
|
||||
func IsSkip(err error) bool {
|
||||
|
@ -45,8 +45,8 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func doRun(ctx *context.Context, c client.Client) error {
|
||||
if !ctx.Publish {
|
||||
return pipeline.ErrSkipPublish
|
||||
if ctx.Snapshot {
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
log.WithField("tag", ctx.Git.CurrentTag).
|
||||
WithField("repo", ctx.Config.Release.GitHub.String()).
|
||||
|
@ -38,7 +38,6 @@ func TestRunPipe(t *testing.T) {
|
||||
}
|
||||
var ctx = context.New(config)
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
Name: "bin.tar.gz",
|
||||
@ -68,7 +67,6 @@ func TestRunPipeReleaseCreationFailed(t *testing.T) {
|
||||
}
|
||||
var ctx = context.New(config)
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||
ctx.Publish = true
|
||||
client := &DummyClient{
|
||||
FailToCreateRelease: true,
|
||||
}
|
||||
@ -88,7 +86,6 @@ func TestRunPipeWithFileThatDontExist(t *testing.T) {
|
||||
}
|
||||
var ctx = context.New(config)
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
Name: "bin.tar.gz",
|
||||
@ -115,7 +112,6 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
||||
}
|
||||
var ctx = context.New(config)
|
||||
ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"}
|
||||
ctx.Publish = true
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
Name: "bin.tar.gz",
|
||||
@ -129,9 +125,9 @@ func TestRunPipeUploadFailure(t *testing.T) {
|
||||
assert.False(t, client.UploadedFile)
|
||||
}
|
||||
|
||||
func TestSkipPublish(t *testing.T) {
|
||||
func TestSnapshot(t *testing.T) {
|
||||
var ctx = &context.Context{
|
||||
Publish: false,
|
||||
Snapshot: true,
|
||||
Parallelism: 1,
|
||||
}
|
||||
client := &DummyClient{}
|
||||
|
@ -68,8 +68,8 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !ctx.Publish {
|
||||
return pipeline.ErrSkipPublish
|
||||
if ctx.Snapshot {
|
||||
return pipeline.ErrSnapshotEnabled
|
||||
}
|
||||
if ctx.Config.Release.Draft {
|
||||
return pipeline.Skip("release is marked as draft")
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/client"
|
||||
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -108,7 +109,6 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -152,7 +152,6 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -195,7 +194,6 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -230,7 +228,6 @@ func Test_doRun(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -273,7 +270,7 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: false,
|
||||
Snapshot: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -281,7 +278,7 @@ func Test_doRun(t *testing.T) {
|
||||
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"},
|
||||
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"},
|
||||
},
|
||||
shouldErr("--skip-publish is set"),
|
||||
shouldErr(pipeline.ErrSnapshotEnabled.Error()),
|
||||
},
|
||||
{
|
||||
"is draft",
|
||||
@ -313,7 +310,6 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -353,7 +349,6 @@ func Test_doRun(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
},
|
||||
&DummyClient{},
|
||||
},
|
||||
@ -408,7 +403,6 @@ func Test_buildManifest(t *testing.T) {
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
},
|
||||
},
|
||||
Publish: true,
|
||||
}
|
||||
out, err := buildManifest(ctx, &DummyClient{}, []artifact.Artifact{
|
||||
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"},
|
||||
|
Reference in New Issue
Block a user