-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
962 changed files
with
756,066 additions
and
27,795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
GO_VERSION: '1.21' | ||
|
||
jobs: | ||
# Check if there is any dirty change for go mod tidy | ||
go-mod: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Check go mod | ||
run: | | ||
go mod tidy | ||
git diff --exit-code go.mod | ||
git diff --exit-code go.sum | ||
# We already run the current golangci-lint in tests, but here we test | ||
# our GitHub action with the latest stable golangci-lint. | ||
golangci-lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: lint | ||
uses: golangci/golangci-lint-action@v3.7.0 | ||
with: | ||
version: latest | ||
# skip cache because of flaky behaviors | ||
skip-build-cache: true | ||
skip-pkg-cache: true | ||
|
||
tests-on-windows: | ||
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ env.GO_VERSION }} # test only the latest go version to speed up CI | ||
- name: Run tests | ||
run: make.exe test | ||
|
||
tests-on-macos: | ||
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ env.GO_VERSION }} # test only the latest go version to speed up CI | ||
- name: Run tests | ||
run: make test | ||
|
||
tests-on-unix: | ||
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
golang: | ||
- '1.21' | ||
- '1.22' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ matrix.golang }} | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ matrix.golang }}-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-${{ matrix.golang }}- | ||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Test | ||
on: [push] | ||
|
||
jobs: | ||
unit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21.x' | ||
- name: Test with the Go CLI | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
linters-settings: | ||
depguard: | ||
rules: | ||
logger: | ||
deny: | ||
- pkg: "github.com/pkg/errors" | ||
desc: Should be replaced by standard lib errors package. | ||
- pkg: "github.com/instana/testify" | ||
desc: It's a fork of github.com/stretchr/testify. | ||
dupl: | ||
threshold: 100 | ||
funlen: | ||
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner. | ||
statements: 50 | ||
goconst: | ||
min-len: 2 | ||
min-occurrences: 3 | ||
gocritic: | ||
enabled-tags: | ||
- diagnostic | ||
- experimental | ||
- opinionated | ||
- performance | ||
- style | ||
disabled-checks: | ||
- dupImport # https://github.com/go-critic/go-critic/issues/845 | ||
- ifElseChain | ||
- octalLiteral | ||
- whyNoLint | ||
gocyclo: | ||
min-complexity: 15 | ||
gofmt: | ||
rewrite-rules: | ||
- pattern: 'interface{}' | ||
replacement: 'any' | ||
goimports: | ||
local-prefixes: github.com/golangci/golangci-lint | ||
gomnd: | ||
# don't include the "operation" and "assign" | ||
checks: | ||
- argument | ||
- case | ||
- condition | ||
- return | ||
ignored-numbers: | ||
- '0' | ||
- '1' | ||
- '2' | ||
- '3' | ||
ignored-functions: | ||
- strings.SplitN | ||
govet: | ||
settings: | ||
printf: | ||
funcs: | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf | ||
enable: | ||
- nilness | ||
- shadow | ||
errorlint: | ||
asserts: false | ||
lll: | ||
line-length: 140 | ||
misspell: | ||
locale: US | ||
nolintlint: | ||
allow-unused: false # report any unused nolint directives | ||
require-explanation: false # don't require an explanation for nolint directives | ||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped | ||
revive: | ||
rules: | ||
- name: unexported-return | ||
disabled: true | ||
- name: unused-parameter | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
- depguard | ||
- dogsled | ||
- errcheck | ||
- errorlint | ||
- exportloopref | ||
- funlen | ||
- gocheckcompilerdirectives | ||
- gochecknoinits | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- gomnd | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- nakedret | ||
- noctx | ||
- nolintlint | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- whitespace | ||
|
||
# don't enable: | ||
# - asciicheck | ||
# - gochecknoglobals | ||
# - gocognit | ||
# - godot | ||
# - godox | ||
# - goerr113 | ||
# - nestif | ||
# - prealloc | ||
# - testpackage | ||
# - wsl | ||
|
||
issues: | ||
# Excluding configuration per-path, per-linter, per-text and per-source | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- gomnd | ||
|
||
- path: pkg/golinters/errcheck.go | ||
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" | ||
- path: pkg/commands/run.go | ||
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead" | ||
- path: pkg/commands/run.go | ||
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used." | ||
|
||
- path: pkg/golinters/gofumpt.go | ||
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." | ||
- path: pkg/golinters/staticcheck_common.go | ||
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead." | ||
- path: pkg/lint/lintersdb/manager.go | ||
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." | ||
- path: pkg/golinters/unused.go | ||
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" | ||
- path: test/(fix|linters)_test.go | ||
text: "string `gocritic.go` has 3 occurrences, make it a constant" | ||
|
||
run: | ||
timeout: 5m | ||
skip-dirs: | ||
- vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
GOBIN = $(GOPATH)/bin | ||
|
||
help: | ||
@echo "Please use 'make <target>' where <target> is one of the following:" | ||
|
||
@echo " docker-run to run the app with Docker (docker-compose)." | ||
@echo " run to run the app without Docker (go run)." | ||
@echo " build to build the app without Docker (go build)." | ||
|
||
@echo " pre-commit to run essential checks before you would make a commit." | ||
@echo " dev-dependencies to install all required Go dev dependencies" | ||
@echo " gomod to run tidy you go.mod file and load vendor files." | ||
@echo " update-mocks to update mocks." | ||
@echo " gci to apply gci." | ||
|
||
@echo " lint to perform linting." | ||
|
||
@echo " test run all unit tests." | ||
@echo " coverage-report open coverage report generated by make test." | ||
|
||
dev-dependencies: | $(GOBIN)/mockgen $(GOBIN)/gci $(GOBIN)/golangci-lint | ||
|
||
.PHONY: run-dev | ||
run-dev: | ||
HTTP_PORT=3000 DB_PATH=data/agg.db nodemon --watch './**/*.go' --signal SIGTERM --exec 'go' run cmd/main.go | ||
|
||
.PHONY: run | ||
run: | ||
CGO_ENABLED=0 GOOS=linux go run -mod=vendor ./cmd/main.go | ||
|
||
.PHONY: docker-run | ||
docker-run: | ||
docker-compose -f docker-compose.yaml build | ||
docker-compose -f docker-compose.yaml up | ||
|
||
.PHONY: build | ||
build: | ||
CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -installsuffix cgo -o lite-reader ./cmd/main.go | ||
|
||
pre-commit: gomod update-mocks lint test | ||
|
||
|
||
.PHONY: gomod | ||
gomod: | ||
@go mod tidy | ||
@go mod vendor | ||
|
||
$(GOBIN)/mockgen: | ||
@go install github.com/golang/mock/mockgen@v1.6.0 | ||
@$(MAKE) gomod | ||
|
||
update-mocks: | $(GOBIN)/mockgen | ||
@find ./internal/mocks ! -name 'definition.go' -type f -exec rm {} + | ||
GO111MODULE=on go generate -mod=vendor -tags=mocks ./... | ||
@$(MAKE) gci | ||
|
||
.PHONY: test | ||
test: | ||
@mkdir -p reports | ||
@go test -coverprofile=reports/codecoverage_all.cov ./... -mod=vendor -cover -race -p=4 | ||
@go tool cover -func=reports/codecoverage_all.cov > reports/functioncoverage.out | ||
@go tool cover -html=reports/codecoverage_all.cov -o reports/coverage.html | ||
@echo "View report at $(PWD)/reports/coverage.html" | ||
@tail -n 1 reports/functioncoverage.out | ||
|
||
.PHONY: coverage-report | ||
coverage-report: | ||
@open reports/coverage.html | ||
|
||
$(GOBIN)/gci: | ||
@go install github.com/daixiang0/gci@v0.3.3 | ||
@$(MAKE) gomod | ||
|
||
gci: | $(GOBIN)/gci | ||
@gci write --Section Standard --Section Default --Section "Prefix(github.com/cubny/lite-reader)" $(shell ls -d $(PWD)/*/ | grep -v vendor) | ||
|
||
$(GOBIN)/golangci-lint: | ||
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.56.1 | ||
|
||
.PHONY: lint | ||
lint: | $(GOBIN)/golangci-lint | ||
golangci-lint run -v | ||
|
||
.PHONY: ci-run | ||
ci-run: | ||
docker-compose build | ||
docker-compose up | ||
|
||
.PHONY: docs | ||
docs: | ||
docker run -v $(CURDIR):/local -w /local quay.io/goswagger/swagger generate spec -o ./docs/swagger.json | ||
docker run -v $(CURDIR):/local -w /local quay.io/goswagger/swagger generate spec -o ./docs/swagger.yaml |
Oops, something went wrong.