Skip to content

Commit 1dbdbbe

Browse files
committed
Refactor and simplify
Closes #50 Closes #49 Closes #48 Closes #47 Closes #40 Closes #38
1 parent 1898607 commit 1dbdbbe

35 files changed

+339
-707
lines changed

.circleci/config.yml

-69
This file was deleted.

.github/CODEOWNERS.txt

-1
This file was deleted.

.github/CONTRIBUTING.md

+11-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Capitalize the first word in the commit message title.
1717

1818
The commit message title should use the verb tense + phrase that completes the blank in
1919

20-
> This change modifies slog to \_\_\_\_\_\_\_\_\_
20+
> This change modifies websocket to \_\_\_\_\_\_\_\_\_
2121
2222
Be sure to [correctly link](https://help.github.com/en/articles/closing-issues-using-keywords)
2323
to an existing issue if one exists. In general, create an issue before a PR to get some
@@ -27,26 +27,19 @@ CI must pass on your changes for them to be merged.
2727

2828
### CI
2929

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.
30+
CI will ensure your code is formatted, lints and passes tests.
31+
It will collect coverage and report it to [coveralls](https://coveralls.io/github/cdr/slog)
32+
and also upload a html `coverage` artifact that you can download to browse coverage.
3433

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).
34+
You can run CI locally.
4335

4436
See [ci/image/Dockerfile](../ci/image/Dockerfile) for the installation of the CI dependencies on Ubuntu.
4537

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.
38+
1. `make fmt` performs code generation and formatting.
39+
1. `make lint` performs linting.
40+
1. `make test` runs tests.
41+
1. `make` runs the above targets.
4842

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.
43+
For coverage details locally, see `ci/out/coverage.html` after running `make test`.
5144

52-
Coverage percentage from codecov and the CI scripts will be different because they are calculated differently.
45+
You can run tests normally with `go test`. `make test` wraps around `go test` to collect coverage.

.github/workflows/ci.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: ci
2+
on: [push, pull_request]
3+
4+
jobs:
5+
fmt:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v1
9+
- uses: actions/cache@v1
10+
with:
11+
path: ~/go/pkg/mod
12+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
13+
restore-keys: |
14+
${{ runner.os }}-go-
15+
- name: make fmt
16+
uses: ./ci/image
17+
with:
18+
args: make fmt
19+
20+
lint:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v1
24+
- uses: actions/cache@v1
25+
with:
26+
path: ~/go/pkg/mod
27+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28+
restore-keys: |
29+
${{ runner.os }}-go-
30+
- name: make lint
31+
uses: ./ci/image
32+
with:
33+
args: make lint
34+
35+
test:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v1
39+
- uses: actions/cache@v1
40+
with:
41+
path: ~/go/pkg/mod
42+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
43+
restore-keys: |
44+
${{ runner.os }}-go-
45+
- name: make test
46+
uses: ./ci/image
47+
with:
48+
args: make test
49+
env:
50+
COVERALLS_TOKEN: ${{ secrets.github_token }}
51+
- name: Upload coverage.html
52+
uses: actions/upload-artifact@master
53+
with:
54+
name: coverage
55+
path: ci/out/coverage.html

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: fmt lint test
2+
3+
.SILENT:
4+
5+
.PHONY: *
6+
7+
.ONESHELL:
8+
SHELL = bash
9+
.SHELLFLAGS = -ceuo pipefail
10+
11+
include ci/fmt.mk
12+
include ci/lint.mk
13+
include ci/test.mk

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# slog
22

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?include_prereleases&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)
3+
[![GitHub Release](https://img.shields.io/github/v/release/cdr/sog?color=6b9ded&sort=semver)](https://github.com/cdr/sog/releases)
4+
[![GoDoc](https://godoc.org/nhooyr.io/websocket?status.svg)](https://godoc.org/nhooyr.io/websocket)
5+
[![Coveralls](https://img.shields.io/coveralls/github/cdr/sog?color=65d6a4)](https://coveralls.io/github/cdr/sog)
6+
[![CI Status](https://github.com/cdr/sog/workflows/ci/badge.svg)](https://github.com/cdr/sog/actions)
77

88
slog is a minimal structured logging library for Go.
99

ci/.codecov.yml

-10
This file was deleted.

ci/.gitignore

-1
This file was deleted.

ci/fmt.mk

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fmt: modtidy gofmt goimports prettier
2+
ifdef CI
3+
if [[ $$(git ls-files --other --modified --exclude-standard) != "" ]]; then
4+
echo "Files need generation or are formatted incorrectly:"
5+
git -c color.ui=always status | grep --color=no '\e\[31m'
6+
echo "Please run the following locally:"
7+
echo " make fmt"
8+
exit 1
9+
fi
10+
endif
11+
12+
modtidy: gen
13+
go mod tidy
14+
15+
gofmt: gen
16+
gofmt -w -s .
17+
18+
goimports: gen
19+
goimports -w "-local=$$(go list -m)" .
20+
21+
prettier:
22+
prettier --write --print-width=120 --no-semi --trailing-comma=all --loglevel=warn $$(git ls-files "*.yml" "*.md")
23+
24+
gen:
25+
go generate ./...

ci/fmt.sh

-49
This file was deleted.

ci/image/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1
2+
3+
RUN apt-get update
4+
RUN apt-get install -y npm
5+
6+
ENV GOFLAGS="-mod=readonly"
7+
ENV PAGER=cat
8+
ENV CI=true
9+
ENV MAKEFLAGS="--jobs=8 --output-sync=target"
10+
11+
RUN npm install -g prettier
12+
RUN go get golang.org/x/tools/cmd/goimports
13+
RUN go get golang.org/x/lint/golint
14+
RUN go get github.com/mattn/goveralls

ci/lint.mk

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
lint: govet golint
2+
3+
govet:
4+
go vet -composites=false ./...
5+
6+
golint:
7+
golint -set_exit_status ./...

ci/lint.sh

-10
This file was deleted.

ci/out/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

ci/run.sh

-11
This file was deleted.

ci/test.mk

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test: gotest ci/out/coverage.html
2+
ifdef CI
3+
test: coveralls
4+
endif
5+
6+
ci/out/coverage.html: gotest
7+
go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html
8+
9+
coveralls: gotest
10+
# https://github.com/coverallsapp/github-action/blob/master/src/run.ts
11+
echo "--- coveralls"
12+
export GIT_BRANCH="$$GITHUB_REF"
13+
export BUILD_NUMBER="$$GITHUB_SHA"
14+
if [[ $$GITHUB_EVENT_NAME == pull_request ]]; then
15+
export CI_PULL_REQUEST="$$(jq .number "$$GITHUB_EVENT_PATH")"
16+
BUILD_NUMBER="$$BUILD_NUMBER-PR-$$CI_PULL_REQUEST"
17+
fi
18+
goveralls -coverprofile=ci/out/coverage.prof -service=github
19+
20+
gotest:
21+
go test -covermode=count -coverprofile=ci/out/coverage.prof -coverpkg=./... $${GOTESTFLAGS-} ./...
22+
sed -i '/_stringer\.go/d' ci/out/coverage.prof

0 commit comments

Comments
 (0)