Skip to content

Commit 795013a

Browse files
committed
Small CI tweaks
Signed-off-by: jose.vazquez <[email protected]>
1 parent 246c47a commit 795013a

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

tools/crd2go/magefile.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ import (
2727

2828
// CI runs all linting and validation checks.
2929
func CI() {
30-
mg.SerialDeps(Build, UnitTests, Addlicense, Checklicense, GCI, Lint, Govulncheck)
30+
mg.Deps(Build, UnitTests, Addlicense, Checklicense, CheckGCI, Lint, Govulncheck)
3131
fmt.Println("✅ CI PASSED all checks")
3232
}
3333

3434
// Build checks all execitable build properly
3535
func Build() error {
36-
return wrapRun("🛠️ Building...", "go", "build", "./...")
36+
return wrapRun("🛠️ Build", "go", "build", "./...")
3737
}
3838

3939
// UnitTests runs the go tests
4040
func UnitTests() error {
41-
return wrapRun("🧪 Running unit tests:\n", "go", "test", "-cover", "./...")
41+
return wrapRun("🧪 Unit tests", "go", "test", "-cover", "./...")
4242
}
4343

4444
// Addlicense runs the addlicense check to ensure source files have license headers
4545
func Addlicense() error {
46-
return wrapRun("🛠️ Running license header check...",
46+
return wrapRun("🛠️ License header check",
4747
"go", "tool",
4848
"addlicense",
4949
"-check",
@@ -62,7 +62,7 @@ func Addlicense() error {
6262

6363
// Checklicense runs the go-licenses tool to check license compliance
6464
func Checklicense() error {
65-
return wrapRun("🔬 Running license compliance checks:\n",
65+
return wrapRun("🔬 License compliance check",
6666
"go", "tool",
6767
"go-licenses", "check",
6868
"--include_tests",
@@ -73,52 +73,53 @@ func Checklicense() error {
7373

7474
// GCI runs gci to check that Go import orders are correct
7575
func GCI() error {
76-
fmt.Println("🧹 Formatting Go imports...")
77-
if err := sh.RunV(
76+
return wrapRun("🧹 Format code",
7877
"go", "tool",
7978
"gci", "write",
8079
"--skip-generated",
8180
"-s", "standard",
8281
"-s", "default",
8382
"-s", "localmodule",
8483
".",
85-
); err != nil {
86-
return fmt.Errorf("gci write command failed: %w", err)
87-
}
84+
)
85+
}
8886

89-
fmt.Println("🔍 Checking for changes...")
87+
// GitClean check git is clean of changes
88+
func GitClean() error {
9089
if err := sh.Run("git", "diff-index", "--quiet", "HEAD", "--"); err != nil {
91-
fmt.Println("❗️ Go files were not correctly formatted. The following files have changes:")
90+
fmt.Println("❗️ The following files have changes:")
9291
sh.RunV("git", "diff-index", "--name-only", "HEAD")
93-
return fmt.Errorf("please run 'mage gci' and commit the changes")
92+
return fmt.Errorf("please run 'mage gci' and commit any changes")
9493
}
95-
96-
fmt.Println("✅ Go imports are correctly formatted.")
9794
return nil
9895
}
9996

97+
// CheckGCI check GCI formatting was committed as expected
98+
func CheckGCI() {
99+
mg.SerialDeps(GCI, GitClean)
100+
}
101+
100102
// Lint runs the golangci-lint tool
101103
func Lint() error {
102104
if err := os.Setenv("CGO_ENABLED", "0"); err != nil {
103105
return nil
104106
}
105-
return wrapRun("▶️ Run linting...",
107+
return wrapRun("🔬 Lint check",
106108
"go", "tool", "golangci-lint", "run",
107109
"./cmd/...", "./internal/...", "./k8s/...", "./pkg/...")
108110
}
109111

110112
// Govulncheck checks for Go toolchain or library vulnerabilities
111113
func Govulncheck() error {
112-
return wrapRun("🔬 Running Go Vulnerability Check:\n",
114+
return wrapRun("🔬 Vulnerability Check",
113115
"go", "tool", "govulncheck", "./...")
114116
}
115117

116-
func wrapRun(msg, cmd string, args ...string) error {
117-
fmt.Print(msg)
118+
func wrapRun(action, cmd string, args ...string) error {
119+
fmt.Printf("▶️ Started: %s\n", action)
118120
if err := sh.RunV(cmd, args...); err != nil {
119-
fmt.Println()
120121
return err
121122
}
122-
fmt.Println("✅ Success")
123+
fmt.Printf("✅ Succeeded: %s\n", action)
123124
return nil
124125
}

0 commit comments

Comments
 (0)