-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmagefile.go
66 lines (54 loc) · 1.36 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
//go:build mage
// +build mage
package main
import (
"os"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
var Default = PHONY
func PHONY() {
mg.Deps(Clean, Build, Deploy, Remove)
}
// clean remove all bin
func Clean() error {
return sh.Rm("bin")
}
// build build each module into "bin"
func Build() error {
mg.Deps(Clean)
os.Setenv("GO111MODULE", "on")
os.Setenv("GOOS", "linux")
gobuild := sh.RunCmd("go", "build", "-ldflags", "-s -w", "-o")
bins := []struct {
output string
source string
}{
{"bin/books/endpoints/create", "modules/books/endpoints/create.go"},
{"bin/books/endpoints/read", "modules/books/endpoints/read.go"},
{"bin/books/endpoints/detail", "modules/books/endpoints/detail.go"},
{"bin/books/endpoints/update", "modules/books/endpoints/update.go"},
{"bin/books/endpoints/delete", "modules/books/endpoints/delete.go"},
{"bin/books/functions/worker", "modules/books/functions/worker.go"},
}
for _, bin := range bins {
err := gobuild(bin.output, bin.source)
if err != nil {
return err
}
}
return nil
}
// test run all go tests
func Test() error {
return sh.Run("go", "test", "./...")
}
// deploy force deployment to default
func Deploy() error {
mg.Deps(Clean, Build)
return sh.Run("serverless", "deploy", "--verbose", "--force")
}
func Remove() error {
mg.Deps(Clean)
return sh.Run("serverless", "remove")
}