mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
moved source pipe into git pipe
This commit is contained in:
parent
8a5392cdf0
commit
0c94ae518a
6
main.go
6
main.go
@ -16,7 +16,6 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pipeline/fpm"
|
||||
"github.com/goreleaser/goreleaser/pipeline/git"
|
||||
"github.com/goreleaser/goreleaser/pipeline/release"
|
||||
"github.com/goreleaser/goreleaser/pipeline/source"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -74,9 +73,8 @@ func pipes(buildOnly bool) []pipeline.Pipe {
|
||||
if !buildOnly {
|
||||
pipes = append(
|
||||
pipes,
|
||||
git.Pipe{}, // get current tag info
|
||||
env.Pipe{}, // load and validate environment variables
|
||||
source.Pipe{}, // validate current git state
|
||||
git.Pipe{}, // get and validate git repo state
|
||||
env.Pipe{}, // load and validate environment variables
|
||||
)
|
||||
}
|
||||
pipes = append(
|
||||
|
@ -18,12 +18,30 @@ func (e ErrInvalidVersionFormat) Error() string {
|
||||
return e.version + " is not in a valid version format"
|
||||
}
|
||||
|
||||
// ErrDirty happens when the repo has uncommitted/unstashed changes
|
||||
type ErrDirty struct {
|
||||
status string
|
||||
}
|
||||
|
||||
func (e ErrDirty) Error() string {
|
||||
return "git is currently in a dirty state:\n" + e.status
|
||||
}
|
||||
|
||||
// ErrWrongRef happens when the HEAD reference is different from the tag being built
|
||||
type ErrWrongRef struct {
|
||||
status string
|
||||
}
|
||||
|
||||
func (e ErrWrongRef) Error() string {
|
||||
return e.status
|
||||
}
|
||||
|
||||
// Pipe for brew deployment
|
||||
type Pipe struct{}
|
||||
|
||||
// Description of the pipe
|
||||
func (Pipe) Description() string {
|
||||
return "Getting Git info"
|
||||
return "Getting and validating git state"
|
||||
}
|
||||
|
||||
// Run the pipe
|
||||
@ -57,7 +75,15 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
ctx.Git.Commit = commit
|
||||
return
|
||||
out, err := git("diff")
|
||||
if strings.TrimSpace(out) != "" || err != nil {
|
||||
return ErrDirty{out}
|
||||
}
|
||||
_, err = cleanGit("describe", "--exact-match", "--tags", "--match", tag)
|
||||
if err != nil {
|
||||
return ErrWrongRef{err.Error()}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func previous(tag string) (previous string, err error) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
@ -15,18 +15,6 @@ func TestDescription(t *testing.T) {
|
||||
assert.NotEmpty(t, Pipe{}.Description())
|
||||
}
|
||||
|
||||
func TestValidVersion(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.NoError(Pipe{}.Run(ctx))
|
||||
assert.NotEmpty(ctx.Git.CurrentTag)
|
||||
assert.NotEmpty(ctx.Git.PreviousTag)
|
||||
assert.NotEmpty(ctx.Git.Diff)
|
||||
}
|
||||
|
||||
func TestNotAGitFolder(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := createAndChdir(t)
|
||||
@ -44,7 +32,6 @@ func TestSingleCommit(t *testing.T) {
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit1")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitLog(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -70,7 +57,6 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit2")
|
||||
gitTag(t, "sadasd")
|
||||
gitLog(t)
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
@ -78,6 +64,41 @@ func TestInvalidTagFormat(t *testing.T) {
|
||||
assert.Equal("sadasd", ctx.Git.CurrentTag)
|
||||
}
|
||||
|
||||
func TestDirty(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
folder, back := createAndChdir(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
dummy, err := os.Create(filepath.Join(folder, "dummy"))
|
||||
assert.NoError(err)
|
||||
gitAdd(t)
|
||||
gitCommit(t, "commit2")
|
||||
gitTag(t, "v0.0.1")
|
||||
assert.NoError(ioutil.WriteFile(dummy.Name(), []byte("lorem ipsum"), 0644))
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
err = Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "git is currently in a dirty state:")
|
||||
}
|
||||
|
||||
func TestTagIsNotLastCommit(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
_, back := createAndChdir(t)
|
||||
defer back()
|
||||
gitInit(t)
|
||||
gitCommit(t, "commit3")
|
||||
gitTag(t, "v0.0.1")
|
||||
gitCommit(t, "commit4")
|
||||
var ctx = &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
err := Pipe{}.Run(ctx)
|
||||
assert.Error(err)
|
||||
assert.Contains(err.Error(), "fatal: no tag exactly matches")
|
||||
}
|
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
@ -115,12 +136,11 @@ func gitTag(t *testing.T, tag string) {
|
||||
assert.Empty(out)
|
||||
}
|
||||
|
||||
func gitLog(t *testing.T) {
|
||||
func gitAdd(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
out, err := git("log")
|
||||
out, err := git("add", "-A")
|
||||
assert.NoError(err)
|
||||
assert.NotEmpty(out)
|
||||
fmt.Print("\n\ngit log output:\n", out)
|
||||
assert.Empty(out)
|
||||
}
|
||||
|
||||
func fakeGit(args ...string) (string, error) {
|
||||
|
@ -1,52 +0,0 @@
|
||||
// Package source provides pipes to take care of validating the current
|
||||
// git repo state.
|
||||
// For the releasing process we need the files of the tag we are releasing.
|
||||
package source
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
// ErrDirty happens when the repo has uncommitted/unstashed changes
|
||||
type ErrDirty struct {
|
||||
status string
|
||||
}
|
||||
|
||||
func (e ErrDirty) Error() string {
|
||||
return "git is currently in a dirty state:\n" + e.status
|
||||
}
|
||||
|
||||
// ErrWrongRef happens when the HEAD reference is different from the tag being built
|
||||
type ErrWrongRef struct {
|
||||
status string
|
||||
}
|
||||
|
||||
func (e ErrWrongRef) Error() string {
|
||||
return e.status
|
||||
}
|
||||
|
||||
// Pipe to make sure we are in the latest Git tag as source.
|
||||
type Pipe struct{}
|
||||
|
||||
// Description of the pipe
|
||||
func (p Pipe) Description() string {
|
||||
return "Validating current git state"
|
||||
}
|
||||
|
||||
// Run errors we the repo is dirty or if the current ref is different from the
|
||||
// tag ref
|
||||
func (p Pipe) Run(ctx *context.Context) error {
|
||||
bts, err := exec.Command("git", "diff").CombinedOutput()
|
||||
if err != nil || strings.TrimSpace(string(bts)) != "" {
|
||||
return ErrDirty{string(bts)}
|
||||
}
|
||||
|
||||
cmd := exec.Command("git", "describe", "--exact-match", "--tags", "--match", ctx.Git.CurrentTag)
|
||||
if bts, err := cmd.CombinedOutput(); err != nil {
|
||||
return ErrWrongRef{string(bts)}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user