Skip to content

Commit 4bc2c99

Browse files
authored
Merge pull request #217 from guggero/build-improvement
Add Makefile, use golangci-lint, move to GitHub actions
2 parents e6974af + eb989f6 commit 4bc2c99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+467
-551
lines changed

.github/workflows/main.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "*"
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
env:
16+
GO_VERSION: 1.16.x
17+
18+
jobs:
19+
########################
20+
# compilation check
21+
########################
22+
rpc-check:
23+
name: RPC and mobile compilation check
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: git checkout
27+
uses: actions/checkout@v2
28+
29+
- name: setup go ${{ env.GO_VERSION }}
30+
uses: actions/setup-go@v2
31+
with:
32+
go-version: '${{ env.GO_VERSION }}'
33+
34+
- name: run check
35+
run: make build
36+
37+
########################
38+
# lint code
39+
########################
40+
lint:
41+
name: lint code
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: git checkout
45+
uses: actions/checkout@v2
46+
47+
- name: Fetch all history for linter
48+
run: git fetch --prune --unshallow
49+
50+
- name: setup go ${{ env.GO_VERSION }}
51+
uses: actions/setup-go@v2
52+
with:
53+
go-version: '${{ env.GO_VERSION }}'
54+
55+
- name: lint
56+
run: make lint
57+
58+
########################
59+
# run unit tests
60+
########################
61+
unit-test:
62+
name: run unit tests
63+
runs-on: ubuntu-latest
64+
strategy:
65+
# Allow other tests in the matrix to continue if one fails.
66+
fail-fast: false
67+
matrix:
68+
unit_type:
69+
- unit-cover
70+
- unit-race
71+
steps:
72+
- name: git checkout
73+
uses: actions/checkout@v2
74+
75+
- name: setup go ${{ env.GO_VERSION }}
76+
uses: actions/setup-go@v2
77+
with:
78+
go-version: '${{ env.GO_VERSION }}'
79+
80+
- name: run ${{ matrix.unit_type }}
81+
run: make ${{ matrix.unit_type }}
82+
83+
- name: Send coverage
84+
uses: shogo82148/actions-goveralls@v1
85+
if: matrix.unit_type == 'unit-cover'
86+
with:
87+
path-to-profile: coverage.txt
88+
parallel: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ vendor/
2727
breakpoints.txt
2828

2929
# coverage output
30-
profile.cov
30+
coverage.txt

.golangci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
run:
2+
# timeout for analysis
3+
deadline: 10m
4+
5+
linters-settings:
6+
govet:
7+
# Don't report about shadowed variables
8+
check-shadowing: false
9+
gofmt:
10+
# simplify code: gofmt with `-s` option, true by default
11+
simplify: true
12+
maligned:
13+
suggest-new: true
14+
15+
linters:
16+
enable-all: true
17+
disable:
18+
# Global variables are used in many places throughout the code base.
19+
- gochecknoglobals
20+
21+
# Some lines are over 80 characters on purpose and we don't want to make them
22+
# even longer by marking them as 'nolint'.
23+
- lll
24+
25+
# We have long functions, especially in tests. Moving or renaming those would
26+
# trigger funlen problems that we may not want to solve at that time.
27+
- funlen
28+
29+
# Disable for now as we haven't yet tuned the sensitivity to our codebase
30+
# yet. Enabling by default for example, would also force new contributors to
31+
# potentially extensively refactor code, when they want to smaller change to
32+
# land.
33+
- gocyclo
34+
35+
# Init functions are used by loggers throughout the codebase.
36+
- gochecknoinits
37+
38+
issues:
39+
exclude-rules:
40+
# Exclude gosec from running for tests so that tests with weak randomness
41+
# (math/rand) will pass the linter.
42+
- path: _test\.go
43+
linters:
44+
- gosec
45+
- errcheck
46+
- dupl
47+
48+
# Instances of table driven tests that don't pre-allocate shouldn't
49+
# trigger the linter.
50+
- prealloc

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

Makefile

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
PKG := github.com/lightninglabs/neutrino
2+
3+
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
4+
GOACC_PKG := github.com/ory/go-acc
5+
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
6+
7+
GO_BIN := ${GOPATH}/bin
8+
LINT_BIN := $(GO_BIN)/golangci-lint
9+
GOACC_BIN := $(GO_BIN)/go-acc
10+
11+
LINT_COMMIT := v1.18.0
12+
GOACC_COMMIT := ddc355013f90fea78d83d3a6c71f1d37ac07ecd5
13+
14+
DEPGET := cd /tmp && GO111MODULE=on go get -v
15+
GOBUILD := GO111MODULE=on go build -v
16+
GOINSTALL := GO111MODULE=on go install -v
17+
GOTEST := GO111MODULE=on go test
18+
19+
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'
20+
GOLIST_COVER := $$(go list -deps $(PKG)/... | grep '$(PKG)')
21+
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
22+
23+
RM := rm -f
24+
CP := cp
25+
MAKE := make
26+
XARGS := xargs -L 1
27+
28+
# Linting uses a lot of memory, so keep it under control by limiting the number
29+
# of workers if requested.
30+
ifneq ($(workers),)
31+
LINT_WORKERS = --concurrency=$(workers)
32+
endif
33+
34+
LINT = $(LINT_BIN) run -v $(LINT_WORKERS)
35+
36+
GREEN := "\\033[0;32m"
37+
NC := "\\033[0m"
38+
define print
39+
echo $(GREEN)$1$(NC)
40+
endef
41+
42+
default: build
43+
44+
all: build check
45+
46+
# ============
47+
# DEPENDENCIES
48+
# ============
49+
50+
$(LINT_BIN):
51+
@$(call print, "Fetching linter")
52+
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)
53+
54+
$(GOACC_BIN):
55+
@$(call print, "Fetching go-acc")
56+
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
57+
58+
goimports:
59+
@$(call print, "Installing goimports.")
60+
$(DEPGET) $(GOIMPORTS_PKG)
61+
62+
# ============
63+
# INSTALLATION
64+
# ============
65+
66+
build:
67+
@$(call print, "Compiling neutrino.")
68+
$(GOBUILD) $(PKG)/...
69+
70+
# =======
71+
# TESTING
72+
# =======
73+
74+
check: unit
75+
76+
unit:
77+
@$(call print, "Running unit tests.")
78+
$(GOLIST) | $(XARGS) env $(GOTEST)
79+
80+
unit-cover: $(GOACC_BIN)
81+
@$(call print, "Running unit coverage tests.")
82+
$(GOACC_BIN) $(GOLIST_COVER)
83+
84+
unit-race:
85+
@$(call print, "Running unit race tests.")
86+
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race
87+
88+
# =========
89+
# UTILITIES
90+
# =========
91+
92+
fmt: goimports
93+
@$(call print, "Fixing imports.")
94+
goimports -w $(GOFILES_NOVENDOR)
95+
@$(call print, "Formatting source.")
96+
gofmt -l -w -s $(GOFILES_NOVENDOR)
97+
98+
lint: $(LINT_BIN)
99+
@$(call print, "Linting source.")
100+
$(LINT)
101+
102+
clean:
103+
@$(call print, "Cleaning source.$(NC)")
104+
$(RM) coverage.txt
105+
106+
.PHONY: all \
107+
default \
108+
build \
109+
check \
110+
unit \
111+
unit-cover \
112+
unit-race \
113+
fmt \
114+
lint \
115+
clean

0 commit comments

Comments
 (0)