1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-09-16 09:26:52 +02:00

refactor: better package organization

This commit is contained in:
Carlos Alexandro Becker
2018-09-12 14:18:01 -03:00
parent e9cc0c9780
commit 39de856eb4
97 changed files with 1079 additions and 1117 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
dist/ dist/
!internal/pipeline/dist !internal/pipe/dist
bin/ bin/
vendor vendor
coverage.txt coverage.txt

View File

@@ -76,7 +76,7 @@ serve:
depgraph: depgraph:
go get github.com/kisielk/godepgraph go get github.com/kisielk/godepgraph
godepgraph -horizontal -s -o github.com/goreleaser github.com/goreleaser/goreleaser | dot -Tsvg -o www/static/deps.svg godepgraph -horizontal -s -o github.com/goreleaser/goreleaser . | dot -Tsvg -o www/static/deps.svg
.PHONY: depgraph .PHONY: depgraph
# Show to-do items per file. # Show to-do items per file.

View File

@@ -15,7 +15,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
@@ -102,7 +102,7 @@ func CheckConfig(ctx *context.Context, put *config.Put, kind string) error {
} }
func misconfigured(kind string, upload *config.Put, reason string) error { func misconfigured(kind string, upload *config.Put, reason string) error {
return pipeline.Skip(fmt.Sprintf("%s section '%s' is not configured properly (%s)", kind, upload.Name, reason)) return pipe.Skip(fmt.Sprintf("%s section '%s' is not configured properly (%s)", kind, upload.Name, reason))
} }
// ResponseChecker is a function capable of validating an http server response. // ResponseChecker is a function capable of validating an http server response.
@@ -112,7 +112,7 @@ type ResponseChecker func(*h.Response) error
// Upload does the actual uploading work // Upload does the actual uploading work
func Upload(ctx *context.Context, puts []config.Put, kind string, check ResponseChecker) error { func Upload(ctx *context.Context, puts []config.Put, kind string, check ResponseChecker) error {
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
// Handle every configured put // Handle every configured put

View File

@@ -8,7 +8,7 @@ import (
h "net/http" h "net/http"
"github.com/goreleaser/goreleaser/internal/http" "github.com/goreleaser/goreleaser/internal/http"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -53,14 +53,14 @@ func (Pipe) Default(ctx *context.Context) error {
// Docs: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-Example-DeployinganArtifact // Docs: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-Example-DeployinganArtifact
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.Artifactories) == 0 { if len(ctx.Config.Artifactories) == 0 {
return pipeline.Skip("artifactory section is not configured") return pipe.Skip("artifactory section is not configured")
} }
// Check requirements for every instance we have configured. // Check requirements for every instance we have configured.
// If not fulfilled, we can skip this pipeline // If not fulfilled, we can skip this pipeline
for _, instance := range ctx.Config.Artifactories { for _, instance := range ctx.Config.Artifactories {
if skip := http.CheckConfig(ctx, &instance, "artifactory"); skip != nil { if skip := http.CheckConfig(ctx, &instance, "artifactory"); skip != nil {
return pipeline.Skip(skip.Error()) return pipe.Skip(skip.Error())
} }
} }

View File

@@ -11,7 +11,7 @@ import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -620,8 +620,8 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
ctx.SkipPublish = true ctx.SkipPublish = true
err := Pipe{}.Run(ctx) err := Pipe{}.Run(ctx)
assert.True(t, pipeline.IsSkip(err)) assert.True(t, pipe.IsSkip(err))
assert.EqualError(t, err, pipeline.ErrSkipPublishEnabled.Error()) assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
} }
func TestRunPipe_DirUpload(t *testing.T) { func TestRunPipe_DirUpload(t *testing.T) {
@@ -663,7 +663,7 @@ func TestDescription(t *testing.T) {
} }
func TestNoArtifactories(t *testing.T) { func TestNoArtifactories(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{})))) assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
} }
func TestArtifactoriesWithoutTarget(t *testing.T) { func TestArtifactoriesWithoutTarget(t *testing.T) {
@@ -681,7 +681,7 @@ func TestArtifactoriesWithoutTarget(t *testing.T) {
}, },
} }
assert.True(t, pipeline.IsSkip(Pipe{}.Run(ctx))) assert.True(t, pipe.IsSkip(Pipe{}.Run(ctx)))
} }
func TestArtifactoriesWithoutUsername(t *testing.T) { func TestArtifactoriesWithoutUsername(t *testing.T) {
@@ -699,11 +699,11 @@ func TestArtifactoriesWithoutUsername(t *testing.T) {
}, },
} }
assert.True(t, pipeline.IsSkip(Pipe{}.Run(ctx))) assert.True(t, pipe.IsSkip(Pipe{}.Run(ctx)))
} }
func TestArtifactoriesWithoutName(t *testing.T) { func TestArtifactoriesWithoutName(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{ assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
Artifactories: []config.Put{ Artifactories: []config.Put{
{ {
Username: "deployuser", Username: "deployuser",
@@ -714,7 +714,7 @@ func TestArtifactoriesWithoutName(t *testing.T) {
} }
func TestArtifactoriesWithoutSecret(t *testing.T) { func TestArtifactoriesWithoutSecret(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{ assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
Artifactories: []config.Put{ Artifactories: []config.Put{
{ {
Name: "production", Name: "production",

View File

@@ -13,7 +13,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client" "github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
@@ -89,10 +89,10 @@ func contains(ss []string, s string) bool {
func doRun(ctx *context.Context, client client.Client) error { func doRun(ctx *context.Context, client client.Client) error {
if ctx.Config.Brew.GitHub.Name == "" { if ctx.Config.Brew.GitHub.Name == "" {
return pipeline.Skip("brew section is not configured") return pipe.Skip("brew section is not configured")
} }
if getFormat(ctx) == "binary" { if getFormat(ctx) == "binary" {
return pipeline.Skip("archive format is binary") return pipe.Skip("archive format is binary")
} }
var archives = ctx.Artifacts.Filter( var archives = ctx.Artifacts.Filter(
@@ -123,13 +123,13 @@ func doRun(ctx *context.Context, client client.Client) error {
} }
if ctx.Config.Brew.SkipUpload { if ctx.Config.Brew.SkipUpload {
return pipeline.Skip("brew.skip_upload is set") return pipe.Skip("brew.skip_upload is set")
} }
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
if ctx.Config.Release.Draft { if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft") return pipe.Skip("release is marked as draft")
} }
path = filepath.Join(ctx.Config.Brew.Folder, filename) path = filepath.Join(ctx.Config.Brew.Folder, filename)

View File

@@ -13,7 +13,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/git" "github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -30,10 +30,10 @@ func (Pipe) String() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if ctx.ReleaseNotes != "" { if ctx.ReleaseNotes != "" {
return pipeline.Skip("release notes already provided via --release-notes") return pipe.Skip("release notes already provided via --release-notes")
} }
if ctx.Snapshot { if ctx.Snapshot {
return pipeline.Skip("not available for snapshots") return pipe.Skip("not available for snapshots")
} }
if err := checkSortDirection(ctx.Config.Changelog.Sort); err != nil { if err := checkSortDirection(ctx.Config.Changelog.Sort); err != nil {
return err return err

View File

@@ -6,21 +6,21 @@ import (
"fmt" "fmt"
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/pipeline/archive" "github.com/goreleaser/goreleaser/internal/pipe/archive"
"github.com/goreleaser/goreleaser/internal/pipeline/artifactory" "github.com/goreleaser/goreleaser/internal/pipe/artifactory"
"github.com/goreleaser/goreleaser/internal/pipeline/brew" "github.com/goreleaser/goreleaser/internal/pipe/brew"
"github.com/goreleaser/goreleaser/internal/pipeline/build" "github.com/goreleaser/goreleaser/internal/pipe/build"
"github.com/goreleaser/goreleaser/internal/pipeline/checksums" "github.com/goreleaser/goreleaser/internal/pipe/checksums"
"github.com/goreleaser/goreleaser/internal/pipeline/docker" "github.com/goreleaser/goreleaser/internal/pipe/docker"
"github.com/goreleaser/goreleaser/internal/pipeline/env" "github.com/goreleaser/goreleaser/internal/pipe/env"
"github.com/goreleaser/goreleaser/internal/pipeline/nfpm" "github.com/goreleaser/goreleaser/internal/pipe/nfpm"
"github.com/goreleaser/goreleaser/internal/pipeline/project" "github.com/goreleaser/goreleaser/internal/pipe/project"
"github.com/goreleaser/goreleaser/internal/pipeline/release" "github.com/goreleaser/goreleaser/internal/pipe/release"
"github.com/goreleaser/goreleaser/internal/pipeline/s3" "github.com/goreleaser/goreleaser/internal/pipe/s3"
"github.com/goreleaser/goreleaser/internal/pipeline/scoop" "github.com/goreleaser/goreleaser/internal/pipe/scoop"
"github.com/goreleaser/goreleaser/internal/pipeline/sign" "github.com/goreleaser/goreleaser/internal/pipe/sign"
"github.com/goreleaser/goreleaser/internal/pipeline/snapcraft" "github.com/goreleaser/goreleaser/internal/pipe/snapcraft"
"github.com/goreleaser/goreleaser/internal/pipeline/snapshot" "github.com/goreleaser/goreleaser/internal/pipe/snapshot"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )

View File

@@ -13,7 +13,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
@@ -60,7 +60,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.Dockers) == 0 || ctx.Config.Dockers[0].Image == "" { if len(ctx.Config.Dockers) == 0 || ctx.Config.Dockers[0].Image == "" {
return pipeline.Skip("docker section is not configured") return pipe.Skip("docker section is not configured")
} }
_, err := exec.LookPath("docker") _, err := exec.LookPath("docker")
if err != nil { if err != nil {
@@ -165,12 +165,12 @@ func link(src, dest string) error {
func publish(ctx *context.Context, docker config.Docker, images []string) error { func publish(ctx *context.Context, docker config.Docker, images []string) error {
if ctx.SkipPublish { if ctx.SkipPublish {
// TODO: this should be better handled // TODO: this should be better handled
log.Warn(pipeline.ErrSkipPublishEnabled.Error()) log.Warn(pipe.ErrSkipPublishEnabled.Error())
return nil return nil
} }
if docker.SkipPush { if docker.SkipPush {
// TODO: this should also be better handled // TODO: this should also be better handled
log.Warn(pipeline.Skip("skip_push is set").Error()) log.Warn(pipe.Skip("skip_push is set").Error())
return nil return nil
} }
for _, image := range images { for _, image := range images {

View File

@@ -10,7 +10,7 @@ import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -420,11 +420,11 @@ func TestDescription(t *testing.T) {
} }
func TestNoDockers(t *testing.T) { func TestNoDockers(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{})))) assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
} }
func TestNoDockerWithoutImageName(t *testing.T) { func TestNoDockerWithoutImageName(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{ assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
Dockers: []config.Docker{ Dockers: []config.Docker{
{ {
Goos: "linux", Goos: "linux",

View File

@@ -6,7 +6,7 @@ import (
"bufio" "bufio"
"os" "os"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
homedir "github.com/mitchellh/go-homedir" homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -36,10 +36,10 @@ func (Pipe) Run(ctx *context.Context) error {
token, err := loadEnv("GITHUB_TOKEN", ctx.Config.EnvFiles.GitHubToken) token, err := loadEnv("GITHUB_TOKEN", ctx.Config.EnvFiles.GitHubToken)
ctx.Token = token ctx.Token = token
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
if ctx.Config.Release.Disable { if ctx.Config.Release.Disable {
return pipeline.Skip("release pipe is disabled") return pipe.Skip("release pipe is disabled")
} }
if ctx.Token == "" && err == nil { if ctx.Token == "" && err == nil {
return ErrMissingToken return ErrMissingToken

View File

@@ -8,7 +8,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/git" "github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -96,10 +96,10 @@ func setVersion(ctx *context.Context) error {
func validate(ctx *context.Context) error { func validate(ctx *context.Context) error {
if ctx.Snapshot { if ctx.Snapshot {
return pipeline.ErrSnapshotEnabled return pipe.ErrSnapshotEnabled
} }
if ctx.SkipValidate { if ctx.SkipValidate {
return pipeline.ErrSkipValidateEnabled return pipe.ErrSkipValidateEnabled
} }
out, err := git.Run("status", "--porcelain") out, err := git.Run("status", "--porcelain")
if strings.TrimSpace(out) != "" || err != nil { if strings.TrimSpace(out) != "" || err != nil {

View File

@@ -17,7 +17,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/linux" "github.com/goreleaser/goreleaser/internal/linux"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
@@ -51,7 +51,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.NFPM.Formats) == 0 { if len(ctx.Config.NFPM.Formats) == 0 {
return pipeline.Skip("no output formats configured") return pipe.Skip("no output formats configured")
} }
return doRun(ctx) return doRun(ctx)
} }

39
internal/pipe/pipe.go Normal file
View File

@@ -0,0 +1,39 @@
// Package pipe provides generic erros for pipes to use.
package pipe
// 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")
// ErrSkipPublishEnabled happens if --skip-publish is set.
// It means that the part of a Piper that publishes its artifacts was not run.
var ErrSkipPublishEnabled = Skip("publishing is disabled")
// ErrSkipSignEnabled happens if --skip-sign is set.
// It means that the part of a Piper that signs some things was not run.
var ErrSkipSignEnabled = Skip("artifact signing is disabled")
// ErrSkipValidateEnabled happens if --skip-validate is set.
// It means that the part of a Piper that validates some things was not run.
var ErrSkipValidateEnabled = Skip("validation is disabled")
// IsSkip returns true if the error is an ErrSkip
func IsSkip(err error) bool {
_, ok := err.(ErrSkip)
return ok
}
// ErrSkip occurs when a pipe is skipped for some reason
type ErrSkip struct {
reason string
}
// Error implements the error interface. returns the reason the pipe was skipped
func (e ErrSkip) Error() string {
return e.reason
}
// Skip skips this pipe with the given reason
func Skip(reason string) ErrSkip {
return ErrSkip{reason: reason}
}

View File

@@ -1,4 +1,4 @@
package pipeline package pipe
import ( import (
"errors" "errors"

View File

@@ -5,7 +5,7 @@ import (
h "net/http" h "net/http"
"github.com/goreleaser/goreleaser/internal/http" "github.com/goreleaser/goreleaser/internal/http"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -27,14 +27,14 @@ func (Pipe) Default(ctx *context.Context) error {
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.Puts) == 0 { if len(ctx.Config.Puts) == 0 {
return pipeline.Skip("put section is not configured") return pipe.Skip("put section is not configured")
} }
// Check requirements for every instance we have configured. // Check requirements for every instance we have configured.
// If not fulfilled, we can skip this pipeline // If not fulfilled, we can skip this pipeline
for _, instance := range ctx.Config.Puts { for _, instance := range ctx.Config.Puts {
if skip := http.CheckConfig(ctx, &instance, "put"); skip != nil { if skip := http.CheckConfig(ctx, &instance, "put"); skip != nil {
return pipeline.Skip(skip.Error()) return pipe.Skip(skip.Error())
} }
} }

View File

@@ -11,7 +11,7 @@ import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -404,8 +404,8 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
ctx.SkipPublish = true ctx.SkipPublish = true
err := Pipe{}.Run(ctx) err := Pipe{}.Run(ctx)
assert.True(t, pipeline.IsSkip(err)) assert.True(t, pipe.IsSkip(err))
assert.EqualError(t, err, pipeline.ErrSkipPublishEnabled.Error()) assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
} }
func TestRunPipe_DirUpload(t *testing.T) { func TestRunPipe_DirUpload(t *testing.T) {
@@ -447,7 +447,7 @@ func TestDescription(t *testing.T) {
} }
func TestNoPuts(t *testing.T) { func TestNoPuts(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{})))) assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{}))))
} }
func TestPutsWithoutTarget(t *testing.T) { func TestPutsWithoutTarget(t *testing.T) {
@@ -465,7 +465,7 @@ func TestPutsWithoutTarget(t *testing.T) {
}, },
} }
assert.True(t, pipeline.IsSkip(Pipe{}.Run(ctx))) assert.True(t, pipe.IsSkip(Pipe{}.Run(ctx)))
} }
func TestPutsWithoutUsername(t *testing.T) { func TestPutsWithoutUsername(t *testing.T) {
@@ -483,11 +483,11 @@ func TestPutsWithoutUsername(t *testing.T) {
}, },
} }
assert.True(t, pipeline.IsSkip(Pipe{}.Run(ctx))) assert.True(t, pipe.IsSkip(Pipe{}.Run(ctx)))
} }
func TestPutsWithoutName(t *testing.T) { func TestPutsWithoutName(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{ assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
Puts: []config.Put{ Puts: []config.Put{
{ {
Username: "deployuser", Username: "deployuser",
@@ -498,7 +498,7 @@ func TestPutsWithoutName(t *testing.T) {
} }
func TestPutsWithoutSecret(t *testing.T) { func TestPutsWithoutSecret(t *testing.T) {
assert.True(t, pipeline.IsSkip(Pipe{}.Run(context.New(config.Project{ assert.True(t, pipe.IsSkip(Pipe{}.Run(context.New(config.Project{
Puts: []config.Put{ Puts: []config.Put{
{ {
Name: "production", Name: "production",

View File

@@ -7,7 +7,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client" "github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -49,10 +49,10 @@ func (Pipe) Run(ctx *context.Context) error {
func doRun(ctx *context.Context, c client.Client) error { func doRun(ctx *context.Context, c client.Client) error {
if ctx.Config.Release.Disable { if ctx.Config.Release.Disable {
return pipeline.Skip("release pipe is disabled") return pipe.Skip("release pipe is disabled")
} }
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
log.WithField("tag", ctx.Git.CurrentTag). log.WithField("tag", ctx.Git.CurrentTag).
WithField("repo", ctx.Config.Release.GitHub.String()). WithField("repo", ctx.Config.Release.GitHub.String()).

View File

@@ -9,7 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
@@ -47,10 +47,10 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
if len(ctx.Config.S3) == 0 { if len(ctx.Config.S3) == 0 {
return pipeline.Skip("s3 section is not configured") return pipe.Skip("s3 section is not configured")
} }
var g = semerrgroup.New(ctx.Parallelism) var g = semerrgroup.New(ctx.Parallelism)
for _, conf := range ctx.Config.S3 { for _, conf := range ctx.Config.S3 {

View File

@@ -11,7 +11,7 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/testlib" "github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
@@ -80,8 +80,8 @@ func TestSkipPublish(t *testing.T) {
ctx.SkipPublish = true ctx.SkipPublish = true
require.NoError(t, Pipe{}.Default(ctx)) require.NoError(t, Pipe{}.Default(ctx))
err = Pipe{}.Run(ctx) err = Pipe{}.Run(ctx)
assert.True(t, pipeline.IsSkip(err)) assert.True(t, pipe.IsSkip(err))
assert.EqualError(t, err, pipeline.ErrSkipPublishEnabled.Error()) assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
} }
func TestUpload(t *testing.T) { func TestUpload(t *testing.T) {

View File

@@ -9,7 +9,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client" "github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -54,10 +54,10 @@ func (Pipe) Default(ctx *context.Context) error {
func doRun(ctx *context.Context, client client.Client) error { func doRun(ctx *context.Context, client client.Client) error {
if ctx.Config.Scoop.Bucket.Name == "" { if ctx.Config.Scoop.Bucket.Name == "" {
return pipeline.Skip("scoop section is not configured") return pipe.Skip("scoop section is not configured")
} }
if ctx.Config.Archive.Format == "binary" { if ctx.Config.Archive.Format == "binary" {
return pipeline.Skip("archive format is binary") return pipe.Skip("archive format is binary")
} }
var archives = ctx.Artifacts.Filter( var archives = ctx.Artifacts.Filter(
@@ -78,10 +78,10 @@ func doRun(ctx *context.Context, client client.Client) error {
} }
if ctx.SkipPublish { if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled return pipe.ErrSkipPublishEnabled
} }
if ctx.Config.Release.Draft { if ctx.Config.Release.Draft {
return pipeline.Skip("release is marked as draft") return pipe.Skip("release is marked as draft")
} }
return client.CreateFile( return client.CreateFile(
ctx, ctx,

View File

@@ -11,7 +11,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client" "github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/testlib" "github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
@@ -286,7 +286,7 @@ func Test_doRun(t *testing.T) {
{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
}, },
shouldErr(pipeline.ErrSkipPublishEnabled.Error()), shouldErr(pipe.ErrSkipPublishEnabled.Error()),
}, },
{ {
"is draft", "is draft",

View File

@@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -39,7 +39,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run executes the Pipe. // Run executes the Pipe.
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if ctx.SkipSign { if ctx.SkipSign {
return pipeline.ErrSkipSignEnabled return pipe.ErrSkipSignEnabled
} }
switch ctx.Config.Sign.Artifacts { switch ctx.Config.Sign.Artifacts {
@@ -54,7 +54,7 @@ func (Pipe) Run(ctx *context.Context) error {
artifact.ByType(artifact.LinuxPackage), artifact.ByType(artifact.LinuxPackage),
)).List()) )).List())
case "none": case "none":
return pipeline.ErrSkipSignEnabled return pipe.ErrSkipSignEnabled
default: default:
return fmt.Errorf("invalid list of artifacts to sign: %s", ctx.Config.Sign.Artifacts) return fmt.Errorf("invalid list of artifacts to sign: %s", ctx.Config.Sign.Artifacts)
} }

View File

@@ -15,7 +15,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/linux" "github.com/goreleaser/goreleaser/internal/linux"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
@@ -70,7 +70,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Snapcraft.Summary == "" && ctx.Config.Snapcraft.Description == "" { if ctx.Config.Snapcraft.Summary == "" && ctx.Config.Snapcraft.Description == "" {
return pipeline.Skip("no summary nor description were provided") return pipe.Skip("no summary nor description were provided")
} }
if ctx.Config.Snapcraft.Summary == "" { if ctx.Config.Snapcraft.Summary == "" {
return ErrNoSummary return ErrNoSummary

View File

@@ -8,7 +8,7 @@ import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -27,7 +27,7 @@ func TestRunPipeMissingInfo(t *testing.T) {
ErrNoDescription: { ErrNoDescription: {
Summary: "dummy summary", Summary: "dummy summary",
}, },
pipeline.Skip("no summary nor description were provided"): {}, pipe.Skip("no summary nor description were provided"): {},
} { } {
t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) { t.Run(fmt.Sprintf("testing if %v happens", eerr), func(t *testing.T) {
var ctx = &context.Context{ var ctx = &context.Context{

View File

@@ -1,39 +1,60 @@
// Package pipeline provides generic erros for pipes to use. // Package pipeline provides generic erros for pipes to use.
package pipeline package pipeline
// ErrSnapshotEnabled happens when goreleaser is running in snapshot mode. import (
// It usually means that publishing and maybe some validations were skipped. "fmt"
var ErrSnapshotEnabled = Skip("disabled during snapshot mode")
// ErrSkipPublishEnabled happens if --skip-publish is set. "github.com/goreleaser/goreleaser/internal/pipe/archive"
// It means that the part of a Piper that publishes its artifacts was not run. "github.com/goreleaser/goreleaser/internal/pipe/artifactory"
var ErrSkipPublishEnabled = Skip("publishing is disabled") "github.com/goreleaser/goreleaser/internal/pipe/before"
"github.com/goreleaser/goreleaser/internal/pipe/brew"
"github.com/goreleaser/goreleaser/internal/pipe/build"
"github.com/goreleaser/goreleaser/internal/pipe/changelog"
"github.com/goreleaser/goreleaser/internal/pipe/checksums"
"github.com/goreleaser/goreleaser/internal/pipe/defaults"
"github.com/goreleaser/goreleaser/internal/pipe/dist"
"github.com/goreleaser/goreleaser/internal/pipe/docker"
"github.com/goreleaser/goreleaser/internal/pipe/effectiveconfig"
"github.com/goreleaser/goreleaser/internal/pipe/env"
"github.com/goreleaser/goreleaser/internal/pipe/git"
"github.com/goreleaser/goreleaser/internal/pipe/nfpm"
"github.com/goreleaser/goreleaser/internal/pipe/put"
"github.com/goreleaser/goreleaser/internal/pipe/release"
"github.com/goreleaser/goreleaser/internal/pipe/s3"
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
"github.com/goreleaser/goreleaser/internal/pipe/sign"
"github.com/goreleaser/goreleaser/internal/pipe/snapcraft"
"github.com/goreleaser/goreleaser/pkg/context"
)
// ErrSkipSignEnabled happens if --skip-sign is set. // Piper defines a pipe, which can be part of a pipeline (a serie of pipes).
// It means that the part of a Piper that signs some things was not run. type Piper interface {
var ErrSkipSignEnabled = Skip("artifact signing is disabled") fmt.Stringer
// ErrSkipValidateEnabled happens if --skip-validate is set. // Run the pipe
// It means that the part of a Piper that validates some things was not run. Run(ctx *context.Context) error
var ErrSkipValidateEnabled = Skip("validation is disabled")
// IsSkip returns true if the error is an ErrSkip
func IsSkip(err error) bool {
_, ok := err.(ErrSkip)
return ok
} }
// ErrSkip occurs when a pipe is skipped for some reason // Pipeline contains all pipe implementations in order
type ErrSkip struct { var Pipeline = []Piper{
reason string defaults.Pipe{}, // load default configs
} before.Pipe{}, // run global hooks before build
dist.Pipe{}, // ensure ./dist is clean
// Error implements the error interface. returns the reason the pipe was skipped git.Pipe{}, // get and validate git repo state
func (e ErrSkip) Error() string { effectiveconfig.Pipe{}, // writes the actual config (with defaults et al set) to dist
return e.reason changelog.Pipe{}, // builds the release changelog
} env.Pipe{}, // load and validate environment variables
build.Pipe{}, // build
// Skip skips this pipe with the given reason archive.Pipe{}, // archive in tar.gz, zip or binary (which does no archiving at all)
func Skip(reason string) ErrSkip { nfpm.Pipe{}, // archive via fpm (deb, rpm) using "native" go impl
return ErrSkip{reason: reason} snapcraft.Pipe{}, // archive via snapcraft (snap)
checksums.Pipe{}, // checksums of the files
sign.Pipe{}, // sign artifacts
docker.Pipe{}, // create and push docker images
artifactory.Pipe{}, // push to artifactory
put.Pipe{}, // upload to http server
s3.Pipe{}, // push to s3/minio
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
scoop.Pipe{}, // push to scoop bucket
} }

View File

@@ -3,12 +3,12 @@ package testlib
import ( import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
// AssertSkipped asserts that a pipe was skipped // AssertSkipped asserts that a pipe was skipped
func AssertSkipped(t *testing.T, err error) { func AssertSkipped(t *testing.T, err error) {
_, ok := err.(pipeline.ErrSkip) _, ok := err.(pipe.ErrSkip)
assert.True(t, ok, "expected a pipeline.ErrSkip but got %v", err) assert.True(t, ok, "expected a pipe.ErrSkip but got %v", err)
} }

View File

@@ -3,9 +3,9 @@ package testlib
import ( import (
"testing" "testing"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipe"
) )
func TestAssertSkipped(t *testing.T) { func TestAssertSkipped(t *testing.T) {
AssertSkipped(t, pipeline.Skip("skip")) AssertSkipped(t, pipe.Skip("skip"))
} }

56
main.go
View File

@@ -13,27 +13,8 @@ import (
"github.com/caarlos0/ctrlc" "github.com/caarlos0/ctrlc"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/pipeline" "github.com/goreleaser/goreleaser/internal/pipeline"
"github.com/goreleaser/goreleaser/internal/pipeline/archive"
"github.com/goreleaser/goreleaser/internal/pipeline/artifactory"
"github.com/goreleaser/goreleaser/internal/pipeline/before"
"github.com/goreleaser/goreleaser/internal/pipeline/brew"
"github.com/goreleaser/goreleaser/internal/pipeline/build"
"github.com/goreleaser/goreleaser/internal/pipeline/changelog"
"github.com/goreleaser/goreleaser/internal/pipeline/checksums"
"github.com/goreleaser/goreleaser/internal/pipeline/defaults"
"github.com/goreleaser/goreleaser/internal/pipeline/dist"
"github.com/goreleaser/goreleaser/internal/pipeline/docker"
"github.com/goreleaser/goreleaser/internal/pipeline/effectiveconfig"
"github.com/goreleaser/goreleaser/internal/pipeline/env"
"github.com/goreleaser/goreleaser/internal/pipeline/git"
"github.com/goreleaser/goreleaser/internal/pipeline/nfpm"
"github.com/goreleaser/goreleaser/internal/pipeline/put"
"github.com/goreleaser/goreleaser/internal/pipeline/release"
"github.com/goreleaser/goreleaser/internal/pipeline/s3"
"github.com/goreleaser/goreleaser/internal/pipeline/scoop"
"github.com/goreleaser/goreleaser/internal/pipeline/sign"
"github.com/goreleaser/goreleaser/internal/pipeline/snapcraft"
"github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context" "github.com/goreleaser/goreleaser/pkg/context"
) )
@@ -44,37 +25,6 @@ var (
date = "unknown" date = "unknown"
) )
var pipes = []Piper{
defaults.Pipe{}, // load default configs
before.Pipe{}, // run global hooks before build
dist.Pipe{}, // ensure ./dist is clean
git.Pipe{}, // get and validate git repo state
effectiveconfig.Pipe{}, // writes the actual config (with defaults et al set) to dist
changelog.Pipe{}, // builds the release changelog
env.Pipe{}, // load and validate environment variables
build.Pipe{}, // build
archive.Pipe{}, // archive in tar.gz, zip or binary (which does no archiving at all)
nfpm.Pipe{}, // archive via fpm (deb, rpm) using "native" go impl
snapcraft.Pipe{}, // archive via snapcraft (snap)
checksums.Pipe{}, // checksums of the files
sign.Pipe{}, // sign artifacts
docker.Pipe{}, // create and push docker images
artifactory.Pipe{}, // push to artifactory
put.Pipe{}, // upload to http server
s3.Pipe{}, // push to s3/minio
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
scoop.Pipe{}, // push to scoop bucket
}
// Piper defines a pipe, which can be part of a pipeline (a serie of pipes).
type Piper interface {
fmt.Stringer
// Run the pipe
Run(ctx *context.Context) error
}
type releaseOptions struct { type releaseOptions struct {
Config string Config string
ReleaseNotes string ReleaseNotes string
@@ -184,7 +134,7 @@ func releaseProject(options releaseOptions) error {
func doRelease(ctx *context.Context) error { func doRelease(ctx *context.Context) error {
defer func() { cli.Default.Padding = 3 }() defer func() { cli.Default.Padding = 3 }()
var release = func() error { var release = func() error {
for _, pipe := range pipes { for _, pipe := range pipeline.Pipeline {
cli.Default.Padding = 3 cli.Default.Padding = 3
log.Infof(color.New(color.Bold).Sprint(strings.ToUpper(pipe.String()))) log.Infof(color.New(color.Bold).Sprint(strings.ToUpper(pipe.String())))
cli.Default.Padding = 6 cli.Default.Padding = 6
@@ -201,7 +151,7 @@ func handle(err error) error {
if err == nil { if err == nil {
return nil return nil
} }
if pipeline.IsSkip(err) { if pipe.IsSkip(err) {
log.WithField("reason", err.Error()).Warn("skipped") log.WithField("reason", err.Error()).Warn("skipped")
return nil return nil
} }

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 74 KiB