pelican/magefiles/magefile.go
Dan Anglin cf7c61637f
chore: update project
- update dependencies.
- a little bit of project restructuring.
- update test to make sure they pass.
- move magefile.go to magefiles directory.
2023-04-22 06:19:50 +01:00

73 lines
1.2 KiB
Go

//go:build mage
package main
import (
"os"
"strings"
"github.com/magefile/mage/sh"
)
const (
binary = "canal"
)
var Default = Build
// Test run the go tests
// To enable verbose mode set CANAL_TEST_VERBOSE=1.
// To enable coverage mode set CANAL_TEST_COVER=1.
func Test() error {
goTest := sh.RunCmd("go", "test")
args := []string{"./..."}
if os.Getenv("CANAL_TEST_VERBOSE") == "1" {
args = append(args, "-v")
}
if os.Getenv("CANAL_TEST_COVER") == "1" {
args = append(args, "-cover")
}
return goTest(args...)
}
// Lint runs golangci-lint against the code.
func Lint() error {
return sh.RunV("golangci-lint", "run", "--color", "always")
}
// Build build the executable
func Build() error {
main := "./cmd/canal/main.go"
return sh.Run("go", "build", "-o", binary, main)
}
// Clean clean the workspace
func Clean() error {
if err := sh.Rm(binary); err != nil {
return err
}
if err := sh.Run("go", "clean", "./..."); err != nil {
return err
}
testDBDir := "./test/databases"
files, err := os.ReadDir(testDBDir)
if err != nil {
return err
}
for _, f := range files {
filename := f.Name()
if strings.HasSuffix(filename, ".db") {
sh.Rm(testDBDir + "/" + filename)
}
}
return nil
}