-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bladefile
65 lines (52 loc) · 1.74 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
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("blade %s", version)
description = description or string.format("blade %s", version)
if not string.match(version, "^v%d[.]%d[.]%d$") then
error("fatal: version must be on the form 'vX.X.X'")
end
exitCode, output = blade._exec('git status --porcelain')
if output ~= "" then
error("fatal: uncommited changes")
end
target.build()
blade.sh('git tag ' .. version)
blade.sh('git push --tags')
blade.sh(string.format("github-release release --user otm --repo blade --tag %s --name '%s' --description '%s'", version, name, description))
for file in io.popen("ls -1 blade_*"):lines() do
code = blade.system(string.format("github-release upload --user otm --repo blade --tag %s --name %s --file %s", version, file, file))
blade.printStatus(file, code)
end
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 blade blade_*")
end
--cross compile
function target.build()
sh.go("generate")
go("gox")
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 go(cmd, options)
code, gopath = blade.system("go env GOPATH")
gopath = (gopath:gsub("^%s*(.-)%s*$", "%1"))
cmd = gopath .. "/bin/" .. cmd
if options and options.sudo then
cmd = "sudo " .. cmd
end
return blade.sh(cmd)
end