From e7ec5361e895bab7310a2b6ce09d04227e07a328 Mon Sep 17 00:00:00 2001 From: Softonik Date: Sat, 29 Jun 2024 01:35:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20Magefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Magefile.go | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Magefile.go diff --git a/Magefile.go b/Magefile.go new file mode 100644 index 0000000..adbc717 --- /dev/null +++ b/Magefile.go @@ -0,0 +1,78 @@ +//go:build mage +// +build mage + +package main + +import ( + // mage:import + . "magefile/docker" +) + +var ( + GolangVolume = "golang.upstream" + MyGoImageName = "my/go" + GOPATH = "/gopath" + GOCACHE = GOPATH + "/gocache" + GoPathMount = "-v " + GOPATH + ":" + GOPATH + ":rw" + GoPathEnv = "-e GOPATH=" + GOPATH + GoCacheEnv = "-e GOCACHE=" + GOCACHE + GolangMount = "-v " + GolangVolume + ":/usr/local/go:ro" + GoAll = GolangMount + ` \ + ` + GoPathMount + ` \ + ` + GoPathEnv + ` \ + ` + GoCacheEnv + + tests_to_run = []string{} +) + +func init() { + AppName = "schet" + ImageName = "my/go" + NetName = "none" + + RunFn = run +} + +func run() error { + err := BuildCMD() + if err != nil { + return err + } + + return Bash(`./schet config.json statement.txt`) +} + +func BuildCMD() error { + return Bash(`go build -o schet cmd/schet/main.go `) +} + +func Test() { + runTests("./...", false) +} +func TestVerbose() { + runTests("./...", true) +} + +func runTests(path string, verbose bool) error { + v := "" + if verbose { + v = "-v" + } + return Bash(`sudo docker run -ti --rm \ + -h host \ + --net=none \ + -v /etc/localtime:/etc/localtime:ro \ + \ + ` + GoAll + ` \ + \ + -v ${PWD}:/app \ + \ + -w /app \ + -u 1000 \ + \ + --entrypoint=/bin/bash \ + \ + ` + ImageName + " -c '" + ` \ + go test ` + v + ` -gcflags=-l -count=1 ` + path + ` + '`) +}