Skip to content

Commit 4cfcb02

Browse files
committed
ci(github): setup GitHub Actions
1 parent d177839 commit 4cfcb02

File tree

4 files changed

+386
-0
lines changed

4 files changed

+386
-0
lines changed

.github/workflows/ci.yml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: CI
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
name: Lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: golangci-lint
12+
uses: golangci/golangci-lint-action@v2
13+
with:
14+
version: v1.44
15+
env:
16+
VERBOSE: "true"
17+
18+
tidy:
19+
name: Tidy
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions/setup-go@v2
24+
with:
25+
go-version: 1.15
26+
- uses: actions/cache@v2
27+
with:
28+
path: ~/go/pkg/mod
29+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
30+
restore-keys: |
31+
${{ runner.os }}-go-
32+
- name: Check if mods are tidy
33+
run: make check-tidy
34+
35+
cov:
36+
name: Coverage
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-go@v2
41+
with:
42+
go-version: 1.16
43+
- uses: actions/cache@v2
44+
with:
45+
path: ~/go/pkg/mod
46+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
47+
restore-keys: |
48+
${{ runner.os }}-go-
49+
- name: Publish coverage
50+
uses: paambaati/[email protected]
51+
env:
52+
VERBOSE: "true"
53+
GOMAXPROCS: 4
54+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
55+
with:
56+
coverageCommand: make cov
57+
prefix: github.com/${{ github.repository }}
58+
coverageLocations: |
59+
${{ github.workspace }}/coverage.out:gocov
60+
61+
test:
62+
name: Test
63+
strategy:
64+
fail-fast: false
65+
matrix:
66+
go_version:
67+
- "1.15"
68+
- "1.16"
69+
- "1.17"
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v2
73+
- uses: actions/setup-go@v2
74+
with:
75+
go-version: ${{ matrix.go_version }}
76+
- uses: actions/cache@v2
77+
with:
78+
path: ~/go/pkg/mod
79+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
80+
restore-keys: |
81+
${{ runner.os }}-go-
82+
- name: Run tests
83+
run: go test -v -count=1 -race ./...

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/*
2+
coverage.out

.golangci.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
linters-settings:
2+
funlen:
3+
lines: 100
4+
statements: 150
5+
gocyclo:
6+
min-complexity: 20
7+
golint:
8+
min-confidence: 0
9+
govet:
10+
check-shadowing: true
11+
enable-all: true
12+
disable:
13+
- fieldalignment
14+
lll:
15+
line-length: 80
16+
tab-width: 4
17+
maligned:
18+
suggest-new: true
19+
misspell:
20+
locale: US
21+
22+
linters:
23+
disable-all: true
24+
enable:
25+
- asciicheck
26+
- bodyclose
27+
- deadcode
28+
- depguard
29+
- durationcheck
30+
- errcheck
31+
- errorlint
32+
- exhaustive
33+
- exportloopref
34+
- funlen
35+
- gochecknoinits
36+
- goconst
37+
- gocritic
38+
- gocyclo
39+
- godot
40+
- gofumpt
41+
- goimports
42+
- goprintffuncname
43+
- gosec
44+
- gosimple
45+
- govet
46+
- importas
47+
- ineffassign
48+
- lll
49+
- misspell
50+
- nakedret
51+
- nilerr
52+
- nlreturn
53+
- noctx
54+
- nolintlint
55+
- prealloc
56+
- predeclared
57+
- revive
58+
- rowserrcheck
59+
- sqlclosecheck
60+
- staticcheck
61+
- structcheck
62+
- tparallel
63+
- typecheck
64+
- unconvert
65+
- unparam
66+
- unused
67+
- varcheck
68+
- wastedassign
69+
- whitespace
70+
71+
issues:
72+
exclude:
73+
- Using the variable on range scope `tt` in function literal
74+
- Using the variable on range scope `tc` in function literal
75+
exclude-rules:
76+
- path: "_test\\.go"
77+
linters:
78+
- funlen
79+
- dupl
80+
- source: "^//go:generate "
81+
linters:
82+
- lll
83+
- source: "`json:"
84+
linters:
85+
- lll
86+
- source: "`xml:"
87+
linters:
88+
- lll
89+
- source: "`yaml:"
90+
linters:
91+
- lll
92+
93+
run:
94+
timeout: 2m
95+
allow-parallel-runners: true
96+
modules-download-mode: readonly

Makefile

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
GOMODNAME := $(shell grep 'module' go.mod | sed -e 's/^module //')
2+
SOURCES := $(shell find . -name "*.go" -or -name "go.mod" -or -name "go.sum" \
3+
-or -name "Makefile")
4+
5+
# Verbose output
6+
ifdef VERBOSE
7+
V = -v
8+
endif
9+
10+
#
11+
# Environment
12+
#
13+
14+
BINDIR := bin
15+
TOOLDIR := $(BINDIR)/tools
16+
17+
# Global environment variables for all targets
18+
SHELL ?= /bin/bash
19+
SHELL := env \
20+
GO111MODULE=on \
21+
GOBIN=$(CURDIR)/$(TOOLDIR) \
22+
CGO_ENABLED=1 \
23+
PATH='$(CURDIR)/$(BINDIR):$(CURDIR)/$(TOOLDIR):$(PATH)' \
24+
$(SHELL)
25+
26+
#
27+
# Defaults
28+
#
29+
30+
# Default target
31+
.DEFAULT_GOAL := test
32+
33+
#
34+
# Tools
35+
#
36+
37+
TOOLS += $(TOOLDIR)/gobin
38+
$(TOOLDIR)/gobin:
39+
GO111MODULE=off go get -u github.com/myitcv/gobin
40+
41+
# external tool
42+
define tool # 1: binary-name, 2: go-import-path
43+
TOOLS += $(TOOLDIR)/$(1)
44+
45+
$(TOOLDIR)/$(1): $(TOOLDIR)/gobin Makefile
46+
gobin $(V) "$(2)"
47+
endef
48+
49+
$(eval $(call tool,godoc,golang.org/x/tools/cmd/godoc))
50+
$(eval $(call tool,gofumpt,mvdan.cc/gofumpt))
51+
$(eval $(call tool,goimports,golang.org/x/tools/cmd/goimports))
52+
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/[email protected]))
53+
$(eval $(call tool,gomod,github.com/Helcaraxan/gomod))
54+
55+
.PHONY: tools
56+
tools: $(TOOLS)
57+
58+
#
59+
# Development
60+
#
61+
62+
BENCH ?= .
63+
TESTARGS ?=
64+
65+
.PHONY: clean
66+
clean:
67+
rm -f $(TOOLS)
68+
rm -f ./coverage.out ./go.mod.tidy-check ./go.sum.tidy-check
69+
70+
.PHONY: test
71+
test:
72+
go test $(V) -count=1 -race $(TESTARGS) ./...
73+
74+
.PHONY: test-deps
75+
test-deps:
76+
go test all
77+
78+
.PHONY: lint
79+
lint: $(TOOLDIR)/golangci-lint
80+
golangci-lint $(V) run
81+
82+
.PHONY: format
83+
format: $(TOOLDIR)/goimports $(TOOLDIR)/gofumpt
84+
goimports -w . && gofumpt -w .
85+
86+
.SILENT: bench
87+
.PHONY: bench
88+
bench:
89+
go test $(V) -count=1 -bench=$(BENCH) $(TESTARGS) ./...
90+
91+
.PHONY: golden-update
92+
golden-update:
93+
GOLDEN_UPDATE=1 $(MAKE) test
94+
95+
.PHONY: golden-clean
96+
golden-clean:
97+
find . -type f -name '*.golden' -path '*/testdata/*' -delete
98+
find . -type d -empty -path '*/testdata/*' -delete
99+
100+
.PHONY: golden-regen
101+
golden-regen: golden-clean golden-update
102+
103+
#
104+
# Code Generation
105+
#
106+
107+
.PHONY: generate
108+
generate:
109+
go generate ./...
110+
111+
.PHONY: check-generate
112+
check-generate:
113+
$(eval CHKDIR := $(shell mktemp -d))
114+
cp -av . "$(CHKDIR)"
115+
make -C "$(CHKDIR)/" generate
116+
( diff -rN . "$(CHKDIR)" && rm -rf "$(CHKDIR)" ) || \
117+
( rm -rf "$(CHKDIR)" && exit 1 )
118+
119+
#
120+
# Coverage
121+
#
122+
123+
.PHONY: cov
124+
cov: coverage.out
125+
126+
.PHONY: cov-html
127+
cov-html: coverage.out
128+
go tool cover -html=./coverage.out
129+
130+
.PHONY: cov-func
131+
cov-func: coverage.out
132+
go tool cover -func=./coverage.out
133+
134+
coverage.out: $(SOURCES)
135+
go test $(V) -covermode=count -coverprofile=./coverage.out ./...
136+
137+
#
138+
# Dependencies
139+
#
140+
141+
.PHONY: deps
142+
deps:
143+
go mod download
144+
145+
.PHONY: deps-update
146+
deps-update:
147+
go get -u -t ./...
148+
149+
.PHONY: deps-analyze
150+
deps-analyze: $(TOOLDIR)/gomod
151+
gomod analyze
152+
153+
.PHONY: tidy
154+
tidy:
155+
go mod tidy $(V)
156+
157+
.PHONY: verify
158+
verify:
159+
go mod verify
160+
161+
.SILENT: check-tidy
162+
.PHONY: check-tidy
163+
check-tidy:
164+
cp go.mod go.mod.tidy-check
165+
cp go.sum go.sum.tidy-check
166+
go mod tidy
167+
( \
168+
diff go.mod go.mod.tidy-check && \
169+
diff go.sum go.sum.tidy-check && \
170+
rm -f go.mod go.sum && \
171+
mv go.mod.tidy-check go.mod && \
172+
mv go.sum.tidy-check go.sum \
173+
) || ( \
174+
rm -f go.mod go.sum && \
175+
mv go.mod.tidy-check go.mod && \
176+
mv go.sum.tidy-check go.sum; \
177+
exit 1 \
178+
)
179+
180+
#
181+
# Documentation
182+
#
183+
184+
# Serve docs
185+
.PHONY: docs
186+
docs: $(TOOLDIR)/godoc
187+
$(info serviing docs on http://127.0.0.1:6060/pkg/$(GOMODNAME)/)
188+
@godoc -http=127.0.0.1:6060
189+
190+
#
191+
# Release
192+
#
193+
194+
.PHONY: new-version
195+
new-version: check-npx
196+
npx standard-version
197+
198+
.PHONY: next-version
199+
next-version: check-npx
200+
npx standard-version --dry-run
201+
202+
.PHONY: check-npx
203+
check-npx:
204+
$(if $(shell which npx),,\
205+
$(error No npx found in PATH, please install NodeJS))

0 commit comments

Comments
 (0)