Skip to content

Commit cf03322

Browse files
committed
WIP: Add magefile support
1 parent 5fed7b4 commit cf03322

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/gofrs/flock v0.7.1
1212
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
1313
github.com/kr/pretty v0.1.0 // indirect
14+
github.com/magefile/mage v1.9.0
1415
github.com/mattn/go-colorable v0.1.0 // indirect
1516
github.com/mattn/go-ieproxy v0.0.0-20190805055040-f9202b1cfdeb
1617
github.com/mattn/go-isatty v0.0.4 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
2727
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2828
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2929
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
30+
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
31+
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
3032
github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
3133
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
3234
github.com/mattn/go-ieproxy v0.0.0-20190805055040-f9202b1cfdeb h1:hXqqXzQtJbENrsb+rsIqkVqcg4FUJL0SQFGw08Dgivw=

magefile.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//+build mage
2+
3+
// This is the mage-based buildfile (magefile, https://magefile.org/) for trivrost.
4+
// Project: https://setlog.github.io/trivrost/
5+
//
6+
// To use this magefile, install 'mage' and just run 'mage' within this directory.
7+
package main
8+
9+
import (
10+
//"log"
11+
"github.com/magefile/mage/mg"
12+
"github.com/magefile/mage/sh"
13+
"regexp"
14+
"runtime"
15+
"time"
16+
)
17+
18+
const modulePathLauncher = "github.com/setlog/trivrost/cmd/launcher"
19+
const modulePathHasher = "github.com/setlog/trivrost/cmd/hasher"
20+
const modulePathValidator = "github.com/setlog/trivrost/cmd/validator"
21+
const modulePathSigner = "github.com/setlog/trivrost/cmd/signer"
22+
const outDir = "out"
23+
const releaseFilesDir = outDir + "/release_files"
24+
const updateFilesDir = outDir + "/update_files"
25+
26+
const hasherBinary = "hasher"
27+
const validatorBinary = "validator"
28+
const signerBinary = "signer"
29+
// allow custom launcher name
30+
var launcherBinary, _ = sh.Output("go", "run", "cmd/echo_field/main.go", "cmd/launcher/resources/launcher-config.json", "BinaryName")
31+
var launcherMsiBinary = launcherBinary
32+
var launcherBrandingName, _ = sh.Output("go", "run", "cmd/echo_field/main.go", "cmd/launcher/resources/launcher-config.json", "BrandingName")
33+
34+
var launcherVersion = version()
35+
var binaryExt = ext()
36+
var gitDesc
37+
38+
// Version is latest tag corresponding to version regex
39+
var versionPattern = regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+$`)
40+
func version() string {
41+
42+
versionPattern.MatchString()
43+
}
44+
45+
func ext() string {
46+
if runtime.GOOS == "windows" {
47+
return ".exe"
48+
} else {
49+
return ""
50+
}
51+
}
52+
53+
func
54+
55+
func init() {
56+
timestamp := time.Now().Format(time.RFC3339)
57+
hash := hash()
58+
tag := tag()
59+
if tag == "" {
60+
tag = "dev" + timestamp + hash
61+
}
62+
// fmt.Sprintf(`-X "github.com/magefile/mage/mage.timestamp=%s" -X "github.com/magefile/mage/mage.commitHash=%s" -X "github.com/magefile/mage/mage.gitTag=%s"`, timestamp, hash, tag)
63+
}
64+
65+
66+
67+
var gocmd = mg.GoCmd()
68+
var Default = Build
69+
70+
// Builds trivrost
71+
func Build() {
72+
mg.Deps(Generate)
73+
}
74+
75+
// Generates all required files
76+
func Generate() {
77+
println("a " + launcherProgramName)
78+
println("b " + launcherProgramExt)
79+
println("c " + launcherBrandingName)
80+
}
81+
82+
// Cleans up generated files
83+
func Clean() error {
84+
if len(outDir) == 0 {
85+
return mg.Fatal(1, "Output directory not set.")
86+
}
87+
_ = sh.Rm(outDir)
88+
_ = sh.Rm("cmd/launcher/resources/*.gen.go")
89+
_ = sh.Rm("cmd/launcher/*.syso")
90+
_ = sh.Run(gocmd, "clean", modulePathLauncher)
91+
_ = sh.Run(gocmd, "clean", modulePathHasher)
92+
return nil
93+
}
94+
95+
// tag returns the git tag for the current branch or "" if none.
96+
func tag() string {
97+
s, _ := sh.Output("git", "describe", "--tags")
98+
return s
99+
}
100+
101+
// hash returns the git hash for the current repo or "" if none.
102+
func hash() string {
103+
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
104+
return hash
105+
}

0 commit comments

Comments
 (0)