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..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:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make fmt lint: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make lint test: runs-on: ubuntu-latest - container: nhooyr/websocket-ci@sha256:ea94e078d2d589d654a2c759d952bf4199c754d80dadb20696dc3902359027cb + container: nhooyr/websocket-ci@sha256:8a8fd73fdea33585d50a33619c4936adfd016246a2ed6bbfbf06def24b518a6a steps: - uses: actions/checkout@v1 - run: make test env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + COVERALLS_TOKEN: ${{ secrets.github_token }} - name: Upload coverage.html uses: actions/upload-artifact@master with: diff --git a/Makefile b/Makefile index ce92ab5b..8c8e1a08 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,14 @@ all: fmt lint test .PHONY: * +.ONESHELL: +SHELL = bash +.SHELLFLAGS = -ceuo pipefail + include ci/fmt.mk 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 9dd5d0a8..8d873fdc 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) +[![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/.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/image/Dockerfile b/ci/Dockerfile similarity index 83% rename from ci/image/Dockerfile rename to ci/Dockerfile index 7fd5544a..0f0fc7d9 100644 --- a/ci/image/Dockerfile +++ b/ci/Dockerfile @@ -3,7 +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 shellcheck +RUN apt-get install -y jq ENV GOPATH=/root/gopath ENV PATH=$GOPATH/bin:$PATH @@ -12,15 +12,12 @@ ENV PAGER=cat 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/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/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/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..f34c2b7f 100644 --- a/ci/test.mk +++ b/ci/test.mk @@ -1,18 +1,23 @@ -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 - -_gotest: - go test -parallel=32 -coverprofile=ci/out/coverage.prof -coverpkg=./... $$TESTFLAGS ./... +coveralls: gotest + # https://github.com/coverallsapp/github-action/blob/master/src/run.ts + echo "--- coveralls" + 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 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) }) }