-
Notifications
You must be signed in to change notification settings - Fork 5
/
release.go
68 lines (58 loc) · 1.61 KB
/
release.go
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
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/progrium/go-shell"
"github.com/spf13/cobra"
)
func init() {
Glu.AddCommand(releaseCmd)
}
var releaseCmd = &cobra.Command{
Use: "release [release-name] [checksum-hash]",
Short: "Creates a github release using gh-release",
Run: func(cmd *cobra.Command, args []string) {
var (
info = NewProjectInfo()
githubRepo = info.Owner + "/" + info.Name
version = info.Version
releaseName = optArg(args, 0, version)
checksumHash = optArg(args, 1, "")
arch = shellOutput("uname -m")
branch = shellOutput("git rev-parse --abbrev-ref HEAD")
)
defer shell.ErrExit()
shell.Trace = true
shell.Tee = os.Stdout
sh("go get -u github.com/progrium/gh-release/...")
sh("rm -rf release")
sh("mkdir release")
for _, platform := range []string{"Linux", "Darwin"} {
if binary := detectBinaryBuild(platform); binary != "" {
// tar -zcf release/$(NAME)_$(VERSION)_$(PLATFORM)_$(ARCH).tgz -C build/$(PLATFORM) $(BINARYNAME)
sh("tar -zcf",
fmt.Sprintf("release/%s_%s_%s_%s.tgz", info.Name, version, platform, arch),
"-C build/"+platform, binary)
}
}
if dir, _ := ioutil.ReadDir("release"); len(dir) == 0 {
sh("cp build/* release")
}
if checksumHash != "" {
sh("gh-release checksums", checksumHash)
}
sh("gh-release create", githubRepo, version, branch, releaseName)
},
}
func detectBinaryBuild(platform string) string {
if !exists("build", platform) {
return ""
}
dir, err := ioutil.ReadDir("build/" + platform)
fatal(err)
if len(dir) != 1 {
return ""
}
return dir[0].Name()
}