Skip to content

Commit 5990e78

Browse files
committed
Add CI and Coverage from nhooyr.io/websocket
Properly open sourced :) Closes #2 Closes #3
1 parent 5808228 commit 5990e78

29 files changed

+391
-23
lines changed

.circleci/config.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
version: 2
2+
jobs:
3+
fmt:
4+
docker:
5+
- image: nhooyr/websocket-ci@sha256:77e37211ded3c528e947439e294fbfc03b4fb9f9537c4e5198d5b304fd1df435
6+
steps:
7+
- checkout
8+
- restore_cache:
9+
keys:
10+
- go-v4-{{ checksum "go.sum" }}
11+
# Fallback to using the latest cache if no exact match is found.
12+
- go-v4-
13+
- run: ./ci/fmt.sh
14+
- save_cache:
15+
paths:
16+
- /root/gopath
17+
- /root/.cache/go-build
18+
key: go-v4-{{ checksum "go.sum" }}
19+
20+
lint:
21+
docker:
22+
- image: nhooyr/websocket-ci@sha256:77e37211ded3c528e947439e294fbfc03b4fb9f9537c4e5198d5b304fd1df435
23+
steps:
24+
- checkout
25+
- restore_cache:
26+
keys:
27+
- go-v4-{{ checksum "go.sum" }}
28+
# Fallback to using the latest cache if no exact match is found.
29+
- go-v4-
30+
- run: ./ci/lint.sh
31+
- save_cache:
32+
paths:
33+
- /root/gopath
34+
- /root/.cache/go-build
35+
key: go-v4-{{ checksum "go.sum" }}
36+
37+
test:
38+
docker:
39+
- image: nhooyr/websocket-ci@sha256:77e37211ded3c528e947439e294fbfc03b4fb9f9537c4e5198d5b304fd1df435
40+
steps:
41+
- checkout
42+
- restore_cache:
43+
keys:
44+
- go-v4-{{ checksum "go.sum" }}
45+
# Fallback to using the latest cache if no exact match is found.
46+
- go-v4-
47+
- run: ./ci/test.sh
48+
- store_artifacts:
49+
path: ci/out
50+
destination: out
51+
- save_cache:
52+
paths:
53+
- /root/gopath
54+
- /root/.cache/go-build
55+
key: go-v4-{{ checksum "go.sum" }}
56+
- store_test_results:
57+
path: ci/out
58+
59+
workflows:
60+
version: 2
61+
fmt:
62+
jobs:
63+
- fmt
64+
lint:
65+
jobs:
66+
- lint
67+
test:
68+
jobs:
69+
- test

.github/CODEOWNERS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @nhooyr

.github/CONTRIBUTING.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Contributing
2+
3+
## Issues
4+
5+
Please be as descriptive as possible.
6+
7+
Reproducible examples are key to finding and fixing bugs.
8+
9+
## Pull requests
10+
11+
Good issues for first time contributors are marked as such. Feel free to
12+
reach out for clarification on what needs to be done.
13+
14+
Split up large changes into several small descriptive commits.
15+
16+
Capitalize the first word in the commit message title.
17+
18+
The commit message title should use the verb tense + phrase that completes the blank in
19+
20+
> This change modifies slog to \_\_\_\_\_\_\_\_\_
21+
22+
Be sure to [correctly link](https://help.github.com/en/articles/closing-issues-using-keywords)
23+
to an existing issue if one exists. In general, create an issue before a PR to get some
24+
discussion going and to make sure you do not spend time on a PR that may be rejected.
25+
26+
CI must pass on your changes for them to be merged.
27+
28+
### CI
29+
30+
CI will ensure your code is formatted correctly, passes linting and tests.
31+
It will collect coverage and report it to [codecov](https://codecov.io/gh/cdr/slog)
32+
and also upload a `out/coverage.html` artifact that you can click on to interactively
33+
browse coverage.
34+
35+
You can run CI locally. The various steps are located in [ci/\*.sh](../ci).
36+
37+
1. [fmt.sh](../ci/fmt.sh) which requires node (specifically prettier).
38+
1. [lint.sh](../ci/lint.sh) which requires [shellcheck](https://github.com/koalaman/shellcheck#installing).
39+
1. [test.sh](../ci/test.sh)
40+
1. [run.sh](../ci/run.sh) which runs the above scripts in order.
41+
42+
For coverage details locally, see `ci/out/coverage.html` after running [test.sh](../ci/test.sh).
43+
44+
See [ci/image/Dockerfile](../ci/image/Dockerfile) for the installation of the CI dependencies on Ubuntu.
45+
46+
You can also run tests normally with `go test`. [test.sh](../ci/test.sh) just passes a default set of flags to
47+
`go test` to collect coverage and also prettify the output.
48+
49+
You can pass flags to [test.sh](../ci/test.sh) if you want to run a specific test or otherwise
50+
control the behaviour of `go test` but also get coverage.
51+
52+
Coverage percentage from codecov and the CI scripts will be different because they are calculated differently.

.github/ISSUE_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- Please be as descriptive as possible. -->
2+
<!-- Reproducible examples are key to finding and fixing bugs. -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- Please read the contributing guidelines. -->
2+
<!-- https://github.com/cdr/slog/blob/master/.github/CONTRIBUTING.md#pull-requests -->

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Coder Technologies, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
# slog
1+
# websocket
22

3-
The Coder Go structured logging library.
3+
[![GoDoc](https://godoc.org/go.coder.com/slog?status.svg)](https://godoc.org/go.coder.com/slog)
4+
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/cdr/slog?color=critical&sort=semver)](https://github.com/cdr/slog/releases)
5+
[![Codecov](https://img.shields.io/codecov/c/github/cdr/slog.svg?color=success)](https://codecov.io/gh/cdr/slog)
6+
[![CI](https://img.shields.io/circleci/build/github/cdr/slog?label=ci)](https://github.com/cdr/slog/commits/master)
7+
8+
slog is a minimal and idiomatic structured logging library for Go.
9+
10+
## Install
11+
12+
```bash
13+
go get go.coder.com/slog
14+
```

ci/.codecov.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
comment: off
2+
coverage:
3+
status:
4+
# Prevent small changes in coverage from failing CI.
5+
project:
6+
default:
7+
threshold: 10
8+
patch:
9+
default:
10+
threshold: 50

ci/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out

ci/fmt.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
cd "$(dirname "${0}")"
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
gen() {
8+
# Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
9+
# See https://github.com/golang/go/issues/27005
10+
go list ./... > /dev/null
11+
go mod tidy
12+
13+
go generate ./...
14+
}
15+
16+
fmt() {
17+
gofmt -w -s .
18+
go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
19+
go run mvdan.cc/sh/cmd/shfmt -i 2 -w -s -sr .
20+
# shellcheck disable=SC2046
21+
npx prettier \
22+
--write \
23+
--print-width 120 \
24+
--no-semi \
25+
--trailing-comma all \
26+
--loglevel silent \
27+
$(git ls-files "*.yaml" "*.yml" "*.md")
28+
}
29+
30+
unstaged_files() {
31+
git ls-files --other --modified --exclude-standard
32+
}
33+
34+
check() {
35+
if [[ ${CI:-} && $(unstaged_files) != "" ]]; then
36+
echo
37+
echo "Files need generation or are formatted incorrectly."
38+
echo "Run:"
39+
echo "./ci/fmt.sh"
40+
echo
41+
git status
42+
git diff
43+
exit 1
44+
fi
45+
}
46+
47+
gen
48+
fmt
49+
check

0 commit comments

Comments
 (0)