build: add a simple magefile

This commit is contained in:
Dan Anglin 2021-08-18 01:40:12 +01:00
parent 5dd56ae8ad
commit a170f90831
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 51 additions and 1 deletions

5
go.mod
View file

@ -2,4 +2,7 @@ module gitlab.com/dananglin/pelican
go 1.16
require go.etcd.io/bbolt v1.3.6
require (
github.com/magefile/mage v1.11.0
go.etcd.io/bbolt v1.3.6
)

2
go.sum
View file

@ -1,3 +1,5 @@
github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls=
github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d h1:L/IKR6COd7ubZrs2oTnTi73IhgqJ71c9s80WsQnh0Es=

45
magefile.go Normal file
View file

@ -0,0 +1,45 @@
//+build mage
package main
import (
"os"
"strings"
"github.com/magefile/mage/sh"
)
var Default = Build
// Clean clean the workspace
func Clean() error {
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") {
os.Remove(testDBDir + "/" + filename)
}
}
return nil
}
// Test run the go tests
func Test() error {
return sh.Run("go", "test", ".")
}
// Build build the executable
func Build() error {
return sh.Run("go", "build", ".")
}