-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
86 lines (70 loc) · 2.02 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//go:build mage
package main
import (
"bytes"
"strings"
"time"
"github.com/danbrakeley/bsh"
"github.com/magefile/mage/mg"
)
var sh = &bsh.Bsh{}
// Test tests all packages
func Test() {
sh.Echo("Running unit tests...")
sh.Cmd("go test ./...").Run()
}
// LambdaBuild builds the lamda (output goes to "local" folder)
func LambdaBuild() {
sh.MkdirAll("local/")
sh.Echof("Building lambda...")
sh.Cmd(
"go build -o local/bootstrap -tags lambda.norpc ./cmd/lambda/",
).Env("GOOS=linux", "GOARCH=arm64", "CGO_ENABLED=0").Run()
}
// LambdaZip zips the lambda
func LambdaZip() {
sh.Echof("Zipping executable to local/lambda.zip...")
sh.ZipFile("local/bootstrap", "local/lambda.zip")
}
// Lambda tests, builds, and packages the lambda
func Lambda() {
mg.SerialDeps(Test, LambdaBuild, LambdaZip)
}
// UpMyIPBuild builds the upmyip cli app
func UpMyIPBuild() {
exeName := sh.ExeName("upmyip")
sh.Echof("Building local/%s...", exeName)
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).Err(&b).RunExitStatus()
if n == 0 {
commit = strings.TrimSpace(b.String())
}
sh.Cmdf(
`go build -ldflags '`+
`-X "github.com/danbrakeley/upmyip/internal/buildvar.Version=%s" `+
`-X "github.com/danbrakeley/upmyip/internal/buildvar.BuildTime=%s" `+
`-X "github.com/danbrakeley/upmyip/internal/buildvar.ReleaseURL=https://github.com/danbrakeley/upmyip"`+
`' -o local/%s ./cmd/upmyip/`, commit, time.Now().Format(time.RFC3339), exeName,
).Run()
}
// UpMyIPRun runs the upmyip cli app in the "local" folder
func UpMyIPRun() {
exeName := sh.ExeName("upmyip")
sh.Echo("Running...")
sh.Cmdf("./%s", exeName).Dir("local").Run()
}
// UpMyIP tests and builds the upmyip cli app
func UpMyIP() {
mg.SerialDeps(Test, UpMyIPBuild)
}
// All tests, builds, and packages all targets
func All() {
mg.SerialDeps(Test, Lambda, UpMyIPBuild)
}
// CI runs all CI tasks
func CI() {
mg.SerialDeps(Test, LambdaBuild, UpMyIPBuild)
}