-
Notifications
You must be signed in to change notification settings - Fork 13
/
Bladefile
89 lines (73 loc) · 2.57 KB
/
Bladefile
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local sh = require('sh')
--<version> [name] [description] - cross compile and create release on Github
function target.release(version, name, description)
assert(version, "fatal: no version specified")
name = name or string.format("limes %s", version)
description = description or string.format("limes %s", version)
preRelease = ""
if not string.match(version, "^v%d[.]%d[.]%d$") then
if string.match(version, "^v%d[.]%d[.]%d%-beta%d$") then
preRelease = "--pre-release"
else
error("fatal: version must be on the form 'vX.X.X'")
end
end
exitCode, output = blade._exec('git status --porcelain')
if output ~= "" then
error("fatal: uncommited changes")
end
target.build(version)
blade.sh('git tag ' .. version)
blade.sh('git push --tags')
blade.sh(string.format("github-release release --user otm --repo limes --tag %s --name '%s' --description '%s' %s", version, name, description, preRelease))
for file in io.popen("ls -1 limes_*"):lines() do
code = blade.system(string.format("github-release upload --user otm --repo limes --tag %s --name %s --file %s", version, file, file))
blade.printStatus(file, code)
end
end
-- blade.flag(target.release, function(flag)
-- flag:string("version", "version", "The version to release", function()
-- return sh.git("tag"):stdout()
-- end)
-- flag:stringArg("name", 1, "The name of the release")
-- flag:stringArg("description", 1, "The description of the release")
-- end)
-- blade.compgen(target.release, function(compWords, compCWord)
-- if compCWord == 1 then
-- code, out = blade._sh("git tag")
-- return out
-- end
-- end)
--clean working directory of builds
function target.clean()
blade.exec("rm limes limes_*")
end
--cross compile
function target.build(version, date)
sh.go("generate")
version = version or "dev-build"
date = os.date("%Y-%m-%d %H:%M:%S")
ldflags=string.format("-X main.version=%s -X 'main.date=%s'", version, date)
sh.gox("-os", "linux darwin", "-ldflags", ldflags):print()
end
--download, install and setup gox for cross compile
function target.goxSetup()
blade.sh("go get github.com/mitchellh/gox")
blade.sh("go install github.com/mitchellh/gox")
go("gox -build-toolchain", {sudo=true})
end
function gocmd(cmd)
code, gopath = blade.system("go env GOPATH")
gopath = (gopath:gsub("^%s*(.-)%s*$", "%1"))
return gopath .. "/bin/" .. cmd
end
function go(cmd, options)
code, gopath = blade.system("go env GOPATH")
gopath = (gopath:gsub("^%s*(.-)%s*$", "%1"))
cmd = gopath .. "/bin/" .. cmd
print(cmd)
if options and options.sudo then
return sh.sudo(cmd):print()
end
return sh(cmd):print()
end