-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagefile.go
71 lines (55 loc) · 1.43 KB
/
magefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//go:build mage
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/dosquad/mage/dyndep"
"github.com/dosquad/mage/helper"
"github.com/dosquad/mage/loga"
"github.com/magefile/mage/mg"
"github.com/na4ma4/go-permbits"
//mage:import
"github.com/dosquad/mage"
)
// TestLocal protoc, lint, test & build debug.
func TestLocal(ctx context.Context) {
mg.CtxDeps(ctx, mage.Golang.Lint)
mg.CtxDeps(ctx, DynamicDeps)
mg.CtxDeps(ctx, mage.Golang.Test)
}
var Default = TestLocal
const (
dyndepFileName = "artifacts/dyndep.test"
)
func DynamicDeps(ctx context.Context) error {
_ = os.Remove(dyndepFileName)
writeFile := func(ctx context.Context) error {
loga.PrintInfo("Running Dynamic Dependency for dyndep.Test")
_ = os.MkdirAll("artifacts", permbits.MustString("ug=rwx,o=rx"))
_ = os.Remove(dyndepFileName)
var f *os.File
{
var err error
f, err = os.Create(dyndepFileName)
if err != nil {
return err
}
}
defer f.Close()
if _, err := io.WriteString(f, "this-is-a-test-file\n"); err != nil {
return err
}
return nil
}
if helper.FileExists(dyndepFileName) {
return fmt.Errorf("DynamicDeps: file exists when it should have been deleted: %s", dyndepFileName)
}
dyndep.Add(dyndep.Test, writeFile)
mg.CtxDeps(ctx, mage.Golang.Test)
if !helper.FileExists(dyndepFileName) {
return fmt.Errorf("DynamicDeps: file does not exist when it should have been created: %s", dyndepFileName)
}
return nil
}