From 2d35d72b6827ef62563911d6b70251ac914fe576 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Oct 2019 13:42:19 -0400 Subject: [PATCH 1/4] Switch to coveralls.io from codecov.io codecov's uploader keeps failing due to the API being unresponsive and the UI is cluttered compared to codecov. --- .github/CONTRIBUTING.md | 7 ++----- .github/workflows/ci.yml | 2 +- Makefile | 4 ++++ README.md | 4 ++-- ci/.codecov.yml | 10 ---------- ci/fmt.mk | 17 ++++++++++------- ci/fmtcheck.sh | 11 ----------- ci/image/Dockerfile | 4 +--- ci/lint.mk | 5 +---- ci/test.mk | 17 ++++++++--------- 10 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 ci/.codecov.yml delete mode 100755 ci/fmtcheck.sh diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index cd6af4f1..357c314a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -28,7 +28,7 @@ CI must pass on your changes for them to be merged. ### CI CI will ensure your code is formatted, lints and passes tests. -It will collect coverage and report it to [codecov](https://codecov.io/gh/nhooyr/websocket) +It will collect coverage and report it to [coveralls](https://coveralls.io/github/nhooyr/websocket) and also upload a html `coverage` artifact that you can download to browse coverage. You can run CI locally. @@ -42,7 +42,4 @@ See [ci/image/Dockerfile](../ci/image/Dockerfile) for the installation of the CI For coverage details locally, see `ci/out/coverage.html` after running `make test`. -You can also run tests normally with `go test`. `make test` just passes a default set of flags to -`go test` to collect coverage and runs the WASM tests. - -Coverage percentage from codecov and the CI scripts will be different because they are calculated differently. +You can run tests normally with `go test`. `make test` wraps around `go test` to collect coverage. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37282e1b..d13e9028 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v1 - run: make test env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} - name: Upload coverage.html uses: actions/upload-artifact@master with: diff --git a/Makefile b/Makefile index ce92ab5b..62633e39 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ all: fmt lint test .PHONY: * +.ONESHELL: +SHELL = bash +.SHELLFLAGS = -ceuo pipefail + include ci/fmt.mk include ci/lint.mk include ci/test.mk diff --git a/README.md b/README.md index 9dd5d0a8..4a425a16 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # websocket -[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/nhooyr/websocket?color=6b9ded&sort=semver)](https://github.com/nhooyr/websocket/releases) +[![GitHub Release](https://img.shields.io/github/v/release/nhooyr/websocket?color=6b9ded&sort=semver)](https://github.com/nhooyr/websocket/releases) [![GoDoc](https://godoc.org/nhooyr.io/websocket?status.svg)](https://godoc.org/nhooyr.io/websocket) -[![Codecov](https://img.shields.io/codecov/c/github/nhooyr/websocket.svg?color=65d6a4)](https://codecov.io/gh/nhooyr/websocket) +[![Codecov](https://img.shields.io/coveralls/github/nhooyr/websocket?color=65d6a4)](https://coveralls.io/github/nhooyr/websocket) [![Actions Status](https://github.com/nhooyr/websocket/workflows/ci/badge.svg)](https://github.com/nhooyr/websocket/actions) websocket is a minimal and idiomatic WebSocket library for Go. diff --git a/ci/.codecov.yml b/ci/.codecov.yml deleted file mode 100644 index fa7c5f0a..00000000 --- a/ci/.codecov.yml +++ /dev/null @@ -1,10 +0,0 @@ -comment: off -coverage: - status: - # Prevent small changes in coverage from failing CI. - project: - default: - threshold: 15% - patch: - default: - threshold: 100% diff --git a/ci/fmt.mk b/ci/fmt.mk index 16a3b24e..8e61bc24 100644 --- a/ci/fmt.mk +++ b/ci/fmt.mk @@ -1,6 +1,12 @@ -fmt: modtidy gofmt goimports prettier shfmt +fmt: modtidy gofmt goimports prettier ifdef CI - ./ci/fmtcheck.sh + if [[ $$(git ls-files --other --modified --exclude-standard) != "" ]]; then + echo "Files need generation or are formatted incorrectly:" + git -c color.ui=always status | grep --color=no '\e\[31m' + echo "Please run the following locally:" + echo " make fmt" + exit 1 + fi endif modtidy: gen @@ -12,11 +18,8 @@ gofmt: gen goimports: gen goimports -w "-local=$$(go list -m)" . -prettier: gen - prettier --write --print-width=120 --no-semi --trailing-comma=all --loglevel=warn $$(git ls-files "*.yaml" "*.yml" "*.md" "*.ts") - -shfmt: gen - shfmt -i 2 -w -s -sr . +prettier: + prettier --write --print-width=120 --no-semi --trailing-comma=all --loglevel=warn $$(git ls-files "*.yml" "*.md") gen: go generate ./... diff --git a/ci/fmtcheck.sh b/ci/fmtcheck.sh deleted file mode 100755 index 6e452a38..00000000 --- a/ci/fmtcheck.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -if [[ $(git ls-files --other --modified --exclude-standard) != "" ]]; then - echo "Files need generation or are formatted incorrectly." - git status - echo "Please run the following locally:" - echo " make fmt" - exit 1 -fi diff --git a/ci/image/Dockerfile b/ci/image/Dockerfile index 7fd5544a..183c9e43 100644 --- a/ci/image/Dockerfile +++ b/ci/image/Dockerfile @@ -3,7 +3,6 @@ FROM golang:1 RUN apt-get update RUN apt-get install -y chromium RUN apt-get install -y npm -RUN apt-get install -y shellcheck ENV GOPATH=/root/gopath ENV PATH=$GOPATH/bin:$PATH @@ -13,14 +12,13 @@ ENV CI=true ENV MAKEFLAGS="--jobs=8 --output-sync=target" COPY ./ci/image/gitignore /root/.config/git/ignore -RUN git config --system color.ui always RUN npm install -g prettier RUN go get golang.org/x/tools/cmd/stringer RUN go get golang.org/x/tools/cmd/goimports -RUN go get mvdan.cc/sh/cmd/shfmt RUN go get golang.org/x/lint/golint RUN go get github.com/agnivade/wasmbrowsertest +RUN go get github.com/mattn/goveralls # Cache go modules and build cache. COPY . /tmp/websocket diff --git a/ci/lint.mk b/ci/lint.mk index f68add41..a656ea8d 100644 --- a/ci/lint.mk +++ b/ci/lint.mk @@ -1,4 +1,4 @@ -lint: govet golint govet-wasm golint-wasm shellcheck +lint: govet golint govet-wasm golint-wasm govet: go vet ./... @@ -11,6 +11,3 @@ golint: golint-wasm: GOOS=js GOARCH=wasm golint -set_exit_status ./... - -shellcheck: - shellcheck -x $$(git ls-files "*.sh") diff --git a/ci/test.mk b/ci/test.mk index 8d46c94a..cebada77 100644 --- a/ci/test.mk +++ b/ci/test.mk @@ -1,18 +1,17 @@ -test: gotest - -gotest: _gotest htmlcov +test: gotest ci/out/coverage.html ifdef CI -gotest: codecov +test: coveralls endif -htmlcov: _gotest +ci/out/coverage.html: gotest go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html -codecov: _gotest - curl -s https://codecov.io/bash | bash -s -- -Z -f ci/out/coverage.prof +coveralls: gotest + echo "--- coveralls" + goveralls -coverprofile=ci/out/coverage.prof -service=github-actions -_gotest: - go test -parallel=32 -coverprofile=ci/out/coverage.prof -coverpkg=./... $$TESTFLAGS ./... +gotest: + go test -parallel=32 -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${TESTFLAGS-} ./... sed -i '/_stringer\.go/d' ci/out/coverage.prof sed -i '/wsecho\.go/d' ci/out/coverage.prof sed -i '/assert\.go/d' ci/out/coverage.prof From dbae76980cdf24bfa4bf1c969c1d81062fbad701 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Oct 2019 13:52:50 -0400 Subject: [PATCH 2/4] Simplify autobahn tests No need to test both client and server side. --- ci/test.mk | 2 +- conn_test.go | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/ci/test.mk b/ci/test.mk index cebada77..a249ea45 100644 --- a/ci/test.mk +++ b/ci/test.mk @@ -11,7 +11,7 @@ coveralls: gotest goveralls -coverprofile=ci/out/coverage.prof -service=github-actions gotest: - go test -parallel=32 -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${TESTFLAGS-} ./... + go test -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${GOTESTFLAGS-} ./... sed -i '/_stringer\.go/d' ci/out/coverage.prof sed -i '/wsecho\.go/d' ci/out/coverage.prof sed -i '/assert\.go/d' ci/out/coverage.prof diff --git a/conn_test.go b/conn_test.go index 4c7d1390..d924fd0a 100644 --- a/conn_test.go +++ b/conn_test.go @@ -1023,14 +1023,7 @@ func TestAutobahn(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - t.Run("server", func(t *testing.T) { - t.Parallel() - run2(t, false) - }) - t.Run("client", func(t *testing.T) { - t.Parallel() - run2(t, true) - }) + run2(t, true) }) } From b0ac42c3873c0099373d8cc8d1e0711e98db994b Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Oct 2019 16:10:25 -0400 Subject: [PATCH 3/4] Cleanup CI image --- .github/workflows/ci.yml | 6 +++--- Makefile | 2 +- README.md | 2 +- ci/{image => }/Dockerfile | 2 -- ci/image/gitignore | 5 ----- ci/test.mk | 2 ++ 6 files changed, 7 insertions(+), 12 deletions(-) rename ci/{image => }/Dockerfile (94%) delete mode 100644 ci/image/gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d13e9028..6154df4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,19 +4,19 @@ on: [push] jobs: fmt: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c steps: - uses: actions/checkout@v1 - run: make fmt lint: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c steps: - uses: actions/checkout@v1 - run: make lint test: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c steps: - uses: actions/checkout@v1 - run: make test diff --git a/Makefile b/Makefile index 62633e39..8c8e1a08 100644 --- a/Makefile +++ b/Makefile @@ -13,5 +13,5 @@ include ci/lint.mk include ci/test.mk ci-image: - docker build -f ./ci/image/Dockerfile -t nhooyr/websocket-ci . + docker build -f ./ci/Dockerfile -t nhooyr/websocket-ci . docker push nhooyr/websocket-ci diff --git a/README.md b/README.md index 4a425a16..8d873fdc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![GitHub Release](https://img.shields.io/github/v/release/nhooyr/websocket?color=6b9ded&sort=semver)](https://github.com/nhooyr/websocket/releases) [![GoDoc](https://godoc.org/nhooyr.io/websocket?status.svg)](https://godoc.org/nhooyr.io/websocket) -[![Codecov](https://img.shields.io/coveralls/github/nhooyr/websocket?color=65d6a4)](https://coveralls.io/github/nhooyr/websocket) +[![Coveralls](https://img.shields.io/coveralls/github/nhooyr/websocket?color=65d6a4)](https://coveralls.io/github/nhooyr/websocket) [![Actions Status](https://github.com/nhooyr/websocket/workflows/ci/badge.svg)](https://github.com/nhooyr/websocket/actions) websocket is a minimal and idiomatic WebSocket library for Go. diff --git a/ci/image/Dockerfile b/ci/Dockerfile similarity index 94% rename from ci/image/Dockerfile rename to ci/Dockerfile index 183c9e43..b9068fa1 100644 --- a/ci/image/Dockerfile +++ b/ci/Dockerfile @@ -11,8 +11,6 @@ ENV PAGER=cat ENV CI=true ENV MAKEFLAGS="--jobs=8 --output-sync=target" -COPY ./ci/image/gitignore /root/.config/git/ignore - RUN npm install -g prettier RUN go get golang.org/x/tools/cmd/stringer RUN go get golang.org/x/tools/cmd/goimports diff --git a/ci/image/gitignore b/ci/image/gitignore deleted file mode 100644 index 3917f38e..00000000 --- a/ci/image/gitignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules -.DS_Store -.idea -.gitignore -.dockerignore diff --git a/ci/test.mk b/ci/test.mk index a249ea45..25609538 100644 --- a/ci/test.mk +++ b/ci/test.mk @@ -8,6 +8,8 @@ ci/out/coverage.html: gotest coveralls: gotest echo "--- coveralls" + export GIT_BRANCH=$${GITHUB_REF} + export BUILD_NUMBER=$${GITHUB_ACTION} goveralls -coverprofile=ci/out/coverage.prof -service=github-actions gotest: From 9b9d7b4aac087688af34698a3a0b45fc8d6303a4 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Oct 2019 17:18:48 -0400 Subject: [PATCH 4/4] Cleanup coveralls setup --- .github/workflows/ci.yml | 10 +++++----- ci/Dockerfile | 1 + ci/test.mk | 12 ++++++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6154df4c..2cc69828 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,27 @@ name: ci -on: [push] +on: [push, pull_request] jobs: fmt: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make fmt lint: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make lint test: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:046cd02e79dcbf81dc06eb6fd333fa8643f2503f437ddd46a4c1af9132078a2c + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make test env: - COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} + COVERALLS_TOKEN: ${{ secrets.github_token }} - name: Upload coverage.html uses: actions/upload-artifact@master with: diff --git a/ci/Dockerfile b/ci/Dockerfile index b9068fa1..0f0fc7d9 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -3,6 +3,7 @@ FROM golang:1 RUN apt-get update RUN apt-get install -y chromium RUN apt-get install -y npm +RUN apt-get install -y jq ENV GOPATH=/root/gopath ENV PATH=$GOPATH/bin:$PATH diff --git a/ci/test.mk b/ci/test.mk index 25609538..f34c2b7f 100644 --- a/ci/test.mk +++ b/ci/test.mk @@ -7,11 +7,15 @@ ci/out/coverage.html: gotest go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html coveralls: gotest + # https://github.com/coverallsapp/github-action/blob/master/src/run.ts echo "--- coveralls" - export GIT_BRANCH=$${GITHUB_REF} - export BUILD_NUMBER=$${GITHUB_ACTION} - goveralls -coverprofile=ci/out/coverage.prof -service=github-actions - + export GIT_BRANCH="$$GITHUB_REF" + export BUILD_NUMBER="$$GITHUB_SHA" + if [[ $$GITHUB_EVENT_NAME == pull_request ]]; then + export CI_PULL_REQUEST="$$(jq .number "$$GITHUB_EVENT_PATH")" + BUILD_NUMBER="$$BUILD_NUMBER-PR-$$CI_PULL_REQUEST" + fi + goveralls -coverprofile=ci/out/coverage.prof -service=github gotest: go test -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${GOTESTFLAGS-} ./... sed -i '/_stringer\.go/d' ci/out/coverage.prof