Skip to content

Commit

Permalink
Merge pull request #1 from haya14busa/travis
Browse files Browse the repository at this point in the history
CI
  • Loading branch information
haya14busa authored Sep 2, 2016
2 parents 82f0acb + 4bde23f commit 36088bd
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: go

go:
- 1.7
- tip

os:
- linux
- osx

before_install:
- make deps

script:
- uname
- make lint
- go test -v -race ./...
- 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
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Prefer go commands for basic tasks like `build`, `test`, etc...

.PHONY: deps lint 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 . | grep '^' # exit 1 if any output given
! golint ./... | grep '^'
go vet ./...
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)
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)
18 changes: 18 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
2 changes: 1 addition & 1 deletion cmd/goplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {

fmt.Println(url)
if *openBrowser {
open.Start(url)
fatalIf(open.Start(url))
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions goplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const defaultBaseURL = "https://play.golang.org"

// DefaultClient is default Go Playground client.
var DefaultClient = &Client{}

var delay = time.Sleep
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -108,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
}
12 changes: 6 additions & 6 deletions goplay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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},
},
}

Expand Down
1 change: 1 addition & 0 deletions socket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 36088bd

Please sign in to comment.