-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
72 lines (58 loc) · 1.9 KB
/
magefile.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
70
71
72
//go:build mage
package main
import (
"bytes"
"strings"
"time"
"github.com/danbrakeley/bsh"
)
var (
sh = &bsh.Bsh{}
needl = "needl"
)
// Build tests and builds the app (output goes to "local" folder)
func Build() {
target := sh.ExeName(needl)
sh.Echo("Running unit tests...")
sh.Cmd("go test ./...").Run()
sh.Echof("Building %s...", target)
sh.MkdirAll("local/")
// grab git commit hash to use as version for local builds
commit := "(dev)"
var b bytes.Buffer
n := sh.Cmd(`git log --pretty=format:'%h' -n 1`).Out(&b).RunExitStatus()
if n == 0 {
commit = strings.TrimSpace(b.String())
}
sh.Cmdf(
`go build -ldflags '`+
`-X "github.com/danbrakeley/needl/internal/buildvar.Version=%s" `+
`-X "github.com/danbrakeley/needl/internal/buildvar.BuildTime=%s" `+
`-X "github.com/danbrakeley/needl/internal/buildvar.ReleaseURL=https://github.com/danbrakeley/needl"`+
`' -o local/%s ./cmd/%s`, commit, time.Now().Format(time.RFC3339), target, needl,
).Run()
}
// CfgClean removes local/needl.toml and local/scraper.toml
func CfgClean() {
sh.Echo("Removing local/needl.toml and local/scraper.toml...")
sh.RemoveAll("local/needl.toml")
sh.RemoveAll("local/scrapers.toml")
}
// Cfg copies needl.toml and scrapers.toml into the local folder
func CfgCopy() {
sh.Echo("Copying needl.toml and scrapers.toml to local...")
sh.Copy("needl.toml", "local/needl.toml")
sh.Copy("scrapers.toml", "local/scrapers.toml")
}
// CfgLocal copies needl.local.toml and scrapers.local.toml into local/needl.toml and local/scrapers.toml, respectively
func CfgLocal() {
sh.Echo("Copying needl.local.toml and scrapers.local.toml to local/needl.toml and local/scrapers.toml...")
sh.Copy("needl.local.toml", "local/needl.toml")
sh.Copy("scrapers.local.toml", "local/scrapers.toml")
}
// Run whatever is in local
func Run() {
target := sh.ExeName(needl)
sh.Echo("Running...")
sh.Cmdf("./%s", target).Dir("local").Run()
}