|
| 1 | +local sh = require('sh') |
| 2 | + |
| 3 | +--<version> [name] [description] - cross compile and create release on Github |
| 4 | +function target.release(version, name, description) |
| 5 | + assert(version, "fatal: no version specified") |
| 6 | + |
| 7 | + name = name or string.format("limes %s", version) |
| 8 | + description = description or string.format("limes %s", version) |
| 9 | + |
| 10 | + if not string.match(version, "^v%d[.]%d[.]%d$") then |
| 11 | + error("fatal: version must be on the form 'vX.X.X'") |
| 12 | + end |
| 13 | + |
| 14 | + exitCode, output = blade._exec('git status --porcelain') |
| 15 | + if output ~= "" then |
| 16 | + error("fatal: uncommited changes") |
| 17 | + end |
| 18 | + |
| 19 | + target.build() |
| 20 | + blade.sh('git tag ' .. version) |
| 21 | + blade.sh('git push --tags') |
| 22 | + |
| 23 | + blade.sh(string.format("github-release release --user otm --repo limes --tag %s --name '%s' --description '%s'", version, name, description)) |
| 24 | + |
| 25 | + for file in io.popen("ls -1 limes_*"):lines() do |
| 26 | + code = blade.system(string.format("github-release upload --user otm --repo limes --tag %s --name %s --file %s", version, file, file)) |
| 27 | + blade.printStatus(file, code) |
| 28 | + end |
| 29 | +end |
| 30 | + |
| 31 | +-- blade.flag(target.release, function(flag) |
| 32 | +-- flag:string("version", "version", "The version to release", function() |
| 33 | +-- return sh.git("tag"):stdout() |
| 34 | +-- end) |
| 35 | +-- flag:stringArg("name", 1, "The name of the release") |
| 36 | +-- flag:stringArg("description", 1, "The description of the release") |
| 37 | +-- end) |
| 38 | + |
| 39 | +-- blade.compgen(target.release, function(compWords, compCWord) |
| 40 | +-- if compCWord == 1 then |
| 41 | +-- code, out = blade._sh("git tag") |
| 42 | +-- return out |
| 43 | +-- end |
| 44 | +-- end) |
| 45 | + |
| 46 | +--clean working directory of builds |
| 47 | +function target.clean() |
| 48 | + blade.exec("rm blade blade_*") |
| 49 | +end |
| 50 | + |
| 51 | +--cross compile |
| 52 | +function target.build() |
| 53 | + sh.go("generate") |
| 54 | + sh(gocmd("gox"), "-os", "linux darwin"):print() |
| 55 | +end |
| 56 | + |
| 57 | +--download, install and setup gox for cross compile |
| 58 | +function target.goxSetup() |
| 59 | + blade.sh("go get github.com/mitchellh/gox") |
| 60 | + blade.sh("go install github.com/mitchellh/gox") |
| 61 | + go("gox -build-toolchain", {sudo=true}) |
| 62 | +end |
| 63 | + |
| 64 | +function gocmd(cmd) |
| 65 | + code, gopath = blade.system("go env GOPATH") |
| 66 | + gopath = (gopath:gsub("^%s*(.-)%s*$", "%1")) |
| 67 | + return gopath .. "/bin/" .. cmd |
| 68 | +end |
| 69 | + |
| 70 | +function go(cmd, options) |
| 71 | + code, gopath = blade.system("go env GOPATH") |
| 72 | + gopath = (gopath:gsub("^%s*(.-)%s*$", "%1")) |
| 73 | + cmd = gopath .. "/bin/" .. cmd |
| 74 | + |
| 75 | + print(cmd) |
| 76 | + if options and options.sudo then |
| 77 | + return sh.sudo(cmd):print() |
| 78 | + end |
| 79 | + |
| 80 | + return sh(cmd):print() |
| 81 | +end |
0 commit comments