-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from guggero/build-improvement
Add Makefile, use golangci-lint, move to GitHub actions
- Loading branch information
Showing
46 changed files
with
467 additions
and
551 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,88 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
env: | ||
GO_VERSION: 1.16.x | ||
|
||
jobs: | ||
######################## | ||
# compilation check | ||
######################## | ||
rpc-check: | ||
name: RPC and mobile compilation check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: git checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: setup go ${{ env.GO_VERSION }} | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '${{ env.GO_VERSION }}' | ||
|
||
- name: run check | ||
run: make build | ||
|
||
######################## | ||
# lint code | ||
######################## | ||
lint: | ||
name: lint code | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: git checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Fetch all history for linter | ||
run: git fetch --prune --unshallow | ||
|
||
- name: setup go ${{ env.GO_VERSION }} | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '${{ env.GO_VERSION }}' | ||
|
||
- name: lint | ||
run: make lint | ||
|
||
######################## | ||
# run unit tests | ||
######################## | ||
unit-test: | ||
name: run unit tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
# Allow other tests in the matrix to continue if one fails. | ||
fail-fast: false | ||
matrix: | ||
unit_type: | ||
- unit-cover | ||
- unit-race | ||
steps: | ||
- name: git checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: setup go ${{ env.GO_VERSION }} | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '${{ env.GO_VERSION }}' | ||
|
||
- name: run ${{ matrix.unit_type }} | ||
run: make ${{ matrix.unit_type }} | ||
|
||
- name: Send coverage | ||
uses: shogo82148/actions-goveralls@v1 | ||
if: matrix.unit_type == 'unit-cover' | ||
with: | ||
path-to-profile: coverage.txt | ||
parallel: true |
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 |
---|---|---|
|
@@ -27,4 +27,4 @@ vendor/ | |
breakpoints.txt | ||
|
||
# coverage output | ||
profile.cov | ||
coverage.txt |
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,50 @@ | ||
run: | ||
# timeout for analysis | ||
deadline: 10m | ||
|
||
linters-settings: | ||
govet: | ||
# Don't report about shadowed variables | ||
check-shadowing: false | ||
gofmt: | ||
# simplify code: gofmt with `-s` option, true by default | ||
simplify: true | ||
maligned: | ||
suggest-new: true | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
# Global variables are used in many places throughout the code base. | ||
- gochecknoglobals | ||
|
||
# Some lines are over 80 characters on purpose and we don't want to make them | ||
# even longer by marking them as 'nolint'. | ||
- lll | ||
|
||
# We have long functions, especially in tests. Moving or renaming those would | ||
# trigger funlen problems that we may not want to solve at that time. | ||
- funlen | ||
|
||
# Disable for now as we haven't yet tuned the sensitivity to our codebase | ||
# yet. Enabling by default for example, would also force new contributors to | ||
# potentially extensively refactor code, when they want to smaller change to | ||
# land. | ||
- gocyclo | ||
|
||
# Init functions are used by loggers throughout the codebase. | ||
- gochecknoinits | ||
|
||
issues: | ||
exclude-rules: | ||
# Exclude gosec from running for tests so that tests with weak randomness | ||
# (math/rand) will pass the linter. | ||
- path: _test\.go | ||
linters: | ||
- gosec | ||
- errcheck | ||
- dupl | ||
|
||
# Instances of table driven tests that don't pre-allocate shouldn't | ||
# trigger the linter. | ||
- prealloc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
PKG := github.com/lightninglabs/neutrino | ||
|
||
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint | ||
GOACC_PKG := github.com/ory/go-acc | ||
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports | ||
|
||
GO_BIN := ${GOPATH}/bin | ||
LINT_BIN := $(GO_BIN)/golangci-lint | ||
GOACC_BIN := $(GO_BIN)/go-acc | ||
|
||
LINT_COMMIT := v1.18.0 | ||
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5 | ||
|
||
DEPGET := cd /tmp && GO111MODULE=on go get -v | ||
GOBUILD := GO111MODULE=on go build -v | ||
GOINSTALL := GO111MODULE=on go install -v | ||
GOTEST := GO111MODULE=on go test | ||
|
||
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)' | ||
GOLIST_COVER := $$(go list -deps $(PKG)/... | grep '$(PKG)') | ||
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*") | ||
|
||
RM := rm -f | ||
CP := cp | ||
MAKE := make | ||
XARGS := xargs -L 1 | ||
|
||
# Linting uses a lot of memory, so keep it under control by limiting the number | ||
# of workers if requested. | ||
ifneq ($(workers),) | ||
LINT_WORKERS = --concurrency=$(workers) | ||
endif | ||
|
||
LINT = $(LINT_BIN) run -v $(LINT_WORKERS) | ||
|
||
GREEN := "\\033[0;32m" | ||
NC := "\\033[0m" | ||
define print | ||
echo $(GREEN)$1$(NC) | ||
endef | ||
|
||
default: build | ||
|
||
all: build check | ||
|
||
# ============ | ||
# DEPENDENCIES | ||
# ============ | ||
|
||
$(LINT_BIN): | ||
@$(call print, "Fetching linter") | ||
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) | ||
|
||
$(GOACC_BIN): | ||
@$(call print, "Fetching go-acc") | ||
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT) | ||
|
||
goimports: | ||
@$(call print, "Installing goimports.") | ||
$(DEPGET) $(GOIMPORTS_PKG) | ||
|
||
# ============ | ||
# INSTALLATION | ||
# ============ | ||
|
||
build: | ||
@$(call print, "Compiling neutrino.") | ||
$(GOBUILD) $(PKG)/... | ||
|
||
# ======= | ||
# TESTING | ||
# ======= | ||
|
||
check: unit | ||
|
||
unit: | ||
@$(call print, "Running unit tests.") | ||
$(GOLIST) | $(XARGS) env $(GOTEST) | ||
|
||
unit-cover: $(GOACC_BIN) | ||
@$(call print, "Running unit coverage tests.") | ||
$(GOACC_BIN) $(GOLIST_COVER) | ||
|
||
unit-race: | ||
@$(call print, "Running unit race tests.") | ||
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race | ||
|
||
# ========= | ||
# UTILITIES | ||
# ========= | ||
|
||
fmt: goimports | ||
@$(call print, "Fixing imports.") | ||
goimports -w $(GOFILES_NOVENDOR) | ||
@$(call print, "Formatting source.") | ||
gofmt -l -w -s $(GOFILES_NOVENDOR) | ||
|
||
lint: $(LINT_BIN) | ||
@$(call print, "Linting source.") | ||
$(LINT) | ||
|
||
clean: | ||
@$(call print, "Cleaning source.$(NC)") | ||
$(RM) coverage.txt | ||
|
||
.PHONY: all \ | ||
default \ | ||
build \ | ||
check \ | ||
unit \ | ||
unit-cover \ | ||
unit-race \ | ||
fmt \ | ||
lint \ | ||
clean |
Oops, something went wrong.