Skip to content

Switch to CircleCI #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 2
jobs:
fmt:
docker:
- image: golang:1
steps:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- run: ./ci/fmt.sh
- save_cache:
paths:
- /go
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}

lint:
docker:
- image: golang:1
steps:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- run: ./ci/lint.sh
- save_cache:
paths:
- /go
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}

test:
docker:
- image: golang:1
steps:
- checkout
- restore_cache:
keys:
- go-{{ checksum "go.sum" }}
# Fallback to using the latest cache if no exact match is found.
- go-
- run: ./ci/test.sh
- save_cache:
paths:
- /go
- /root/.cache/go-build
key: go-{{ checksum "go.sum" }}

workflows:
version: 2
fmt:
jobs:
- fmt
lint:
jobs:
- lint
test:
jobs:
- test
21 changes: 0 additions & 21 deletions .github/main.workflow

This file was deleted.

1 change: 1 addition & 0 deletions ci/.codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
comment: off
coverage:
status:
# Prevent small changes in coverage from failing CI.
Expand Down
16 changes: 16 additions & 0 deletions ci/bench.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -euo pipefail
cd "$(dirname "${0}")"
source ./lib.sh

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 \
.

echo
echo "Profiles are in ./ci/out/*.prof
Keep in mind that every profiler Go provides is enabled so that may skew the benchmarks."
10 changes: 0 additions & 10 deletions ci/bench/Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions ci/bench/entrypoint.sh

This file was deleted.

37 changes: 37 additions & 0 deletions ci/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -euo pipefail
cd "$(dirname "${0}")"
source ./lib.sh

unstaged_files() {
git ls-files --other --modified --exclude-standard
}

gen() {
# Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
# See https://github.com/golang/go/issues/27005
go list ./... > /dev/null
go mod tidy

go generate ./...
}

fmt() {
gofmt -w -s .
go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
go run mvdan.cc/sh/cmd/shfmt -i 2 -w -s -sr .
}

gen
fmt

if [[ $CI && $(unstaged_files) != "" ]]; then
echo
echo "Files either need generation or are formatted incorrectly."
echo "Please run:"
echo "./ci/fmt.sh"
echo
git status
exit 1
fi
10 changes: 0 additions & 10 deletions ci/fmt/Dockerfile

This file was deleted.

36 changes: 0 additions & 36 deletions ci/fmt/entrypoint.sh

This file was deleted.

16 changes: 7 additions & 9 deletions ci/lib.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env bash

set -euxo pipefail || exit 1

export GO111MODULE=on
export PAGER=cat

# shellcheck disable=SC2034
# CI is used by the scripts that source this file.
export CI=${GITHUB_ACTION-}
set -euo pipefail

# Ensures $CI can be used if it's set or not.
export CI=${CI:-}
if [[ $CI ]]; then
export GOFLAGS=-mod=readonly
export GOFLAGS=-mod=readonly
export DEBIAN_FRONTEND=noninteractive
fi

cd "$(git rev-parse --show-toplevel)"
15 changes: 15 additions & 0 deletions ci/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -euo pipefail
cd "$(dirname "${0}")"
source ./lib.sh

if [[ $CI ]]; then
apt-get update -qq
apt-get install -qq shellcheck > /dev/null
fi

# shellcheck disable=SC2046
shellcheck -e SC1091 -x $(git ls-files "*.sh")
go vet ./...
go run golang.org/x/lint/golint -set_exit_status ./...
12 changes: 0 additions & 12 deletions ci/lint/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions ci/lint/entrypoint.sh

This file was deleted.

64 changes: 7 additions & 57 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -1,61 +1,11 @@
#!/usr/bin/env bash

# This script is for local testing. See .github for CI.
# This script is for local testing. See .circleci for CI.

cd "$(dirname "${0}")/.." || exit 1
source ci/lib.sh || exit 1
set -euo pipefail
cd "$(dirname "${0}")"
source ./lib.sh

function docker_run() {
local DIR="$1"
local IMAGE
IMAGE="$(docker build -q "$DIR")"
docker run \
-it \
-v "${PWD}:/repo" \
-v "$(go env GOPATH):/go" \
-v "$(go env GOCACHE):/root/.cache/go-build" \
-w /repo \
"${IMAGE}"
}

function help() {
set +x
echo
echo "$0 [-h] <step>"
cat << EOF

If you do not pass in an explicit step, all steps will be ran in order.
Pass "analyze" as the step to be put into an interactive container to analyze
profiles.
EOF
exit 1
}

# Use this to analyze benchmark profiles.
if [[ ${1-} == "analyze" ]]; then
docker run \
-it \
-v "${PWD}:/repo" \
-v "$(go env GOPATH):/go" \
-v "$(go env GOCACHE):/root/.cache/go-build" \
-w /repo \
golang:1.12
fi

if [[ ${1-} == "-h" || ${1-} == "--help" || ${1-} == "help" ]]; then
help
fi

if [[ $# -gt 0 ]]; then
if [[ ! -d "ci/$*" ]]; then
help
fi

docker_run "ci/$*"
exit 0
fi

docker_run ci/fmt
docker_run ci/lint
docker_run ci/test
docker_run ci/bench
./fmt.sh
./lint.sh
./test.sh
30 changes: 30 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -euo pipefail
cd "$(dirname "${0}")"
source ./lib.sh

echo "This step includes benchmarks for race detection and coverage purposes
but the numbers will be misleading. please see the bench step or ./bench.sh for
more accurate numbers."
echo

if [[ $CI ]]; then
apt-get update -qq
apt-get install -qq python-pip > /dev/null
# Need to add pip install directory to $PATH.
export PATH="/home/circleci/.local/bin:$PATH"
pip install -qqq autobahntestsuite
fi

go test -race -coverprofile=ci/out/coverage.prof --vet=off -bench=. -coverpkg=./... ./...
go tool cover -func=ci/out/coverage.prof

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

echo
echo "Please open ci/out/coverage.html to see detailed test coverage stats."
fi
14 changes: 0 additions & 14 deletions ci/test/Dockerfile

This file was deleted.

Loading