-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmagefile.go
66 lines (50 loc) · 1.4 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
package main
import (
"fmt"
"os"
"github.com/fatih/color"
utils "github.com/l50/goutils"
// mage utility functions
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
func init() {
os.Setenv("GO111MODULE", "on")
}
// InstallDeps Installs go dependencies
func InstallDeps() error {
fmt.Println(color.YellowString("Installing dependencies."))
if err := utils.InstallGoPCDeps(); err != nil {
return fmt.Errorf(color.RedString(
"failed to install pre-commit dependencies: %v", err))
}
return nil
}
// InstallPreCommitHooks Installs pre-commit hooks locally
func InstallPreCommitHooks() error {
mg.Deps(InstallDeps)
fmt.Println(color.YellowString("Installing pre-commit hooks."))
if err := utils.InstallPCHooks(); err != nil {
return err
}
return nil
}
// RunPreCommit runs all pre-commit hooks locally
func RunPreCommit() error {
mg.Deps(InstallDeps)
fmt.Println(color.YellowString("Updating pre-commit hooks."))
if err := utils.UpdatePCHooks(); err != nil {
return err
}
fmt.Println(color.YellowString(
"Clearing the pre-commit cache to ensure we have a fresh start."))
if err := utils.ClearPCCache(); err != nil {
return err
}
fmt.Println(color.YellowString("Running all pre-commit hooks locally."))
if err := sh.RunV("pre-commit", "run", "--all-files"); err != nil {
return fmt.Errorf(color.RedString("failed to run unit tests: %v", err))
}
return nil
}