-
Notifications
You must be signed in to change notification settings - Fork 0
/
mage.go
72 lines (63 loc) · 1.62 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
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// The default target when the command executes `mage` in Cloud Shell
var Default = Full
// A build step that runs Clean, Format, Unit and Integration in sequence
func Full() {
mg.Deps(Format)
mg.Deps(Integration)
}
// A build step that runs unit tests
func Unit() error {
mg.Deps(Clean)
mg.Deps(Format)
fmt.Println("Running unit tests...")
return sh.RunV("go", "test", "test/", "-v")
}
// A build step that runs integration tests
func Integration() error {
mg.Deps(Clean)
mg.Deps(Format)
fmt.Println("Running integration tests...")
return sh.RunV("go", "test", "./test/", "-v")
}
// A build step that formats both Terraform code and Go code
func Format() error {
fmt.Println("Formatting...")
if err := sh.RunV("terraform", "fmt", "."); err != nil {
return err
}
return sh.RunV("go", "fmt", "./test/")
}
// A build step that removes temporary build and test files
func Clean() error {
fmt.Println("Cleaning...")
return filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() && info.Name() == "vendor" {
return filepath.SkipDir
}
if info.IsDir() && info.Name() == ".terraform" {
os.RemoveAll(path)
fmt.Printf("Removed \"%v\"\n", path)
return filepath.SkipDir
}
if !info.IsDir() && (info.Name() == "terraform.tfstate" ||
info.Name() == "terraform.tfplan" ||
info.Name() == "terraform.tfstate.backup") {
os.Remove(path)
fmt.Printf("Removed \"%v\"\n", path)
}
return nil
})
}