-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
113 lines (84 loc) · 2.06 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//go:build mage
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const cliBuildDst = "./build/cli/"
const lambdaBuildDst = "./build/lambdas/"
func clearCli() error {
return sh.Run("rm", "-rf", cliBuildDst)
}
func clearLambdas() error {
return sh.Run("rm", "-rf", lambdaBuildDst)
}
// Clears contents of ./build directory.
func Clear() error {
mg.Deps(clearCli)
mg.Deps(clearLambdas)
return nil
}
// Builds the cli version of the app.
func Cli() error {
mg.Deps(clearCli)
if err := sh.Run("go", "mod", "download"); err != nil {
return err
}
env := map[string]string{
"GOOS": runtime.GOOS,
"GOARCH": runtime.GOARCH,
"CGO_ENABLED": "0",
}
cliBuildDst := filepath.Join(cliBuildDst, "fpc")
cliSrc := "./cmd/cli"
_, err := sh.Exec(env, os.Stdout, os.Stderr, "go", "build", "-v", "-ldflags="+"-w -s", "-o", cliBuildDst, cliSrc)
return err
}
func lambda(lambdaName string) error {
env := map[string]string{
"GOOS": "linux",
"GOARCH": "amd64",
"CGO_ENABLED": "0",
}
if err := sh.Run("go", "mod", "download"); err != nil {
return err
}
lambdaBinDst := filepath.Join(lambdaBuildDst, lambdaName)
zipDst := filepath.Join(lambdaBuildDst, fmt.Sprintf("%s.zip", lambdaName))
lambdaSrc := fmt.Sprintf("./cmd/lambdas/%s", lambdaName)
if _, err := sh.Exec(env, os.Stdout, os.Stderr, "go", "build", "-v",
"-o", lambdaBinDst, lambdaSrc); err != nil {
return err
}
if _, err := sh.Exec(env, os.Stdout, os.Stderr, "zip", "-j",
zipDst, lambdaBinDst); err != nil {
return err
}
return nil
}
func lambdaFetch() error {
return lambda("fetch")
}
func lambdaGenerate() error {
return lambda("generate")
}
func lambdaGet() error {
return lambda("get")
}
// Builds lambda-based version of the app.
func Lambdas() error {
mg.Deps(clearLambdas)
mg.Deps(lambdaFetch)
mg.Deps(lambdaGenerate)
mg.Deps(lambdaGet)
return nil
}
// Runs all tests.
func Test() error {
_, err := sh.Exec(nil, os.Stdout, os.Stderr, "go", "test", "./...", "-cover")
return err
}