diff options
| author | Christine Dodrill <me@christine.website> | 2017-12-13 10:43:58 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2017-12-13 10:43:58 -0800 |
| commit | 91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8 (patch) | |
| tree | 39b7911168d9ffc501894b79842975735bde6c81 /vendor/github.com/magefile/mage/magefile.go | |
| parent | 141a3320ff790cbaa52319371de530ae9fd09d89 (diff) | |
| download | xesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.tar.xz xesite-91dd3b19f69bfbeefb22c66f75ea3321f2f97bb8.zip | |
convert to go buildpack
Diffstat (limited to 'vendor/github.com/magefile/mage/magefile.go')
| -rw-r--r-- | vendor/github.com/magefile/mage/magefile.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/github.com/magefile/mage/magefile.go b/vendor/github.com/magefile/mage/magefile.go new file mode 100644 index 0000000..373ab5d --- /dev/null +++ b/vendor/github.com/magefile/mage/magefile.go @@ -0,0 +1,72 @@ +//+build mage + +package main + +import ( + "bytes" + "errors" + "fmt" + "os" + "time" + + "github.com/magefile/mage/sh" +) + +// Runs "go install" for mage. This generates the version info the binary. +func Build() error { + ldf, err := flags() + if err != nil { + return err + } + + return sh.Run("go", "install", "-ldflags="+ldf, "github.com/magefile/mage") +} + +// Generates a new release. Expects the TAG environment variable to be set, +// which will create a new tag with that name. +func Release() (err error) { + if os.Getenv("TAG") == "" { + return errors.New("MSG and TAG environment variables are required") + } + if err := sh.RunV("git", "tag", "-a", "$TAG"); err != nil { + return err + } + if err := sh.RunV("git", "push", "origin", "$TAG"); err != nil { + return err + } + defer func() { + if err != nil { + sh.RunV("git", "tag", "--delete", "$TAG") + sh.RunV("git", "push", "--delete", "origin", "$TAG") + } + }() + return sh.RunV("goreleaser") +} + +// Remove the temporarily generated files from Release. +func Clean() error { + return sh.Rm("dist") +} + +func flags() (string, error) { + timestamp := time.Now().Format(time.RFC3339) + hash := hash() + tag := tag() + if tag == "" { + tag = "dev" + } + return fmt.Sprintf(`-X "github.com/magefile/mage/mage.timestamp=%s" -X "github.com/magefile/mage/mage.commitHash=%s" -X "github.com/magefile/mage/mage.gitTag=%s"`, timestamp, hash, tag), nil +} + +// tag returns the git tag for the current branch or "" if none. +func tag() string { + buf := &bytes.Buffer{} + _, _ = sh.Exec(nil, buf, nil, "git", "describe", "--tags") + return buf.String() +} + +// hash returns the git hash for the current repo or "" if none. +func hash() string { + hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD") + return hash +} |
