2017-01-21 19:11:54 -02:00
|
|
|
// Package source provides pipes to take care of validating the current
|
|
|
|
// git repo state.
|
2017-01-19 09:47:17 +01:00
|
|
|
// For the releasing process we need the files of the tag we are releasing.
|
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2017-01-31 11:24:48 -02:00
|
|
|
"strings"
|
2017-01-19 09:47:17 +01:00
|
|
|
|
|
|
|
"github.com/goreleaser/goreleaser/context"
|
|
|
|
)
|
|
|
|
|
2017-01-21 19:11:54 -02:00
|
|
|
// ErrDirty happens when the repo has uncommitted/unstashed changes
|
2017-01-30 23:46:28 -02:00
|
|
|
type ErrDirty struct {
|
|
|
|
status string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e ErrDirty) Error() string {
|
2017-01-31 11:08:12 -02:00
|
|
|
return "git is currently in a dirty state:\n" + e.status
|
2017-01-30 23:46:28 -02:00
|
|
|
}
|
2017-01-21 19:11:54 -02:00
|
|
|
|
2017-01-21 19:33:30 -02:00
|
|
|
// ErrWrongRef happens when the HEAD reference is different from the tag being built
|
2017-01-30 23:46:28 -02:00
|
|
|
type ErrWrongRef struct {
|
|
|
|
status string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e ErrWrongRef) Error() string {
|
2017-01-31 11:24:48 -02:00
|
|
|
return e.status
|
2017-01-30 23:46:28 -02:00
|
|
|
}
|
2017-01-21 19:11:54 -02:00
|
|
|
|
|
|
|
// Pipe to make sure we are in the latest Git tag as source.
|
|
|
|
type Pipe struct{}
|
2017-01-19 09:47:17 +01:00
|
|
|
|
|
|
|
// Description of the pipe
|
2017-01-23 09:47:35 -02:00
|
|
|
func (p Pipe) Description() string {
|
2017-01-21 19:11:54 -02:00
|
|
|
return "Validating current git state"
|
2017-01-19 09:47:17 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 19:11:54 -02:00
|
|
|
// Run errors we the repo is dirty or if the current ref is different from the
|
|
|
|
// tag ref
|
2017-01-23 09:47:35 -02:00
|
|
|
func (p Pipe) Run(ctx *context.Context) error {
|
2017-01-31 11:24:48 -02:00
|
|
|
bts, err := exec.Command("git", "diff").CombinedOutput()
|
|
|
|
if err != nil || strings.TrimSpace(string(bts)) != "" {
|
2017-01-31 11:08:12 -02:00
|
|
|
return ErrDirty{string(bts)}
|
2017-01-19 09:47:17 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 11:24:48 -02:00
|
|
|
cmd := exec.Command("git", "describe", "--exact-match", "--tags", "--match", ctx.Git.CurrentTag)
|
2017-01-31 11:08:12 -02:00
|
|
|
if bts, err := cmd.CombinedOutput(); err != nil {
|
|
|
|
return ErrWrongRef{string(bts)}
|
2017-01-19 10:24:04 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|