Skip to content

Commit

Permalink
Switch to arch linux for CI
Browse files Browse the repository at this point in the history
Race detector doesn't work on alpine.

See golang/go#14481
  • Loading branch information
nhooyr committed Aug 21, 2019
1 parent 1e60655 commit 4132e3c
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 47 deletions.
38 changes: 21 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
- go-v3-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- go-v3-
- run: ./ci/fmt.sh
- save_cache:
paths:
- /go
- /root/gopath
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}
key: go-v3-{{ checksum "go.sum" }}

lint:
docker:
Expand All @@ -24,15 +24,15 @@ jobs:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
- go-v3-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- go-v3-
- run: ./ci/lint.sh
- save_cache:
paths:
- /go
- /root/gopath
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}
key: go-v3-{{ checksum "go.sum" }}

test:
docker:
Expand All @@ -41,17 +41,20 @@ jobs:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
- go-v3-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- go-v3-
- run: ./ci/test.sh
- store_artifacts:
path: ci/out
destination: out
- save_cache:
paths:
- /go
- /root/gopath
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}
key: go-v3-{{ checksum "go.sum" }}
- store_test_results:
path: ci/out

bench:
docker:
Expand All @@ -60,17 +63,18 @@ jobs:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
- go-v3-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- go-v3-
- run: ./ci/bench.sh
- store_artifacts:
path: ci/out
destination: out
- save_cache:
paths:
- /go
- /root/gopath
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}
key: go-v3-{{ checksum "go.sum" }}

workflows:
version: 2
Expand All @@ -85,4 +89,4 @@ workflows:
- test
bench:
jobs:
- bench
- bench
23 changes: 18 additions & 5 deletions ci/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"

mkdir -p ci/out
go test -vet=off -run=^$ -bench=. -o=ci/out/websocket.test \
-cpuprofile=ci/out/cpu.prof \
-memprofile=ci/out/mem.prof \
-blockprofile=ci/out/block.prof \
-mutexprofile=ci/out/mutex.prof \
benchArgs=(
"-vet=off"
"-run=^$"
"-bench=."
"-o=ci/out/websocket.test"
"-cpuprofile=ci/out/cpu.prof"
"-memprofile=ci/out/mem.prof"
"-blockprofile=ci/out/block.prof"
"-mutexprofile=ci/out/mutex.prof"
.
)

if [[ ${CI-} ]]; then
# https://circleci.com/docs/2.0/collect-test-data/
go test "${benchArgs[@]}" | tee /dev/stderr |
go run github.com/jstemmer/go-junit-report > ci/out/benchReport.xml
else
go test "${benchArgs[@]}"
fi

echo
echo "Profiles are in ./ci/out/*.prof
Expand Down
23 changes: 11 additions & 12 deletions ci/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
FROM golang:1-alpine
FROM circleci/golang:1-node
USER root

RUN apk add --update bash git
ENV DEBIAN_FRONTEND=noninteractive
ENV GOPATH /root/gopath
ENV GOFLAGS -mod=readonly

# Autobahn Test suite.
RUN apk add py2-pip python2-dev gcc libffi-dev libc-dev openssl-dev && \
pip install autobahntestsuite
COPY . /tmp/websocket
RUN cd /tmp/websocket && go mod download && rm -rf

# prettier.
RUN apk add npm && npm install -g prettier
RUN apt-get update && \
apt-get install -y shellcheck python-pip && \
pip2 install autobahntestsuite && \
npm install -g prettier

# shellcheck
RUN apk add xz curl && \
curl -o /tmp/shellcheck.tar.xz -L https://storage.googleapis.com/shellcheck/shellcheck-stable.linux.x86_64.tar.xz && \
tar -xf /tmp/shellcheck.tar.xz && \
ln -s "${PWD}/shellcheck-stable/shellcheck" /usr/local/bin/shellcheck
3 changes: 2 additions & 1 deletion ci/image/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -euo pipefail
cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"

docker build -t nhooyr/websocket-ci .
docker build -f ./ci/image/Dockerfile -t nhooyr/websocket-ci .
docker push nhooyr/websocket-ci
2 changes: 1 addition & 1 deletion ci/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"

# shellcheck disable=SC2046
shellcheck -e SC1091 -x $(git ls-files "*.sh")
shellcheck -x $(git ls-files "*.sh")
go vet ./...
go run golang.org/x/lint/golint -set_exit_status ./...
14 changes: 9 additions & 5 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"

mkdir -p ci/out
# If you'd like to modify the args to go test, just run go test directly, this script is meant
# for running tests at the end to get coverage and test under the race detector.
go test -race -vet=off -coverprofile=ci/out/coverage.prof -coverpkg=./... ./...
testFlags=(-race "-vet=off" "-coverprofile=ci/out/coverage.prof" "-coverpkg=./...")
if [[ ${CI-} ]]; then
# https://circleci.com/docs/2.0/collect-test-data/
go test "${testFlags[@]}" -v ./... 2>&1 | tee /dev/stderr |
go run github.com/jstemmer/go-junit-report > ci/out/testReport.xml
else
go test "${testFlags[@]}" ./...
fi
go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html

if [[ ${CI:-} ]]; then
bash <(curl -s https://codecov.io/bash) -f ci/out/coverage.prof
else
go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html
fi
10 changes: 4 additions & 6 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ For remote coverage, you can use either [codecov](https://codecov.io/gh/nhooyr/w

You can also run any of the CI steps individually. All of them are scripts in the `ci` directory.

See [../ci/lint.sh](../ci/lint.sh) and [../ci/test.sh](../ci/test.sh) for the
installation of shellcheck, node and the Autobahn test suite on Debian or Ubuntu.
See [../ci/image/Dockerfile](../ci/image/Dockerfile) for the
installation of the CI dependencies on arch linux.

For Go, please refer to the [offical docs](https://golang.org/doc/install).

You can benchmark the library with `./ci/benchmark.sh`. You only need Go to run that script. Benchmark
profiles generated by that script are also available as artifacts on the bench step.
You can benchmark the library with `./ci/benchmark.sh`. You only need Go to run that script.
Benchmark profiles generated by that script are also available as artifacts on the bench step.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.12
require (
github.com/golang/protobuf v1.3.1
github.com/google/go-cmp v0.2.0
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024
github.com/kr/pretty v0.1.0 // indirect
go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tools

// See https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md
import (
_ "github.com/jstemmer/go-junit-report"
_ "go.coder.com/go-tools/cmd/goimports"
_ "golang.org/x/lint/golint"
_ "golang.org/x/tools/cmd/stringer"
Expand Down

0 comments on commit 4132e3c

Please sign in to comment.