summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-24 22:30:20 +0300
committerPaul Buetow <paul@buetow.org>2025-09-24 22:30:20 +0300
commit16ce1d306f89f44974eb033056bc65c1be9a5f8a (patch)
tree5899c8f35cb43e2193457819d1c39290d8820520
parent95997ba2eb4de80b02245bacbf15e881adafd73c (diff)
move from Taskfile to Magefile
-rw-r--r--Magefile.go121
-rw-r--r--README.md23
-rw-r--r--Taskfile.yml45
-rw-r--r--go.mod1
-rw-r--r--go.sum2
5 files changed, 138 insertions, 54 deletions
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=