-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
249 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
module github.com/yinheli/sshw | ||
|
||
require ( | ||
github.com/chzyer/logex v1.1.10 // indirect | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect | ||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect | ||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect | ||
github.com/manifoldco/promptui v0.3.0 | ||
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0 // indirect | ||
github.com/mattn/go-isatty v0.0.4 // indirect | ||
github.com/BurntSushi/toml v0.3.1 // indirect | ||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect | ||
github.com/magefile/mage v1.8.0 | ||
github.com/manifoldco/promptui v0.3.2 | ||
github.com/nicksnyder/go-i18n v1.10.0 // indirect | ||
github.com/pelletier/go-toml v1.2.0 // indirect | ||
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f | ||
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30 // indirect | ||
gopkg.in/yaml.v2 v2.2.1 | ||
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,65 @@ | ||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/alecthomas/gometalinter v2.0.11+incompatible h1:ENdXMllZNSVDTJUUVIzBW9CSEpntTrQa76iRsEFLX/M= | ||
github.com/alecthomas/gometalinter v2.0.11+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk= | ||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= | ||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= | ||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= | ||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= | ||
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= | ||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE= | ||
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= | ||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= | ||
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= | ||
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc h1:cJlkeAx1QYgO5N80aF5xRGstVsRQwgLR7uA2FnP1ZjY= | ||
github.com/gordonklaus/ineffassign v0.0.0-20180909121442-1003c8bd00dc/go.mod h1:cuNKsD1zp2v6XfE/orVX2QE1LC+i254ceGcVeDT3pTU= | ||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= | ||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= | ||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw= | ||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= | ||
github.com/manifoldco/promptui v0.3.0 h1:vJiVJREqDfn9ZhqTG1Dz5zP9RPWlAzWQkwRYLGyUHx4= | ||
github.com/manifoldco/promptui v0.3.0/go.mod h1:zoCNXiJnyM03LlBgTsWv8mq28s7aTC71UgKasqRJHww= | ||
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0 h1:cDvUG90i1ssGJGqMNx2Ubbn+bx7VOzjdvQ45zpy0X4w= | ||
github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= | ||
github.com/magefile/mage v1.8.0 h1:mzL+xIopvPURVBwHG9A50JcjBO+xV3b5iZ7khFRI+5E= | ||
github.com/magefile/mage v1.8.0/go.mod h1:IUDi13rsHje59lecXokTfGX0QIzO45uVPlXnJYsXepA= | ||
github.com/manifoldco/promptui v0.3.2 h1:rir7oByTERac6jhpHUPErHuopoRDvO3jxS+FdadEns8= | ||
github.com/manifoldco/promptui v0.3.2/go.mod h1:8JU+igZ+eeiiRku4T5BjtKh2ms8sziGpSYl1gN8Bazw= | ||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= | ||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= | ||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= | ||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= | ||
github.com/nicksnyder/go-i18n v1.10.0 h1:5AzlPKvXBH4qBzmZ09Ua9Gipyruv6uApMcrNZdo96+Q= | ||
github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2xBGjv0j365Q= | ||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= | ||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9 h1:vY5WqiEon0ZSTGM3ayVVi+twaHKHDFUVloaQ/wug9/c= | ||
github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk= | ||
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f h1:lRy+hhwk7YT7MsKejxuz0C5Q1gk6p/QoPQYEmKmGFb8= | ||
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30 h1:4bYUqrXBoiI7UFQeibUwFhvcHfaEeL75O3lOcZa964o= | ||
golang.org/x/sys v0.0.0-20180715085529-ac767d655b30/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc= | ||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= | ||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4= | ||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1 h1:bsEj/LXbv3BCtkp/rBj9Wi/0Nde4OMaraIZpndHAhdI= | ||
golang.org/x/tools v0.0.0-20181122213734-04b5d21e00f1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y= | ||
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= | ||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/magefile/mage/mage" | ||
"os" | ||
) | ||
|
||
func main() { | ||
os.Exit(mage.Main()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// +build mage | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"fmt" | ||
"github.com/magefile/mage/mg" | ||
"github.com/magefile/mage/sh" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// Default target to run when none is specified | ||
// If not set, running mage will list available targets | ||
// var Default = Build | ||
|
||
// tidy code | ||
func Fmt() error { | ||
packages := strings.Split("cmd", " ") | ||
files, _ := filepath.Glob("*.go") | ||
packages = append(packages, files...) | ||
return sh.Run("gofmt", append([]string{"-s", "-l", "-w"}, packages...)...) | ||
} | ||
|
||
// for local machine build | ||
func Build() error { | ||
return buildTarget(runtime.GOOS, runtime.GOARCH, nil) | ||
} | ||
|
||
// build all platform | ||
func Pack() error { | ||
buildTarget("darwin", "amd64", nil) | ||
buildTarget("darwin", "386", nil) | ||
buildTarget("freebsd", "amd64", nil) | ||
buildTarget("freebsd", "386", nil) | ||
buildTarget("linux", "amd64", nil) | ||
buildTarget("linux", "386", nil) | ||
buildTarget("linux", "arm", nil) | ||
buildTarget("linux", "arm64", nil) | ||
buildTarget("windows", "amd64", nil) | ||
buildTarget("windows", "386", nil) | ||
return genCheckSum() | ||
} | ||
|
||
// Test all packages | ||
func Test() error { | ||
err := sh.RunV("go", "test", "-v", "-coverprofile", ".cover.out", "./...") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = sh.RunV("go", "tool", "cover", "-func=.cover.out") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = sh.Run("go", "tool", "cover", "-html=.cover.out", "-o", ".cover.html") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return sh.Rm(".cover.out") | ||
} | ||
|
||
// build to target (cross build) | ||
func buildTarget(OS, arch string, envs map[string]string) error { | ||
tag := tag() | ||
name := fmt.Sprintf("sshw-%s-%s-%s", OS, arch, tag) | ||
dir := fmt.Sprintf("dist/%s", name) | ||
target := fmt.Sprintf("%s/sshw", dir) | ||
|
||
args := make([]string, 0, 10) | ||
args = append(args, "build", "-o", target) | ||
args = append(args, "-ldflags", flags(), "cmd/sshw/main.go") | ||
|
||
fmt.Println("build", target) | ||
env := make(map[string]string) | ||
env["GOOS"] = OS | ||
env["GOARCH"] = arch | ||
env["CGO_ENABLED"] = "0" | ||
|
||
if envs != nil { | ||
for k, v := range envs { | ||
env[k] = v | ||
} | ||
} | ||
|
||
if err := sh.RunWith(env, mg.GoCmd(), args...); err != nil { | ||
return err | ||
} | ||
|
||
sh.Run("tar", "-czf", fmt.Sprintf("%s.tar.gz", dir), "-C", "dist", name) | ||
|
||
return nil | ||
} | ||
|
||
func flags() string { | ||
hash := hash() | ||
tag := tag() | ||
return fmt.Sprintf(`-s -w -X "main.Build=%s-%s" -extldflags "-static"`, tag, hash) | ||
} | ||
|
||
// tag returns the git tag for the current branch or "" if none. | ||
func tag() string { | ||
s, _ := sh.Output("bash", "-c", "git describe --abbrev=0 --tags 2> /dev/null") | ||
if s == "" { | ||
return "dev" | ||
} | ||
return s | ||
} | ||
|
||
// hash returns the git hash for the current repo or "" if none. | ||
func hash() string { | ||
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD") | ||
return hash | ||
} | ||
|
||
func mod() string { | ||
f, err := os.Open("go.mod") | ||
if err == nil { | ||
reader := bufio.NewReader(f) | ||
line, _, _ := reader.ReadLine() | ||
return strings.Replace(string(line), "module ", "", 1) | ||
} | ||
return "" | ||
} | ||
|
||
// cleanup all build files | ||
func Clean() { | ||
sh.Rm("dist") | ||
sh.Rm(".cover.html") | ||
} | ||
|
||
func genCheckSum() error { | ||
fmt.Println("generate checksum.txt file") | ||
fs, err := ioutil.ReadDir("dist") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
file, err := os.OpenFile("dist/checksum.txt", os.O_CREATE|os.O_WRONLY, 0600) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
for _, f := range fs { | ||
if f.IsDir() { | ||
continue | ||
} | ||
|
||
if strings.HasSuffix(f.Name(), ".tar.gz") { | ||
sum, _ := fileHash(fmt.Sprintf("dist/%s", f.Name())) | ||
fmt.Println(sum, f.Name()) | ||
file.WriteString(fmt.Sprintf("%s %s\n", sum, f.Name())) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func fileHash(filename string) (string, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
hash := sha1.New() | ||
io.Copy(hash, file) | ||
ret := hash.Sum(nil) | ||
return hex.EncodeToString(ret[:]), nil | ||
} |