From 4e5177fc250090cfc61494b1ec94884a30f51778 Mon Sep 17 00:00:00 2001 From: Anmol Sethi <hi@nhooyr.io> Date: Sun, 10 May 2020 05:03:40 -0400 Subject: [PATCH] Back to GH Actions See https://github.com/agnivade/wasmbrowsertest/issues/15 --- .github/workflows/ci.yaml | 39 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 40 --------------------------------------- Makefile | 7 ------- README.md | 4 ++-- ci/container/Dockerfile | 14 ++++++++++++++ ci/ensure_fmt.sh | 23 ---------------------- ci/fmt.mk | 22 --------------------- ci/fmt.sh | 38 +++++++++++++++++++++++++++++++++++++ ci/lint.mk | 16 ---------------- ci/lint.sh | 16 ++++++++++++++++ ci/test.mk | 17 ----------------- ci/test.sh | 25 ++++++++++++++++++++++++ conn_test.go | 4 ---- 13 files changed, 134 insertions(+), 131 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .travis.yml delete mode 100644 Makefile create mode 100644 ci/container/Dockerfile delete mode 100755 ci/ensure_fmt.sh delete mode 100644 ci/fmt.mk create mode 100755 ci/fmt.sh delete mode 100644 ci/lint.mk create mode 100755 ci/lint.sh delete mode 100644 ci/test.mk create mode 100755 ci/test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..3d9829e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,39 @@ +name: ci + +on: [push, pull_request] + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run ./ci/fmt.sh + uses: ./ci/container + with: + args: ./ci/fmt.sh + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run ./ci/lint.sh + uses: ./ci/container + with: + args: ./ci/lint.sh + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Run ./ci/test.sh + uses: ./ci/container + with: + args: ./ci/test.sh + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: 9b3ee4dc-8297-4774-b4b9-a61561fbbce7 + - name: Upload coverage.html + uses: actions/upload-artifact@v2 + with: + name: coverage.html + path: ./ci/out/coverage.html diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 41d3c20..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: go -go: 1.x -dist: bionic - -env: - global: - - SHFMT_URL=https://github.com/mvdan/sh/releases/download/v3.0.1/shfmt_v3.0.1_linux_amd64 - - GOFLAGS="-mod=readonly" - -jobs: - include: - - name: Format - before_script: - - sudo apt-get install -y npm - - sudo npm install -g prettier - - sudo curl -L "$SHFMT_URL" > /usr/local/bin/shfmt && sudo chmod +x /usr/local/bin/shfmt - - go get golang.org/x/tools/cmd/stringer - - go get golang.org/x/tools/cmd/goimports - script: make -j16 fmt - - name: Lint - before_script: - - sudo apt-get install -y shellcheck - - go get golang.org/x/lint/golint - script: make -j16 lint - - name: Test - before_script: - - sudo apt-get install -y chromium-browser - - go get github.com/agnivade/wasmbrowsertest - - go get github.com/mattn/goveralls - script: make -j16 test - -addons: - apt: - update: true - -cache: - npm: true - directories: - - ~/.cache - - ~/gopath/pkg diff --git a/Makefile b/Makefile deleted file mode 100644 index f9f31c4..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: fmt lint test - -.SILENT: - -include ci/fmt.mk -include ci/lint.mk -include ci/test.mk diff --git a/README.md b/README.md index 14c3929..a88d26c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # websocket [](https://pkg.go.dev/nhooyr.io/websocket) +[](https://nhooyrio-websocket-coverage.netlify.app) websocket is a minimal and idiomatic WebSocket library for Go. @@ -10,12 +11,11 @@ websocket is a minimal and idiomatic WebSocket library for Go. go get nhooyr.io/websocket ``` -## Features +## Highlights - Minimal and idiomatic API - First class [context.Context](https://blog.golang.org/context) support - Fully passes the WebSocket [autobahn-testsuite](https://github.com/crossbario/autobahn-testsuite) -- Thorough tests with [90% coverage](https://coveralls.io/github/nhooyr/websocket) - [Single dependency](https://pkg.go.dev/nhooyr.io/websocket?tab=imports) - JSON and protobuf helpers in the [wsjson](https://pkg.go.dev/nhooyr.io/websocket/wsjson) and [wspb](https://pkg.go.dev/nhooyr.io/websocket/wspb) subpackages - Zero alloc reads and writes diff --git a/ci/container/Dockerfile b/ci/container/Dockerfile new file mode 100644 index 0000000..fd00878 --- /dev/null +++ b/ci/container/Dockerfile @@ -0,0 +1,14 @@ +FROM golang + +RUN apt-get update +RUN apt-get install -y npm shellcheck chromium + +ENV GO111MODULE=on +RUN go get golang.org/x/tools/cmd/goimports +RUN go get mvdan.cc/sh/v3/cmd/shfmt +RUN go get golang.org/x/tools/cmd/stringer +RUN go get golang.org/x/lint/golint +RUN go get github.com/agnivade/wasmbrowsertest + +RUN npm install -g prettier +RUN npm install -g netlify-cli diff --git a/ci/ensure_fmt.sh b/ci/ensure_fmt.sh deleted file mode 100755 index 6fe9cb1..0000000 --- a/ci/ensure_fmt.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -main() { - local files - mapfile -t files < <(git ls-files --other --modified --exclude-standard) - if [[ ${files[*]} == "" ]]; then - return - fi - - echo "Files need generation or are formatted incorrectly:" - for f in "${files[@]}"; do - echo " $f" - done - - echo - echo "Please run the following locally:" - echo " make fmt" - exit 1 -} - -main "$@" diff --git a/ci/fmt.mk b/ci/fmt.mk deleted file mode 100644 index 1ed2920..0000000 --- a/ci/fmt.mk +++ /dev/null @@ -1,22 +0,0 @@ -fmt: modtidy gofmt goimports prettier shfmt -ifdef CI - ./ci/ensure_fmt.sh -endif - -modtidy: gen - go mod tidy - -gofmt: gen - gofmt -w -s . - -goimports: gen - goimports -w "-local=$$(go list -m)" . - -prettier: - prettier --write --print-width=120 --no-semi --trailing-comma=all --loglevel=warn --arrow-parens=avoid $$(git ls-files "*.yml" "*.md" "*.js" "*.css" "*.html") - -gen: - stringer -type=opcode,MessageType,StatusCode -output=stringer.go - -shfmt: - shfmt -i 2 -w -s -sr $$(git ls-files "*.sh") diff --git a/ci/fmt.sh b/ci/fmt.sh new file mode 100755 index 0000000..e6a2d68 --- /dev/null +++ b/ci/fmt.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/.." + + go mod tidy + gofmt -w -s . + goimports -w "-local=$(go list -m)" . + + prettier \ + --write \ + --print-width=120 \ + --no-semi \ + --trailing-comma=all \ + --loglevel=warn \ + --arrow-parens=avoid \ + $(git ls-files "*.yml" "*.md" "*.js" "*.css" "*.html") + shfmt -i 2 -w -s -sr $(git ls-files "*.sh") + + stringer -type=opcode,MessageType,StatusCode -output=stringer.go + + if [[ ${CI-} ]]; then + ensure_fmt + fi +} + +ensure_fmt() { + if [[ $(git ls-files --other --modified --exclude-standard) ]]; then + git -c color.ui=always --no-pager diff + echo + echo "Please run the following locally:" + echo " ./ci/fmt.sh" + exit 1 + fi +} + +main "$@" diff --git a/ci/lint.mk b/ci/lint.mk deleted file mode 100644 index 4335e7b..0000000 --- a/ci/lint.mk +++ /dev/null @@ -1,16 +0,0 @@ -lint: govet golint govet-wasm golint-wasm shellcheck - -govet: - go vet ./... - -govet-wasm: - GOOS=js GOARCH=wasm go vet ./... - -golint: - golint -set_exit_status ./... - -golint-wasm: - GOOS=js GOARCH=wasm golint -set_exit_status ./... - -shellcheck: - shellcheck $$(git ls-files "*.sh") diff --git a/ci/lint.sh b/ci/lint.sh new file mode 100755 index 0000000..e1053d1 --- /dev/null +++ b/ci/lint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/.." + + go vet ./... + GOOS=js GOARCH=wasm go vet ./... + + golint -set_exit_status ./... + GOOS=js GOARCH=wasm golint -set_exit_status ./... + + shellcheck --exclude=SC2046 $(git ls-files "*.sh") +} + +main "$@" diff --git a/ci/test.mk b/ci/test.mk deleted file mode 100644 index 553a05c..0000000 --- a/ci/test.mk +++ /dev/null @@ -1,17 +0,0 @@ -test: ci/out/coverage.html -ifdef CI -test: coveralls -endif - -ci/out/coverage.html: gotest - go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html - -coveralls: gotest - echo "--- coveralls" - goveralls -coverprofile=ci/out/coverage.prof - -gotest: - go test -timeout=30m -covermode=atomic -coverprofile=ci/out/coverage.prof -coverpkg=./... $${GOTESTFLAGS-} ./... - sed -i '/stringer\.go/d' ci/out/coverage.prof - sed -i '/nhooyr.io\/websocket\/internal\/test/d' ci/out/coverage.prof - sed -i '/examples/d' ci/out/coverage.prof diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 0000000..64aa772 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +main() { + cd "$(dirname "$0")/.." + + go test -timeout=30m -covermode=atomic -coverprofile=ci/out/coverage.prof -coverpkg=./... "$@" ./... + sed -i '/stringer\.go/d' ci/out/coverage.prof + sed -i '/nhooyr.io\/websocket\/internal\/test/d' ci/out/coverage.prof + sed -i '/examples/d' ci/out/coverage.prof + + # Last line is the total coverage. + go tool cover -func ci/out/coverage.prof | tail -n1 + + go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html + + if [[ ${CI} && ${GITHUB_REF-} == *master ]]; then + local deployDir + deployDir="$(mktemp -d)" + cp ci/out/coverage.html "$deployDir/index.html" + netlify deploy --prod "--dir=$deployDir" + fi +} + +main "$@" diff --git a/conn_test.go b/conn_test.go index 28e8d59..e1990a5 100644 --- a/conn_test.go +++ b/conn_test.go @@ -267,10 +267,6 @@ func TestConn(t *testing.T) { func TestWasm(t *testing.T) { t.Parallel() - if os.Getenv("CI") != "" { - t.Skip("skipping on CI") - } - s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ Subprotocols: []string{"echo"}, -- GitLab