|
| 1 | +//go:build mage |
| 2 | +// +build mage |
| 3 | + |
| 4 | +package main |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "os" |
| 9 | + |
| 10 | + "github.com/magefile/mage/sh" |
| 11 | +) |
| 12 | + |
| 13 | +// CI runs all validation checks (tests, linting, coverage, benchmarks) |
| 14 | +func CI() error { |
| 15 | + fmt.Println("Running full CI validation...") |
| 16 | + |
| 17 | + if err := Test(); err != nil { |
| 18 | + return err |
| 19 | + } |
| 20 | + |
| 21 | + if err := Lint(); err != nil { |
| 22 | + return err |
| 23 | + } |
| 24 | + |
| 25 | + if err := Benchmark(); err != nil { |
| 26 | + return err |
| 27 | + } |
| 28 | + |
| 29 | + fmt.Println("All CI checks passed!") |
| 30 | + return nil |
| 31 | +} |
| 32 | + |
| 33 | +// Test runs all tests with race detection and coverage |
| 34 | +func Test() error { |
| 35 | + fmt.Println("Running tests with race detection...") |
| 36 | + if err := sh.RunV("go", "test", "-v", "-race", "-coverprofile=coverage.out", "./..."); err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + |
| 40 | + fmt.Println("Generating coverage report...") |
| 41 | + return sh.RunV("go", "tool", "cover", "-func=coverage.out") |
| 42 | +} |
| 43 | + |
| 44 | +// Lint runs golangci-lint |
| 45 | +func Lint() error { |
| 46 | + fmt.Println("Running linter...") |
| 47 | + return sh.RunV("golangci-lint", "run", "--timeout=5m") |
| 48 | +} |
| 49 | + |
| 50 | +// Benchmark runs all benchmarks |
| 51 | +func Benchmark() error { |
| 52 | + fmt.Println("Running benchmarks...") |
| 53 | + return sh.RunV("go", "test", "-bench=.", "-benchmem") |
| 54 | +} |
| 55 | + |
| 56 | +// Clean removes build artifacts and coverage files |
| 57 | +func Clean() error { |
| 58 | + fmt.Println("Cleaning build artifacts...") |
| 59 | + os.Remove("coverage.out") |
| 60 | + return nil |
| 61 | +} |
| 62 | + |
| 63 | +// Fmt formats all Go code |
| 64 | +func Fmt() error { |
| 65 | + fmt.Println("Formatting code...") |
| 66 | + return sh.RunV("go", "fmt", "./...") |
| 67 | +} |
| 68 | + |
| 69 | +// Vet runs go vet |
| 70 | +func Vet() error { |
| 71 | + fmt.Println("Running go vet...") |
| 72 | + return sh.RunV("go", "vet", "./...") |
| 73 | +} |
| 74 | + |
| 75 | +// ModTidy tidies go.mod |
| 76 | +func ModTidy() error { |
| 77 | + fmt.Println("Tidying go.mod...") |
| 78 | + return sh.RunV("go", "mod", "tidy") |
| 79 | +} |
0 commit comments