pelican/magefiles/mage.go
Dan Anglin 155dab0918
Some checks failed
/ test (pull_request) Successful in 28s
/ lint (pull_request) Failing after 3m41s
chore: project maintenance
Changes:

- Changed README from Markdown to Asciidoc
- Updated go.mod and go.sum
- Updated magefiles for CI
- Added workflow for Forgejo Actions
2023-12-12 10:05:25 +00:00

73 lines
1.2 KiB
Go

//go:build mage
package main
import (
"os"
"strings"
"github.com/magefile/mage/sh"
)
const (
binary = "pelican"
)
var Default = Build
// Test run the go tests
// To enable verbose mode set PELICAN_TEST_VERBOSE=1.
// To enable coverage mode set PELICAN_TEST_COVER=1.
func Test() error {
goTest := sh.RunCmd("go", "test")
args := []string{"./..."}
if os.Getenv("PELICAN_TEST_VERBOSE") == "1" {
args = append(args, "-v")
}
if os.Getenv("PELICAN_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/"+binary+"/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
}