mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-13 11:50:34 +02:00
refactor: added publish pipe
This commit is contained in:
parent
f99940ff53
commit
71df84f829
40
internal/pipe/publish/publish.go
Normal file
40
internal/pipe/publish/publish.go
Normal file
@ -0,0 +1,40 @@
|
||||
// Package publish contains the publishing pipe.
|
||||
package publish
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Pipe that publishes artifacts
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string {
|
||||
return "publishing artifacts"
|
||||
}
|
||||
|
||||
// Publisher should be implemented by pipes that want to publish artifacts
|
||||
type Publisher interface {
|
||||
fmt.Stringer
|
||||
|
||||
// Default sets the configuration defaults
|
||||
Publish(ctx *context.Context) error
|
||||
}
|
||||
|
||||
var publishers = []Publisher{}
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.SkipPublish {
|
||||
return pipe.ErrSkipPublishEnabled
|
||||
}
|
||||
for _, publisher := range publishers {
|
||||
if err := publisher.Publish(ctx); err != nil {
|
||||
return errors.Wrapf(err, "failed to publish artifacts for %s", publisher.String())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
22
internal/pipe/publish/publish_test.go
Normal file
22
internal/pipe/publish/publish_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package publish
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDescription(t *testing.T) {
|
||||
assert.NotEmpty(t, Pipe{}.String())
|
||||
}
|
||||
|
||||
func TestPublishDisable(t *testing.T) {
|
||||
var ctx = context.New(config.Project{})
|
||||
ctx.SkipPublish = true
|
||||
require.EqualError(t, Pipe{}.Run(ctx), pipe.ErrSkipPublishEnabled.Error())
|
||||
}
|
@ -18,6 +18,7 @@ import (
|
||||
"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/publish"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/put"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/release"
|
||||
"github.com/goreleaser/goreleaser/internal/pipe/s3"
|
||||
@ -57,4 +58,5 @@ var Pipeline = []Piper{
|
||||
release.Pipe{}, // release to github
|
||||
brew.Pipe{}, // push to brew tap
|
||||
scoop.Pipe{}, // push to scoop bucket
|
||||
publish.Pipe{}, // publishes artifacts
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user