Set up Mage build targets

Add magefiles/magefile.go with build automation targets:
- Test() - runs go test -v ./...
- Coverage() - runs tests with coverage profile output
- Lint() - runs staticcheck for static analysis
- Fmt() - formats all Go source files with gofmt
- Vet() - runs go vet for code analysis
- Check() - runs all quality checks in sequence (fmt, vet, lint, test)
- Clean() - removes build artifacts

Update magefiles/go.mod with github.com/magefile/mage dependency.

Closes checkvist-api-8q3
This commit is contained in:
Oliver Jakoubek 2026-01-14 13:33:14 +01:00
commit bf4d899eb8
4 changed files with 62 additions and 1 deletions

View file

@ -1,3 +1,5 @@
module code.beautifulmachines.dev/jakoubek/checkvist-api/magefiles
go 1.21
require github.com/magefile/mage v1.15.0

View file

@ -0,0 +1,2 @@
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=

View file

@ -3,4 +3,61 @@
// Package main provides Mage build targets for the checkvist-api module.
package main
import (
"fmt"
"os"
"os/exec"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
// magefile.go contains build targets: Test, Coverage, Lint, Fmt, Check.
// Default target when running mage without arguments.
var Default = Test
// Test runs all tests with verbose output.
func Test() error {
fmt.Println("Running tests...")
return sh.RunV("go", "test", "-v", "./...")
}
// Coverage runs tests with coverage reporting.
func Coverage() error {
fmt.Println("Running tests with coverage...")
return sh.RunV("go", "test", "-coverprofile=coverage.out", "./...")
}
// Lint runs staticcheck for static analysis.
func Lint() error {
fmt.Println("Running staticcheck...")
if _, err := exec.LookPath("staticcheck"); err != nil {
fmt.Println("staticcheck not found. Install with: go install honnef.co/go/tools/cmd/staticcheck@latest")
os.Exit(1)
}
return sh.RunV("staticcheck", "./...")
}
// Fmt formats all Go source files.
func Fmt() error {
fmt.Println("Formatting Go files...")
return sh.RunV("gofmt", "-w", ".")
}
// Vet runs go vet for code analysis.
func Vet() error {
fmt.Println("Running go vet...")
return sh.RunV("go", "vet", "./...")
}
// Check runs all quality checks: fmt, vet, staticcheck, and tests.
func Check() {
mg.SerialDeps(Fmt, Vet, Lint, Test)
}
// Clean removes build artifacts.
func Clean() error {
fmt.Println("Cleaning build artifacts...")
return sh.Rm("coverage.out")
}