From 16ce1d306f89f44974eb033056bc65c1be9a5f8a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 24 Sep 2025 22:30:20 +0300 Subject: move from Taskfile to Magefile --- Magefile.go | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 23 +++++++----- Taskfile.yml | 45 ---------------------- go.mod | 1 + go.sum | 2 + 5 files changed, 138 insertions(+), 54 deletions(-) create mode 100644 Magefile.go delete mode 100644 Taskfile.yml diff --git a/Magefile.go b/Magefile.go new file mode 100644 index 0000000..8b18265 --- /dev/null +++ b/Magefile.go @@ -0,0 +1,121 @@ +//go:build mage +// +build mage + +package main + +import ( + "fmt" + "os" + "os/exec" + + "github.com/magefile/mage/mg" +) + +// Default target to run when none is specified +// in preference to running all. +var Default = Build + +// A build step that requires additional params, or platform specific steps for example +func Build() error { + mg.Deps(BuildGos, BuildGosc) + return nil +} + +// A custom install step that runs after build +func Install() error { + mg.Deps(Build) + fmt.Println("Installing...") + err := os.Rename("./gos", os.ExpandEnv("$HOME/go/bin/gos")) + if err != nil { + return err + } + return os.Rename("./gosc", os.ExpandEnv("$HOME/go/bin/gosc")) +} + +// A step on it's own +func BuildGos() error { + fmt.Println("Building gos...") + cmd := exec.Command("go", "build", "-o", "gos", "cmd/gos/main.go") + return cmd.Run() +} + +// A step on it's own +func BuildGosc() error { + fmt.Println("Building gosc...") + cmd := exec.Command("go", "build", "-o", "gosc", "cmd/gosc/main.go") + return cmd.Run() +} + +// Run gos +func Run() error { + mg.Deps(Dev) + fmt.Println("Running...") + cmd := exec.Command("go", "run", "cmd/gos/main.go") + return cmd.Run() +} + +// Run development steps +func Dev() error { + mg.Deps(Test, Vet, Lint) + fmt.Println("Building dev...") + cmd := exec.Command("go", "build", "-race", "-o", "gos", "cmd/gos/main.go") + if err := cmd.Run(); err != nil { + return err + } + cmd = exec.Command("go", "build", "-race", "-o", "gosc", "cmd/gosc/main.go") + return cmd.Run() +} + +// Run tests +func Test() error { + fmt.Println("Testing...") + cmd := exec.Command("go", "clean", "-testcache") + if err := cmd.Run(); err != nil { + return err + } + cmd = exec.Command("go", "test", "-v", "./...") + return cmd.Run() +} + +// Run fuzz tests +func Fuzz() error { + fmt.Println("Fuzzing...") + cmd := exec.Command("go", "clean", "-testcache") + if err := cmd.Run(); err != nil { + return err + } + cmd = exec.Command("go", "test", "./internal/entry/", "-fuzz=FuzzExtractURLs", "-fuzztime=10s") + return cmd.Run() +} + +// Run vet +func Vet() error { + fmt.Println("Vetting...") + cmd := exec.Command("go", "vet", "./...") + return cmd.Run() +} + +// Run lint +func Lint() error { + fmt.Println("Linting...") + cmd := exec.Command("golangci-lint", "run") + return cmd.Run() +} + +// Install dev tools +func DevInstall() error { + fmt.Println("Installing dev tools...") + cmd := exec.Command("go", "install", "golang.org/x/tools/gopls@latest") + if err := cmd.Run(); err != nil { + return err + } + cmd = exec.Command("go", "install", "github.com/golangci/golangci-lint/cmd/golangci-lint@latest") + return cmd.Run() +} + +// Clean up after build +func Clean() { + fmt.Println("Cleaning...") + os.RemoveAll("gos") + os.RemoveAll("gosc") +} diff --git a/README.md b/README.md index 82dbe16..971b6ad 100644 --- a/README.md +++ b/README.md @@ -35,20 +35,25 @@ git clone https://codeberg.org/snonux/gos.git cd gos ``` -Build the binaries: +Build and install the binaries: ```bash -go build -o gos ./cmd/gos -go build -o gosc ./cmd/gosc -sudo mv gos ~/go/bin -sudo mv gosc ~/go/bin +mage install ``` -Or, if you want to use the `Taskfile`: +### Mage targets -```bash -go-task install -``` +This project uses Mage for automation. Here are some common commands: + +* `mage` or `mage build`: Build the `gos` and `gosc` binaries. +* `mage install`: Build and install the binaries to `~/go/bin`. +* `mage clean`: Remove the built binaries. +* `mage test`: Run the tests. +* `mage fuzz`: Run the fuzz tests. +* `mage lint`: Run the linter. +* `mage vet`: Run `go vet`. +* `mage dev`: Run tests, vet, and lint, then build the binaries with the race detector. +* `mage devInstall`: Install `gopls` and `golangci-lint`. ## Configuration diff --git a/Taskfile.yml b/Taskfile.yml deleted file mode 100644 index b8d3984..0000000 --- a/Taskfile.yml +++ /dev/null @@ -1,45 +0,0 @@ -version: '3' - -tasks: - default: - deps: ["build"] - install: - deps: ["build"] - cmds: - - cp -v ./gos ~/go/bin/ - - cp -v ./gosc ~/go/bin/ - run: - deps: ["dev"] - cmds: - - go run cmd/gos/main.go - build: - deps: ["buildgos", "buildgosc"] - buildgos: - cmds: - - go build -o gos cmd/gos/main.go - buildgosc: - cmds: - - go build -o gosc cmd/gosc/main.go - dev: - deps: ["test", "vet", "lint"] - cmds: - - go build -race -o gos cmd/gos/main.go - - go build -race -o gosc cmd/gosc/main.go - test: - cmds: - - go clean -testcache - - go test -v ./... - fuzz: - cmds: - - go clean -testcache - - go test ./internal/entry/ -fuzz=FuzzExtractURLs -fuzztime=10s - vet: - cmds: - - go vet ./... - lint: - cmds: - - golangci-lint run - dev-install: - cmds: - - go install golang.org/x/tools/gopls@latest - - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest diff --git a/go.mod b/go.mod index d1eddef..a200055 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( cloud.google.com/go/compute/metadata v0.6.0 // indirect github.com/buger/goterm v1.0.4 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/magefile/mage v1.15.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/yuin/goldmark v1.7.8 // indirect diff --git a/go.sum b/go.sum index fb6d8fb..b0af85e 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= +github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= -- cgit v1.2.3