Skip to content

Commit

Permalink
refactor: better package organization
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Sep 12, 2018
1 parent e9cc0c9 commit 39de856
Show file tree
Hide file tree
Showing 97 changed files with 1,049 additions and 1,087 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
dist/
!internal/pipeline/dist
!internal/pipe/dist
bin/
vendor
coverage.txt
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -76,7 +76,7 @@ serve:

depgraph:
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

# Show to-do items per file.
Expand Down
6 changes: 3 additions & 3 deletions internal/http/http.go
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/pkg/errors"

"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/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
Expand Down Expand Up @@ -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 {
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.
Expand All @@ -112,7 +112,7 @@ type ResponseChecker func(*h.Response) error
// Upload does the actual uploading work
func Upload(ctx *context.Context, puts []config.Put, kind string, check ResponseChecker) error {
if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled
return pipe.ErrSkipPublishEnabled
}

// Handle every configured put
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -8,7 +8,7 @@ import (
h "net/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"
)

Expand Down Expand Up @@ -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
func (Pipe) Run(ctx *context.Context) error {
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.
// If not fulfilled, we can skip this pipeline
for _, instance := range ctx.Config.Artifactories {
if skip := http.CheckConfig(ctx, &instance, "artifactory"); skip != nil {
return pipeline.Skip(skip.Error())
return pipe.Skip(skip.Error())
}
}

Expand Down
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"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/context"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -620,8 +620,8 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) {
ctx.SkipPublish = true

err := Pipe{}.Run(ctx)
assert.True(t, pipeline.IsSkip(err))
assert.EqualError(t, err, pipeline.ErrSkipPublishEnabled.Error())
assert.True(t, pipe.IsSkip(err))
assert.EqualError(t, err, pipe.ErrSkipPublishEnabled.Error())
}

func TestRunPipe_DirUpload(t *testing.T) {
Expand Down Expand Up @@ -663,7 +663,7 @@ func TestDescription(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) {
Expand All @@ -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) {
Expand All @@ -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) {
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{
{
Username: "deployuser",
Expand All @@ -714,7 +714,7 @@ func TestArtifactoriesWithoutName(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{
{
Name: "production",
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions internal/pipeline/brew/brew.go → internal/pipe/brew/brew.go
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/goreleaser/goreleaser/internal/artifact"
"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/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
Expand Down Expand Up @@ -89,10 +89,10 @@ func contains(ss []string, s string) bool {

func doRun(ctx *context.Context, client client.Client) error {
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" {
return pipeline.Skip("archive format is binary")
return pipe.Skip("archive format is binary")
}

var archives = ctx.Artifacts.Filter(
Expand Down Expand Up @@ -123,13 +123,13 @@ func doRun(ctx *context.Context, client client.Client) error {
}

if ctx.Config.Brew.SkipUpload {
return pipeline.Skip("brew.skip_upload is set")
return pipe.Skip("brew.skip_upload is set")
}
if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled
return pipe.ErrSkipPublishEnabled
}
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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/apex/log"

"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/pipeline"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
)

Expand All @@ -30,10 +30,10 @@ func (Pipe) String() string {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
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 {
return pipeline.Skip("not available for snapshots")
return pipe.Skip("not available for snapshots")
}
if err := checkSortDirection(ctx.Config.Changelog.Sort); err != nil {
return err
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -6,21 +6,21 @@ import (
"fmt"

"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/pipeline/archive"
"github.com/goreleaser/goreleaser/internal/pipeline/artifactory"
"github.com/goreleaser/goreleaser/internal/pipeline/brew"
"github.com/goreleaser/goreleaser/internal/pipeline/build"
"github.com/goreleaser/goreleaser/internal/pipeline/checksums"
"github.com/goreleaser/goreleaser/internal/pipeline/docker"
"github.com/goreleaser/goreleaser/internal/pipeline/env"
"github.com/goreleaser/goreleaser/internal/pipeline/nfpm"
"github.com/goreleaser/goreleaser/internal/pipeline/project"
"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/internal/pipeline/snapshot"
"github.com/goreleaser/goreleaser/internal/pipe/archive"
"github.com/goreleaser/goreleaser/internal/pipe/artifactory"
"github.com/goreleaser/goreleaser/internal/pipe/brew"
"github.com/goreleaser/goreleaser/internal/pipe/build"
"github.com/goreleaser/goreleaser/internal/pipe/checksums"
"github.com/goreleaser/goreleaser/internal/pipe/docker"
"github.com/goreleaser/goreleaser/internal/pipe/env"
"github.com/goreleaser/goreleaser/internal/pipe/nfpm"
"github.com/goreleaser/goreleaser/internal/pipe/project"
"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/internal/pipe/snapshot"
"github.com/goreleaser/goreleaser/pkg/context"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/pkg/errors"

"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/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
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")
if err != nil {
Expand Down Expand Up @@ -165,12 +165,12 @@ func link(src, dest string) error {
func publish(ctx *context.Context, docker config.Docker, images []string) error {
if ctx.SkipPublish {
// TODO: this should be better handled
log.Warn(pipeline.ErrSkipPublishEnabled.Error())
log.Warn(pipe.ErrSkipPublishEnabled.Error())
return nil
}
if docker.SkipPush {
// 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
}
for _, image := range images {
Expand Down
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"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/context"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -420,11 +420,11 @@ func TestDescription(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) {
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{
{
Goos: "linux",
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/pipeline/env/env.go → internal/pipe/env/env.go
Expand Up @@ -6,7 +6,7 @@ import (
"bufio"
"os"

"github.com/goreleaser/goreleaser/internal/pipeline"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
Expand Down Expand Up @@ -36,10 +36,10 @@ func (Pipe) Run(ctx *context.Context) error {
token, err := loadEnv("GITHUB_TOKEN", ctx.Config.EnvFiles.GitHubToken)
ctx.Token = token
if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled
return pipe.ErrSkipPublishEnabled
}
if ctx.Config.Release.Disable {
return pipeline.Skip("release pipe is disabled")
return pipe.Skip("release pipe is disabled")
}
if ctx.Token == "" && err == nil {
return ErrMissingToken
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/pipeline/git/git.go → internal/pipe/git/git.go
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/apex/log"
"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/pkg/context"
"github.com/pkg/errors"
Expand Down Expand Up @@ -96,10 +96,10 @@ func setVersion(ctx *context.Context) error {

func validate(ctx *context.Context) error {
if ctx.Snapshot {
return pipeline.ErrSnapshotEnabled
return pipe.ErrSnapshotEnabled
}
if ctx.SkipValidate {
return pipeline.ErrSkipValidateEnabled
return pipe.ErrSkipValidateEnabled
}
out, err := git.Run("status", "--porcelain")
if strings.TrimSpace(out) != "" || err != nil {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions internal/pipeline/nfpm/nfpm.go → internal/pipe/nfpm/nfpm.go
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/goreleaser/goreleaser/internal/artifact"
"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/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
Expand Down Expand Up @@ -51,7 +51,7 @@ func (Pipe) Default(ctx *context.Context) error {
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
if len(ctx.Config.NFPM.Formats) == 0 {
return pipeline.Skip("no output formats configured")
return pipe.Skip("no output formats configured")
}
return doRun(ctx)
}
Expand Down
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions internal/pipe/pipe.go
@@ -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}
}
@@ -1,4 +1,4 @@
package pipeline
package pipe

import (
"errors"
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 39de856

Please sign in to comment.