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
14 changed files
with
327 additions
and
66 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,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
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,17 @@ | ||
on: push | ||
jobs: | ||
ci: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.19.0' | ||
- name: "Run CI" | ||
run: make --warn-undefined-variables --no-print-directory ci | ||
- name: "Upload coverage" | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: coverage | ||
path: coverage.* |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/build | ||
/coverage.* |
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 |
---|---|---|
@@ -1,28 +1,143 @@ | ||
run: | ||
deadline: "10m" | ||
timeout: "10m" | ||
output: | ||
uniq-by-line: false | ||
sort-results: true | ||
linters: | ||
disable-all: true | ||
enable: | ||
- "asciicheck" | ||
- "bidichk" | ||
- "bodyclose" | ||
- "deadcode" | ||
- "containedctx" | ||
- "contextcheck" | ||
# - "cyclop" # Redundant with gocyclo. | ||
# - "deadcode" # Replaced by unused. | ||
# - "decorder" # Maybe overkill. | ||
- "depguard" | ||
- "dogsled" | ||
- "dupl" | ||
- "durationcheck" | ||
- "errcheck" | ||
- "errchkjson" | ||
- "errname" | ||
- "errorlint" | ||
- "execinquery" | ||
- "exhaustive" | ||
# - "exhaustivestruct " # Replaced by exhaustruct. | ||
# - "exhaustruct" # Too many false positive, and not always relevant. | ||
- "exportloopref" | ||
- "forbidigo" | ||
- "forcetypeassert" | ||
# - "funlen" # It causes issues in table driven tests, and cyclomatic complexity is more relevant. | ||
# - "gci" # Redundant with goimports and grouper. | ||
# - "gochecknoglobals" # It's OK. | ||
# - "gochecknoinits" # It's OK. | ||
# - "gocognit" # Redundant with gocyclo. | ||
# - "goconst" # Too many false positive. | ||
# - "gocritic" # Must be disabled for Go 1.18. | ||
- "gocyclo" | ||
- "godot" | ||
# - "godox" # Should not be reported as error. | ||
# - "goerr113" # Not useful. | ||
- "gofmt" | ||
- "gofumpt" | ||
# - "goheader" # Not useful. | ||
- "goimports" | ||
- "golint" | ||
# - "golint" # Replaced by revive. | ||
# - "gomnd" # Too many false positive. | ||
# - "gomoddirectives" # Not useful. | ||
# - "gomodguard" # Redundant with depguard. | ||
- "goprintffuncname" | ||
- "gosec" | ||
- "gosimple" | ||
- "govet" | ||
- "grouper" | ||
# - "ifshort" # Deprecated. | ||
- "importas" | ||
- "ineffassign" | ||
- "megacheck" | ||
# - "interfacer" # Archived. | ||
# - "ireturn" # Too many false positive. | ||
# - "lll" # We don't use punch cards anymore. | ||
# - "maintidx" # Redundant with gocyclo. | ||
- "makezero" | ||
# - "maligned" # Replaced by govet 'fieldalignment'. | ||
- "misspell" | ||
- "nakedret" | ||
- "structcheck" | ||
- "nestif" | ||
- "nilerr" | ||
- "nilnil" | ||
# - "nlreturn" # Is that a good practice ? | ||
- "noctx" | ||
- "nolintlint" | ||
# - "nonamedreturns" # Named returns are OK. | ||
- "nosprintfhostport" | ||
# - "paralleltest" # Not useful. | ||
- "prealloc" | ||
- "predeclared" | ||
# - "promlinter" # Not useful. | ||
- "revive" | ||
- "rowserrcheck" | ||
# - "scopelint" # Replaced by exportloopref. | ||
- "sqlclosecheck" | ||
- "staticcheck" | ||
#- "structcheck" # Replaced by unused. | ||
- "stylecheck" | ||
#- "tagliatelle" # Not useful. | ||
- "tenv" | ||
# - "testpackage" # Not useful. | ||
- "thelper" | ||
# - "tparallel" # Not useful. | ||
- "typecheck" | ||
- "unconvert" | ||
- "unparam" | ||
- "varcheck" | ||
- "unused" | ||
- "usestdlibvars" | ||
# - "varcheck" # Replaced by unused. | ||
# - "varnamelen" # Maybe overkill. | ||
- "wastedassign" | ||
# - "whitespace" # Not useful. | ||
- "wrapcheck" | ||
# - "wsl" # Not useful. | ||
linters-settings: | ||
depguard: | ||
list-type: blacklist | ||
include-go-root: true | ||
packages-with-error-message: | ||
- reflect: "shouldn't be used by most application" | ||
- unsafe: "it's not safe" | ||
gocritic: | ||
enabled-tags: | ||
- experimental | ||
- diagnostic | ||
- opinionated | ||
- performance | ||
- style | ||
gocyclo: | ||
min-complexity: 10 | ||
gofumpt: | ||
extra-rules: true | ||
gosimple: | ||
checks: [ "all" ] | ||
govet: | ||
enable-all: true | ||
disable: | ||
- fieldalignment # Too many false positive. | ||
grouper: | ||
import-require-single-import: true | ||
import-require-grouping: true | ||
nolintlint: | ||
allow-unused: false | ||
allow-no-explanation: | ||
- errcheck | ||
- misspell | ||
require-explanation: true | ||
require-specific: true | ||
staticcheck: | ||
checks: [ "all" ] | ||
stylecheck: | ||
checks: [ "all" ] | ||
issues: | ||
exclude-use-default: false | ||
max-per-linter: 0 | ||
max-issues-per-linter: 0 | ||
max-same-issues: 0 |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,30 +1 @@ | ||
export GO111MODULE=on | ||
|
||
build: build/geohash | ||
|
||
build/geohash: | ||
go build -o build/geohash ./cmd/geohash | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: lint | ||
lint: \ | ||
golangci-lint | ||
|
||
GOLANGCI_LINT_VERSION=v1.17.0 | ||
GOLANGCI_LINT_DIR=$(shell go env GOPATH)/pkg/golangci-lint/$(GOLANGCI_LINT_VERSION) | ||
$(GOLANGCI_LINT_DIR): | ||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOLANGCI_LINT_DIR) $(GOLANGCI_LINT_VERSION) | ||
|
||
.PHONY: install-golangci-lint | ||
install-golangci-lint: $(GOLANGCI_LINT_DIR) | ||
|
||
.PHONY: golangci-lint | ||
golangci-lint: install-golangci-lint | ||
$(GOLANGCI_LINT_DIR)/golangci-lint run | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf build | ||
include Makefile-common.mk |
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,150 @@ | ||
.DEFAULT_GOAL=noop | ||
.DELETE_ON_ERROR: | ||
|
||
.PHONY: noop | ||
noop: | ||
|
||
CI?=false | ||
|
||
ENSURE_COMMAND=@ which $(1) > /dev/null || (echo "Install the '$(1)' command. $(2)"; exit 1) | ||
|
||
VERSION?=$(shell (git describe --tags --exact-match 2> /dev/null || git rev-parse HEAD) | sed "s/^v//") | ||
.PHONY: version | ||
version: | ||
@echo $(VERSION) | ||
|
||
GO_BUILD_DIR=build | ||
.PHONY: build | ||
build: | ||
ifneq ($(wildcard ./cmd/*),) | ||
mkdir -p $(GO_BUILD_DIR) | ||
go build -v -ldflags="-s -w -X main.version=$(VERSION)" -o $(GO_BUILD_DIR) ./cmd/... | ||
endif | ||
|
||
.PHONY: test | ||
test: | ||
go test -v -cover -coverprofile=coverage.out ./... | ||
go tool cover -func=coverage.out -o=coverage.txt | ||
cat coverage.txt | ||
go tool cover -html=coverage.out -o=coverage.html | ||
|
||
.PHONY: generate | ||
generate:: | ||
go generate -v ./... | ||
|
||
.PHONY: lint | ||
lint: | ||
$(MAKE) golangci-lint | ||
$(MAKE) lint-rules | ||
|
||
GOLANGCI_LINT_VERSION=v1.48.0 | ||
GOLANGCI_LINT_DIR=$(shell go env GOPATH)/pkg/golangci-lint/$(GOLANGCI_LINT_VERSION) | ||
GOLANGCI_LINT_BIN=$(GOLANGCI_LINT_DIR)/golangci-lint | ||
|
||
$(GOLANGCI_LINT_BIN): | ||
curl -vfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCI_LINT_DIR) $(GOLANGCI_LINT_VERSION) | ||
|
||
.PHONY: install-golangci-lint | ||
install-golangci-lint: $(GOLANGCI_LINT_BIN) | ||
|
||
GOLANGCI_LINT_RUN=$(GOLANGCI_LINT_BIN) -v run | ||
.PHONY: golangci-lint | ||
golangci-lint: install-golangci-lint | ||
ifeq ($(CI),true) | ||
$(GOLANGCI_LINT_RUN) | ||
else | ||
# Fix errors if possible. | ||
$(GOLANGCI_LINT_RUN) --fix | ||
endif | ||
|
||
.PHONY: golangci-lint-cache-clean | ||
golangci-lint-cache-clean: install-golangci-lint | ||
$(GOLANGCI_LINT_BIN) cache clean | ||
|
||
.PHONY: ensure-command-pcregrep | ||
ensure-command-pcregrep: | ||
$(call ENSURE_COMMAND,pcregrep,) | ||
|
||
.PHONY: lint-rules | ||
lint-rules: ensure-command-pcregrep | ||
# Disallowed files. | ||
find . -name ".DS_Store" | xargs -I {} sh -c 'echo {} && false' | ||
|
||
# Mandatory files. | ||
[ -e .gitignore ] | ||
[ -e README.md ] | ||
[ -e .github/workflows/ci.yml ] | ||
[ -e go.mod ] | ||
[ -e .golangci.yml ] | ||
[ -e Makefile ] | ||
[ -e Makefile-common.mk ] | ||
|
||
# Don't use upper case letter in file and directory name. | ||
# The convention for separator in name is: | ||
# - file: "_" | ||
# - directory in "/cmd": "-" | ||
# - other directory: shouldn't be separated | ||
! find . -name "*.go" | pcregrep "[[:upper:]]" | ||
|
||
# Don't export type/function/variable/constant in main package/test. | ||
! pcregrep -rnM --include=".+\.go$$" --exclude=".+_test\.go$$" "^package main\n(.*\n)*(type|func|var|const) [[:upper:]]" . | ||
! pcregrep -rnM --include=".+\.go$$" --exclude=".+_test\.go$$" "^package main\n(.*\n)*(var|const) \(\n((\t.*)?\n)*\t[[:upper:]]" . | ||
! pcregrep -rn --include=".+_test\.go$$" "^(type|var|const) [[:upper:]]" . | ||
! pcregrep -rnM --include=".+_test\.go$$" "^(var|const) \(\n((\t.*)?\n)*\t[[:upper:]]" . | ||
! pcregrep -rn --include=".+_test\.go$$" "^func [[:upper:]]" . | pcregrep -v ":func (Test.*\(t \*testing\.T\)|Benchmark.*\(b \*testing\.B\)|Example.*\(\)) {" | ||
|
||
# Don't declare a var block inside a function. | ||
! pcregrep -rn --include=".+\.go$$" "^\t+var \($$" . | ||
|
||
# Use Go 1.19 in go.mod. | ||
! pcregrep -n "^go " go.mod | pcregrep -v "go 1.19$$" | ||
|
||
.PHONY: mod-update | ||
mod-update: | ||
go get -v -u all | ||
$(MAKE) mod-tidy | ||
|
||
.PHONY: mod-tidy | ||
mod-tidy: | ||
go mod tidy -v | ||
|
||
.PHONY: git-latest-release | ||
git-latest-release: | ||
@git tag --list --sort=v:refname --format="%(refname:short) => %(creatordate:short)" | tail -n 1 | ||
|
||
.PHONY: clean | ||
clean: | ||
git clean -fdX | ||
go clean -cache -testcache | ||
$(MAKE) golangci-lint-cache-clean | ||
|
||
ifeq ($(CI),true) | ||
|
||
CI_LOG_GROUP_START=@echo "::group::$(1)" | ||
CI_LOG_GROUP_END=@echo "::endgroup::" | ||
|
||
.PHONY: ci | ||
ci: | ||
$(call CI_LOG_GROUP_START,apt) | ||
$(MAKE) ci-apt | ||
$(call CI_LOG_GROUP_END) | ||
|
||
$(call CI_LOG_GROUP_START,build) | ||
$(MAKE) build | ||
$(call CI_LOG_GROUP_END) | ||
|
||
$(call CI_LOG_GROUP_START,test) | ||
$(MAKE) test | ||
$(call CI_LOG_GROUP_END) | ||
|
||
$(call CI_LOG_GROUP_START,lint) | ||
$(MAKE) lint | ||
$(call CI_LOG_GROUP_END) | ||
|
||
CI_APT_PACKAGES:=pcregrep | ||
.PHONY: ci-apt | ||
ci-apt: | ||
sudo apt-get update | ||
sudo apt-get install $(CI_APT_PACKAGES) | ||
|
||
endif # CI end |
Oops, something went wrong.