Skip to content

Commit eacfccc

Browse files
committed
update deps and use mage
1 parent 7a83065 commit eacfccc

File tree

6 files changed

+249
-20
lines changed

6 files changed

+249
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7+
/build
78

89
# Test binary, build with `go test -c`
910
*.test
@@ -12,5 +13,5 @@
1213
*.out
1314

1415
# Misc
15-
/release
16+
/dist
1617
.idea

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ go:
55
- master
66

77
script:
8-
- export GO111MODULE=on && make clean test fmt pack-all
8+
- export GO111MODULE=on && go run mage.go -v clean fmt test pack

go.mod

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module github.com/yinheli/sshw
22

33
require (
4-
github.com/chzyer/logex v1.1.10 // indirect
5-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
6-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
7-
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect
8-
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect
9-
github.com/manifoldco/promptui v0.3.0
10-
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0 // indirect
11-
github.com/mattn/go-isatty v0.0.4 // indirect
4+
github.com/BurntSushi/toml v0.3.1 // indirect
5+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
6+
github.com/magefile/mage v1.8.0
7+
github.com/manifoldco/promptui v0.3.2
8+
github.com/nicksnyder/go-i18n v1.10.0 // indirect
9+
github.com/pelletier/go-toml v1.2.0 // indirect
1210
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f
13-
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30 // indirect
14-
gopkg.in/yaml.v2 v2.2.1
11+
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
12+
gopkg.in/yaml.v2 v2.2.2
1513
)

go.sum

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/alecthomas/gometalinter v2.0.11+incompatible h1:ENdXMllZNSVDTJUUVIzBW9CSEpntTrQa76iRsEFLX/M=
4+
github.com/alecthomas/gometalinter v2.0.11+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk=
5+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
6+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
17
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
28
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
39
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
410
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
511
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
612
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
13+
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
14+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
15+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
16+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
17+
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE=
18+
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
19+
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg=
20+
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
21+
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc h1:cJlkeAx1QYgO5N80aF5xRGstVsRQwgLR7uA2FnP1ZjY=
22+
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU=
723
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
824
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
25+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
26+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
27+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
28+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
29+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
930
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
1031
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
11-
github.com/manifoldco/promptui v0.3.0 h1:vJiVJREqDfn9ZhqTG1Dz5zP9RPWlAzWQkwRYLGyUHx4=
12-
github.com/manifoldco/promptui v0.3.0/go.mod h1:zoCNXiJnyM03LlBgTsWv8mq28s7aTC71UgKasqRJHww=
13-
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0 h1:cDvUG90i1ssGJGqMNx2Ubbn+bx7VOzjdvQ45zpy0X4w=
14-
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
32+
github.com/magefile/mage v1.8.0 h1:mzL+xIopvPURVBwHG9A50JcjBO+xV3b5iZ7khFRI+5E=
33+
github.com/magefile/mage v1.8.0/go.mod h1:IUDi13rsHje59lecXokTfGX0QIzO45uVPlXnJYsXepA=
34+
github.com/manifoldco/promptui v0.3.2 h1:rir7oByTERac6jhpHUPErHuopoRDvO3jxS+FdadEns8=
35+
github.com/manifoldco/promptui v0.3.2/go.mod h1:8JU+igZ+eeiiRku4T5BjtKh2ms8sziGpSYl1gN8Bazw=
36+
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
37+
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
1538
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
1639
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
40+
github.com/nicksnyder/go-i18n v1.10.0 h1:5AzlPKvXBH4qBzmZ09Ua9Gipyruv6uApMcrNZdo96+Q=
41+
github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2xBGjv0j365Q=
42+
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
43+
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
44+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
45+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
46+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
47+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
48+
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c=
49+
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk=
1750
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f h1:lRy+hhwk7YT7MsKejxuz0C5Q1gk6p/QoPQYEmKmGFb8=
1851
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
19-
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30 h1:4bYUqrXBoiI7UFQeibUwFhvcHfaEeL75O3lOcZa964o=
20-
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
52+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc=
53+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
54+
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
55+
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
56+
golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1 h1:bsEj/LXbv3BCtkp/rBj9Wi/0Nde4OMaraIZpndHAhdI=
57+
golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
58+
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y=
59+
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA=
2160
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2261
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23-
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
24-
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
62+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
63+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
64+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
65+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

mage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"github.com/magefile/mage/mage"
7+
"os"
8+
)
9+
10+
func main() {
11+
os.Exit(mage.Main())
12+
}

magefile.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// +build mage
2+
3+
package main
4+
5+
import (
6+
"bufio"
7+
"crypto/sha1"
8+
"encoding/hex"
9+
"fmt"
10+
"github.com/magefile/mage/mg"
11+
"github.com/magefile/mage/sh"
12+
"io"
13+
"io/ioutil"
14+
"os"
15+
"path/filepath"
16+
"runtime"
17+
"strings"
18+
)
19+
20+
// Default target to run when none is specified
21+
// If not set, running mage will list available targets
22+
// var Default = Build
23+
24+
// tidy code
25+
func Fmt() error {
26+
packages := strings.Split("cmd", " ")
27+
files, _ := filepath.Glob("*.go")
28+
packages = append(packages, files...)
29+
return sh.Run("gofmt", append([]string{"-s", "-l", "-w"}, packages...)...)
30+
}
31+
32+
// for local machine build
33+
func Build() error {
34+
return buildTarget(runtime.GOOS, runtime.GOARCH, nil)
35+
}
36+
37+
// build all platform
38+
func Pack() error {
39+
buildTarget("darwin", "amd64", nil)
40+
buildTarget("darwin", "386", nil)
41+
buildTarget("freebsd", "amd64", nil)
42+
buildTarget("freebsd", "386", nil)
43+
buildTarget("linux", "amd64", nil)
44+
buildTarget("linux", "386", nil)
45+
buildTarget("linux", "arm", nil)
46+
buildTarget("linux", "arm64", nil)
47+
buildTarget("windows", "amd64", nil)
48+
buildTarget("windows", "386", nil)
49+
return genCheckSum()
50+
}
51+
52+
// Test all packages
53+
func Test() error {
54+
err := sh.RunV("go", "test", "-v", "-coverprofile", ".cover.out", "./...")
55+
if err != nil {
56+
return err
57+
}
58+
59+
err = sh.RunV("go", "tool", "cover", "-func=.cover.out")
60+
if err != nil {
61+
return err
62+
}
63+
64+
err = sh.Run("go", "tool", "cover", "-html=.cover.out", "-o", ".cover.html")
65+
if err != nil {
66+
return err
67+
}
68+
69+
return sh.Rm(".cover.out")
70+
}
71+
72+
// build to target (cross build)
73+
func buildTarget(OS, arch string, envs map[string]string) error {
74+
tag := tag()
75+
name := fmt.Sprintf("sshw-%s-%s-%s", OS, arch, tag)
76+
dir := fmt.Sprintf("dist/%s", name)
77+
target := fmt.Sprintf("%s/sshw", dir)
78+
79+
args := make([]string, 0, 10)
80+
args = append(args, "build", "-o", target)
81+
args = append(args, "-ldflags", flags(), "cmd/sshw/main.go")
82+
83+
fmt.Println("build", target)
84+
env := make(map[string]string)
85+
env["GOOS"] = OS
86+
env["GOARCH"] = arch
87+
env["CGO_ENABLED"] = "0"
88+
89+
if envs != nil {
90+
for k, v := range envs {
91+
env[k] = v
92+
}
93+
}
94+
95+
if err := sh.RunWith(env, mg.GoCmd(), args...); err != nil {
96+
return err
97+
}
98+
99+
sh.Run("tar", "-czf", fmt.Sprintf("%s.tar.gz", dir), "-C", "dist", name)
100+
101+
return nil
102+
}
103+
104+
func flags() string {
105+
hash := hash()
106+
tag := tag()
107+
return fmt.Sprintf(`-s -w -X "main.Build=%s-%s" -extldflags "-static"`, tag, hash)
108+
}
109+
110+
// tag returns the git tag for the current branch or "" if none.
111+
func tag() string {
112+
s, _ := sh.Output("bash", "-c", "git describe --abbrev=0 --tags 2> /dev/null")
113+
if s == "" {
114+
return "dev"
115+
}
116+
return s
117+
}
118+
119+
// hash returns the git hash for the current repo or "" if none.
120+
func hash() string {
121+
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
122+
return hash
123+
}
124+
125+
func mod() string {
126+
f, err := os.Open("go.mod")
127+
if err == nil {
128+
reader := bufio.NewReader(f)
129+
line, _, _ := reader.ReadLine()
130+
return strings.Replace(string(line), "module ", "", 1)
131+
}
132+
return ""
133+
}
134+
135+
// cleanup all build files
136+
func Clean() {
137+
sh.Rm("dist")
138+
sh.Rm(".cover.html")
139+
}
140+
141+
func genCheckSum() error {
142+
fmt.Println("generate checksum.txt file")
143+
fs, err := ioutil.ReadDir("dist")
144+
if err != nil {
145+
return err
146+
}
147+
148+
file, err := os.OpenFile("dist/checksum.txt", os.O_CREATE|os.O_WRONLY, 0600)
149+
if err != nil {
150+
return err
151+
}
152+
defer file.Close()
153+
for _, f := range fs {
154+
if f.IsDir() {
155+
continue
156+
}
157+
158+
if strings.HasSuffix(f.Name(), ".tar.gz") {
159+
sum, _ := fileHash(fmt.Sprintf("dist/%s", f.Name()))
160+
fmt.Println(sum, f.Name())
161+
file.WriteString(fmt.Sprintf("%s %s\n", sum, f.Name()))
162+
}
163+
}
164+
return nil
165+
}
166+
167+
func fileHash(filename string) (string, error) {
168+
file, err := os.Open(filename)
169+
if err != nil {
170+
return "", err
171+
}
172+
173+
hash := sha1.New()
174+
io.Copy(hash, file)
175+
ret := hash.Sum(nil)
176+
return hex.EncodeToString(ret[:]), nil
177+
}

0 commit comments

Comments
 (0)