Skip to content

Commit bdc5dcc

Browse files
Add Makefile, golangci-lint config and CI
Introduce a Makefile with a check target that runs the unit tests with the race detector, plus golangci and golangci-fix targets that install a pinned golangci-lint (v2.12.2) and lint the module. The linter is installed from the version-tagged install script rather than master, whose checksum handling currently mismatches release SBOM artifacts. Add a .golangci.yml enabling the linters we care about (gosec, govet, misspell, revive, staticcheck, unused) with gofmt/goimports, and a GitHub Actions workflow that runs make check and make golangci using the Go version from go.mod. Remove the obsolete Travis configuration and ignore the locally installed golangci-lint binary. Signed-off-by: Antonin Bas <antonin.bas@broadcom.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4c85e5b commit bdc5dcc

5 files changed

Lines changed: 121 additions & 11 deletions

File tree

.github/workflows/test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
name: Unit tests
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out code
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Go
14+
uses: actions/setup-go@v5
15+
with:
16+
go-version-file: go.mod
17+
18+
- name: Run unit tests
19+
run: make check
20+
21+
golangci-lint:
22+
name: Lint
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Check out code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Go
29+
uses: actions/setup-go@v5
30+
with:
31+
go-version-file: go.mod
32+
33+
- name: Run golangci-lint
34+
run: make golangci

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ _testmain.go
2121

2222
*.exe
2323
*.test
24+
25+
# golangci-lint binary installed by the Makefile
26+
/.golangci-bin/

.golangci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# golangci-lint configuration used for CI.
2+
version: "2"
3+
run:
4+
tests: true
5+
timeout: 15m
6+
linters:
7+
default: none
8+
enable:
9+
- gosec
10+
- govet
11+
- misspell
12+
- revive
13+
- staticcheck
14+
- unused
15+
settings:
16+
gosec:
17+
excludes:
18+
# G115 reports a lot of integer-conversion false positives and is not
19+
# accurate enough yet (see https://github.com/securego/gosec/issues/1187).
20+
- G115 # Potential integer overflow when converting between integer types
21+
revive:
22+
confidence: 0.8
23+
severity: warning
24+
rules:
25+
- name: unreachable-code
26+
- name: errorf
27+
- name: range
28+
- name: superfluous-else
29+
- name: var-declaration
30+
- name: duplicated-imports
31+
exclusions:
32+
presets:
33+
- legacy
34+
- common-false-positives
35+
formatters:
36+
enable:
37+
- gofmt
38+
- goimports
39+
settings:
40+
goimports:
41+
local-prefixes:
42+
- gopkg.in/natefinch/lumberjack.v2
43+
44+
issues:
45+
max-issues-per-linter: 0
46+
max-same-issues: 0

.travis.yml

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

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SHELL := /bin/bash
2+
3+
GO ?= go
4+
5+
# Arguments to pass to the "go test" invocation.
6+
# Example: make check TEST_ARGS="-run ^TestMaxAge$"
7+
TEST_ARGS ?=
8+
9+
GOLANGCI_LINT_VERSION := v2.12.2
10+
GOLANGCI_LINT_BINDIR := $(CURDIR)/.golangci-bin
11+
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION)/golangci-lint
12+
13+
.PHONY: all
14+
all: check
15+
16+
.PHONY: check
17+
check:
18+
@echo "===> Running unit tests <==="
19+
@CGO_ENABLED=1 $(GO) test $(TEST_ARGS) -race ./...
20+
21+
$(GOLANGCI_LINT_BIN):
22+
@echo "===> Installing golangci-lint <==="
23+
@rm -rf $(GOLANGCI_LINT_BINDIR)/* # remove old versions
24+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh | sh -s -- -b $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION) $(GOLANGCI_LINT_VERSION)
25+
26+
.PHONY: golangci
27+
golangci: $(GOLANGCI_LINT_BIN)
28+
@echo "===> Running golangci-lint <==="
29+
@$(GOLANGCI_LINT_BIN) run ./...
30+
31+
.PHONY: golangci-fix
32+
golangci-fix: $(GOLANGCI_LINT_BIN)
33+
@echo "===> Running golangci-lint --fix <==="
34+
@$(GOLANGCI_LINT_BIN) run --fix ./...
35+
36+
.PHONY: clean
37+
clean:
38+
@rm -rf $(GOLANGCI_LINT_BINDIR)

0 commit comments

Comments
 (0)