From f75ace1b45a26af21aae8c6700a6de20c53fa547 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 06:43:27 +0900 Subject: [PATCH 01/13] CI: add .travis.yml --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..aeea0c2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: go + +go: + - 1.7 + - tip + +install: + - go get -t -d -v ./... + +script: + - go test -v -race ./... From fb964813f8e156a8ab09ba514acf55c1c5bc046e Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 06:52:05 +0900 Subject: [PATCH 02/13] CI: coveralls integration --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index aeea0c2..7c8c8cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,13 @@ go: - 1.7 - tip +before_install: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + install: - go get -t -d -v ./... script: - go test -v -race ./... + - $HOME/gopath/bin/goveralls -service=travis-ci From 0d74311e6303602075e68f871d3377b907414247 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 07:21:58 +0900 Subject: [PATCH 03/13] CI: add `make release` --- .gitignore | 1 + Makefile | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d702569 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +release diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c93b60 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +# https://github.com/golang/go/wiki/HostedContinuousIntegration +# https://loads.pickle.me.uk/2015/08/22/easy-peasy-github-releases-for-go-projects-using-travis/ +package = github.com/haya14busa/goplay/cmd/goplay + +.PHONY: release + +release: + mkdir -p release + GOOS=linux GOARCH=amd64 go build -o release/goplay-linux-amd64 $(package) + GOOS=linux GOARCH=386 go build -o release/goplay-linux-386 $(package) + GOOS=linux GOARCH=arm go build -o release/goplay-linux-arm $(package) + GOOS=windows GOARCH=amd64 go build -o release/goplay-windows-amd64.exe $(package) + GOOS=windows GOARCH=386 go build -o release/goplay-windows-386.exe $(package) + GOOS=darwin GOARCH=amd64 go build -o release/goplay-darwin-amd64 $(package) + GOOS=darwin GOARCH=386 go build -o release/goplay-darwin-386 $(package) From fba9294135adb6b1f47f08bb5cc67772c473052f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 07:39:09 +0900 Subject: [PATCH 04/13] CI: add deply step --- .travis.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c8c8cb..2e6e6df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,21 @@ install: script: - go test -v -race ./... - - $HOME/gopath/bin/goveralls -service=travis-ci + - goveralls -service=travis-ci + +before_deploy: make release +deploy: + provider: releases + api_key: + secure: pMpSqWsjmn1p7+mJB3XcDlvkD+Kldlho16Inqhl4JEPjM+MYg+L1lT91ZShgOldtgk6YY9e126cAKNOhwDhah4941euhng/PryVeDnxqaYJIlU6yL/60NasvAcp2dybSWvyTov549bjBTy0b4tz6vzAd244q39Z5Fg8NllUvGmNMKgKZHAC2GBLejP01+Xpd1Tj++//JfpD/kjef/Ck004pT64/xcZBh40Yj8QGNi08+wTeU1EuJcHdMnAcd011sVhDNIaQHfRkjVMahVuUApApguHZmodw0hlFhFIy7IKiQOHe52gMDpo549jGBKq2oQAHea/uPV7+EsPEv/YwlYfjb4mLD5pyM9oCK8LGjSeEKWj8BXVWQcLQZfp4Nid0A4oC5hyAaZD7MvWc8Gd4RPzu3h51m0K4cRQ2c6V7gRpkJWi1VfjNu//N0ZAWeDa1xQ72CAd0ddRNfRbNIFRxFkhwTIPNsjAG7GvGYdVYN1xT3LmnXLmbAuP+A48GGlBLBmPBPnfdcuQeNGlimegiOFcC3PzYN0H3HyMdIZ0c1UxXlt/TUiSK07rdfWjtdP9vvtMLfq67SLLhS8bamDUGBfSgJImSDcHqYUfgyz3YtNrf5n6Ubc59HF1ONxxdFJpBxoqqDnoojiUsQ9rzjSZ2xW83K5KajoedoMmXKTSpt9MM= + file: + - release/goplay-linux-amd64 + - release/goplay-linux-386 + - release/goplay-linux-arm + - release/goplay-windows-amd64.exe + - release/goplay-windows-386.exe + - release/goplay-darwin-amd64 + - release/goplay-darwin-386 + skip_cleanup: true + on: + tags: true From 31389778d2c04564b64a69f7e4e1ac874ab7d618 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 08:03:21 +0900 Subject: [PATCH 05/13] CI: add appveyor integration --- appveyor.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..415dc7a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +version: '{build}' + +clone_folder: c:\gopath\src\github.com\haya14busa\goplay + +environment: + GOPATH: c:\gopath + +install: + - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% + - go version + - go env + - go get -t -d -v ./... + +build_script: + - go build -v + +test_script: + - go test -v -race ./... From 697d90ffaa5910213a7d4fbb400dfdbd5ecdd49f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 08:20:18 +0900 Subject: [PATCH 06/13] CI: run test on osx as well --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2e6e6df..39ff292 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,10 @@ go: - 1.7 - tip +os: + - linux + - osx + before_install: - go get github.com/mattn/goveralls - go get golang.org/x/tools/cmd/cover From 73898f8400bf704ef014cae5f0cf358d8419aa3e Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 08:33:55 +0900 Subject: [PATCH 07/13] Fix lint --- goplay.go | 3 +++ goplay_test.go | 12 ++++++------ socket/client.go | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/goplay.go b/goplay.go index f7b1052..0a29247 100644 --- a/goplay.go +++ b/goplay.go @@ -14,6 +14,7 @@ import ( const defaultBaseURL = "https://play.golang.org" +// DefaultClient is default Go Playground client. var DefaultClient = &Client{} var delay = time.Sleep @@ -50,6 +51,7 @@ func (c *Client) compileEndpoint() string { return c.baseURL() + "/compile" } +// Run runs code which compiled in The Go Playground. func (c *Client) Run(code io.Reader, stdout io.Writer, stderr io.Writer) error { resp, err := c.Compile(code) if err != nil { @@ -69,6 +71,7 @@ func (c *Client) Run(code io.Reader, stdout io.Writer, stderr io.Writer) error { return nil } +// Compile compiles code on The Go Playground. func (c *Client) Compile(code io.Reader) (*Response, error) { b, err := ioutil.ReadAll(code) if err != nil { diff --git a/goplay_test.go b/goplay_test.go index dbe4743..d01bd01 100644 --- a/goplay_test.go +++ b/goplay_test.go @@ -16,14 +16,14 @@ func TestClient_Run(t *testing.T) { defer func() { delay = saveDelay }() events := []*Event{ - &Event{Message: "out1", Kind: "stdout", Delay: 5}, - &Event{Message: "out2", Kind: "stdout", Delay: 5}, - &Event{Message: "err1", Kind: "stderr", Delay: 5}, + {Message: "out1", Kind: "stdout", Delay: 5}, + {Message: "out2", Kind: "stdout", Delay: 5}, + {Message: "err1", Kind: "stderr", Delay: 5}, } delayCalledN := 0 delay = func(d time.Duration) { - delayCalledN += 1 + delayCalledN++ if d != 5 { t.Errorf("delay func got unexpected value: %v", d) } @@ -78,8 +78,8 @@ func TestClient_Compile(t *testing.T) { wantResp := &Response{ Errors: "", Events: []*Event{ - &Event{Message: "test1", Kind: "stdout", Delay: 0}, - &Event{Message: "test2", Kind: "stdout", Delay: 2}, + {Message: "test1", Kind: "stdout", Delay: 0}, + {Message: "test2", Kind: "stdout", Delay: 2}, }, } diff --git a/socket/client.go b/socket/client.go index 5f5c1cd..bcc0373 100644 --- a/socket/client.go +++ b/socket/client.go @@ -28,6 +28,7 @@ type Client struct { Stderr io.Writer } +// Run runs code on connected go playground websocket server. func (c *Client) Run(code string) error { stdout, stderr := c.Stdout, c.Stderr if stdout == nil { From 7e018eadd321601bf454e3b9def94371a7900bc2 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 09:13:21 +0900 Subject: [PATCH 08/13] Fix errcheck lint --- cmd/goplay/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/goplay/main.go b/cmd/goplay/main.go index 38d7e5a..d8a4a6f 100644 --- a/cmd/goplay/main.go +++ b/cmd/goplay/main.go @@ -61,7 +61,7 @@ func main() { fmt.Println(url) if *openBrowser { - open.Start(url) + fatalIf(open.Start(url)) } } } From 9075f9e924cfa395227e1b2cde7fb9f6788c12c8 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 09:26:30 +0900 Subject: [PATCH 09/13] CI: add various linter --- .travis.yml | 7 ++----- Makefile | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39ff292..a30edc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,10 @@ os: - osx before_install: - - go get github.com/mattn/goveralls - - go get golang.org/x/tools/cmd/cover - -install: - - go get -t -d -v ./... + - make deps script: + - make lint - go test -v -race ./... - goveralls -service=travis-ci diff --git a/Makefile b/Makefile index 9c93b60..9b9e440 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,25 @@ # https://loads.pickle.me.uk/2015/08/22/easy-peasy-github-releases-for-go-projects-using-travis/ package = github.com/haya14busa/goplay/cmd/goplay -.PHONY: release +.PHONY: deps lint release -release: +deps: + go get -d -v -t ./... + go get github.com/mattn/goveralls + go get golang.org/x/tools/cmd/cover + go get github.com/golang/lint/golint + go get github.com/kisielk/errcheck + go get github.com/client9/misspell/cmd/misspell + + +lint: deps + gofmt -d -s . | tee /dev/stderr | xargs -r false + golint ./... | tee /dev/stderr | xargs -r false + go vet ./... + errcheck -asserts -ignoretests -ignore 'Close' + misspell -error **/*.go **/*.md + +release: deps mkdir -p release GOOS=linux GOARCH=amd64 go build -o release/goplay-linux-amd64 $(package) GOOS=linux GOARCH=386 go build -o release/goplay-linux-386 $(package) From 188610116c5570b78cc8133209c779d8a5e33490 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 09:35:24 +0900 Subject: [PATCH 10/13] tweak Makefile --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9b9e440..2c695a9 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ -# https://github.com/golang/go/wiki/HostedContinuousIntegration -# https://loads.pickle.me.uk/2015/08/22/easy-peasy-github-releases-for-go-projects-using-travis/ -package = github.com/haya14busa/goplay/cmd/goplay +# Prefer go commands for basic tasks like `build`, `test`, etc... .PHONY: deps lint release @@ -20,6 +18,10 @@ lint: deps errcheck -asserts -ignoretests -ignore 'Close' misspell -error **/*.go **/*.md +# https://github.com/golang/go/wiki/HostedContinuousIntegration +# https://loads.pickle.me.uk/2015/08/22/easy-peasy-github-releases-for-go-projects-using-travis/ +package = github.com/haya14busa/goplay/cmd/goplay + release: deps mkdir -p release GOOS=linux GOARCH=amd64 go build -o release/goplay-linux-amd64 $(package) From 525532a2fed02632ebad17844d2d38357ad7dac4 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 10:07:30 +0900 Subject: [PATCH 11/13] Tweak License comment --- goplay.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/goplay.go b/goplay.go index 0a29247..2457af9 100644 --- a/goplay.go +++ b/goplay.go @@ -111,18 +111,18 @@ func (c *Client) Share(code io.Reader) (string, error) { } // Response represensts response type of /compile. -// Licence: Copyright (c) 2014 The Go Authors. All rights reserved. -// https://github.com/golang/playground/blob/816964eae74f7612221c13ab73f2a8021c581010/sandbox/sandbox.go#L35-L38 type Response struct { Errors string Events []*Event + // Licence: Copyright (c) 2014 The Go Authors. All rights reserved. + // https://github.com/golang/playground/blob/816964eae74f7612221c13ab73f2a8021c581010/sandbox/sandbox.go#L35-L38 } // Event represensts event of /compile result. -// Licence: Copyright (c) 2014 The Go Authors. All rights reserved. -// https://github.com/golang/playground/blob/816964eae74f7612221c13ab73f2a8021c581010/sandbox/play.go#L76-L80 type Event struct { Message string Kind string // "stdout" or "stderr" Delay time.Duration // time to wait before printing Message + // Licence: Copyright (c) 2014 The Go Authors. All rights reserved. + // https://github.com/golang/playground/blob/816964eae74f7612221c13ab73f2a8021c581010/sandbox/play.go#L76-L80 } From cf2fbeb40317dbe1fcc6a04afa1865dd39788af6 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 10:07:43 +0900 Subject: [PATCH 12/13] CI: support BSD xargs --- .travis.yml | 1 + Makefile | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a30edc1..109c0ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ before_install: - make deps script: + - uname - make lint - go test -v -race ./... - goveralls -service=travis-ci diff --git a/Makefile b/Makefile index 2c695a9..89237e9 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,15 @@ deps: go get github.com/kisielk/errcheck go get github.com/client9/misspell/cmd/misspell +# http://syohex.hatenablog.com/entry/20140702/1404250291 +XARG_EMPTY='' +ifeq ("$(uname)", "LINUX") + XARG_EMPTY='-r' +endif lint: deps - gofmt -d -s . | tee /dev/stderr | xargs -r false - golint ./... | tee /dev/stderr | xargs -r false + gofmt -d -s . | tee /dev/stderr | xargs $(XARG_EMPTY) false + golint ./... | tee /dev/stderr | xargs $(XARG_EMPTY) false go vet ./... errcheck -asserts -ignoretests -ignore 'Close' misspell -error **/*.go **/*.md From 4bde23f38dabb4c2a12ca32b4d9d2f57e24be573 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Fri, 2 Sep 2016 10:44:51 +0900 Subject: [PATCH 13/13] CI: use ! cmd | grep '^' to check output Handling xargs option is troublesome... --- Makefile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 89237e9..fd43940 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,9 @@ deps: go get github.com/kisielk/errcheck go get github.com/client9/misspell/cmd/misspell -# http://syohex.hatenablog.com/entry/20140702/1404250291 -XARG_EMPTY='' -ifeq ("$(uname)", "LINUX") - XARG_EMPTY='-r' -endif - lint: deps - gofmt -d -s . | tee /dev/stderr | xargs $(XARG_EMPTY) false - golint ./... | tee /dev/stderr | xargs $(XARG_EMPTY) false + ! gofmt -d -s . | grep '^' # exit 1 if any output given + ! golint ./... | grep '^' go vet ./... errcheck -asserts -ignoretests -ignore 'Close' misspell -error **/*.go **/*.md