|
| 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