-
Notifications
You must be signed in to change notification settings - Fork 0
/
mage.go
132 lines (111 loc) · 2.99 KB
/
mage.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// ==========================================================================================================
// <copyright>COPYRIGHT © InfoVista Sweden AB</copyright>
//
// The copyright of the computer program herein is the property of InfoVista Sweden AB.
// The program may be used and/or copied only with the written permission from InfoVista Sweden AB
// or in the accordance with the terms and conditions stipulated in the agreement/contract under which
// the program has been supplied.
// ==========================================================================================================
//go:build mage
// +build mage
// The SiteVerification Microservice build targets.
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// Install the binaries.
func Build() error {
mg.Deps(ToolInstall)
version := os.Getenv("BUILDVERSION")
if version == "" {
version = "dev"
}
buildTime, err := sh.Output("date", "--iso-8601=seconds")
if err != nil {
return err
}
commit, err := sh.Output("git", "rev-parse", "--short", "HEAD")
if err != nil {
return err
}
return sh.Run("go",
"install",
fmt.Sprintf("-ldflags= -X main.version=%s -X main.commit=%s -X main.buildTime=%s", version, commit, buildTime),
"./...")
}
// Performs a lint analysis on the Go code
func Lint() error {
mg.Deps(ToolInstall)
return sh.RunV("golangci-lint", "run")
}
// Performs a Vulnerability check on the Go code
func Vuln() error {
mg.Deps(ToolInstall)
return sh.RunV("govulncheck", "./...")
}
// Run the tests.
func Test() error {
mg.Deps(ToolInstall)
return sh.Run("ginkgo", "--timeout", "1m", "--no-color", "--race", "-v", "./...")
}
// Cleans the binaries.
func Clean() error {
return sh.Run("go", "clean", "./...")
}
// Run the tests in watch mode.
func Watch() error {
mg.Deps(ToolInstall)
return sh.Run("ginkgo", "watch", "./...")
}
// Updates the module dependencies.
func Update() error {
return sh.Run("go", "get", "-u", "./...")
}
// Creates a release using goreleaser
func Release() error {
mg.Deps(ToolInstall)
return sh.Run("goreleaser", "release", "--snapshot", "--skip=publish", "--skip=sign", "--clean")
}
// Creates a release using goreleaser
func ReleaseCI() error {
mg.Deps(ToolInstall)
return sh.Run("goreleaser", "release", "--clean")
}
// Install all tool dependencies
func ToolInstall() error {
tools, err := findTools()
if err != nil {
return err
}
for _, t := range tools {
if err := sh.Run("go", "install", t); err != nil {
return err
}
}
return nil
}
func findTools() ([]string, error) {
f, err := os.Open("tools.go")
if err != nil {
return nil, err
}
defer f.Close()
var tools []string
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := strings.Trim(scanner.Text(), " \t")
if strings.HasPrefix(line, "_") {
tokens := strings.Split(line, " ")
tools = append(tools, strings.Trim(tokens[1], "\""))
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return tools, nil
}