-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMagefile.go
79 lines (59 loc) · 1.67 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
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
// mg contains helpful utility functions, like Deps
)
// Default target to run when none is specified
// If not set, running mage will list available targets
// var Default = Build
func getExecutableName(os string, arch string) string {
exeName := fmt.Sprintf("%s_%s_%s", "grafana-dashboard-synchronizer", os, arch)
if os == "windows" {
exeName = fmt.Sprintf("%s.exe", exeName)
}
return exeName
}
// A build step that requires additional params, or platform specific steps for example
func buildPlatform(os string, arch string) error {
exeName := getExecutableName(os, arch)
envMap := make(map[string]string)
envMap["GOARCH"] = arch
envMap["GOOS"] = os
// TODO: Change to sh.RunWithV once available.
return sh.RunWith(envMap, "go", "build", "-o", filepath.Join("dist", exeName), "./pkg")
}
func BuildWindows() error {
return buildPlatform("windows", "amd64")
}
func BuildLinux() error {
return buildPlatform("linux", "amd64")
}
func BuildLinuxARM() error {
return buildPlatform("linux", "arm")
}
func BuildLinuxARM64() error {
return buildPlatform("linux", "arm64")
}
func BuildDarwin() error {
return buildPlatform("darwin", "amd64")
}
func BuildDarwinARM64() error {
return buildPlatform("darwin", "arm64")
}
func BuildAll() { //revive:disable-line
mg.Deps(Clean)
fmt.Println("Building all platforms...")
mg.Deps(BuildWindows, BuildLinux, BuildLinuxARM, BuildLinuxARM64, BuildDarwin, BuildDarwinARM64)
}
// Clean up after yourself
func Clean() {
fmt.Println("Cleaning...")
os.RemoveAll("dist")
}
var Default = BuildAll