-
Notifications
You must be signed in to change notification settings - Fork 39
/
mage.go
69 lines (57 loc) · 1.65 KB
/
mage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//+build mage
// This is the "magefile" for gnorm. To install mage, run go get github.com/magefile/mage.
// To build gnorm, just mage build.
package main
import (
"errors"
"log"
"os"
"regexp"
"github.com/magefile/mage/sh"
)
// Runs go install for gnorm. This generates the embedded docs and the version
// info into the binary.
func Build() error {
if err := genSite(); err != nil {
return err
}
defer cleanup()
ldf, err := flags()
if err != nil {
return err
}
log.Print("running go install")
// use -tags make so we can have different behavior for when we know we've built with mage.
return run("go", "install", "-tags", "make", "--ldflags="+ldf, "gnorm.org/gnorm")
}
// Runs go generate.
func Generate() error {
return sh.Run("go", "generate", "./...")
}
// 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) {
releaseTag := regexp.MustCompile(`^v1\.[0-9]+\.[0-9]+$`)
tag := os.Getenv("TAG")
if !releaseTag.MatchString(tag) {
return errors.New("TAG environment variable must be in semver v1.x.x format, but was " + tag)
}
if err := sh.RunV("git", "tag", "-a", tag, "-m", 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")
}
// Removes generated cruft. This target shouldn't ever be necessary, since the
// cleanup should happen automatically, but it's here just in case.
func Clean() error {
return cleanup()
}