Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 93 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,104 @@ name: CI

on:
push:
branches: [ master, main ]
branches: [master, main]
pull_request:
branches: [ master, main ]
branches: [master, main]

permissions:
contents: read

env:
GOIMPORTS_VERSION: v0.49.0
GOLANGCI_LINT_VERSION: v2.13.2
GOVULNCHECK_VERSION: v1.7.0

jobs:
test:
name: Test (Go ${{ matrix.go-version }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
go-version: ['1.21', '1.22', '1.23']

go-version: ["1.23.x", stable]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: go.sum
- run: go test ./... -count=1
- run: go build ./...

quality:
name: Format and lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: stable
cache-dependency-path: go.sum
- name: Install pinned tools
run: |
go install "golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION}"
go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}"
- run: make fmt-check
- run: make lint
- name: Check module metadata
run: go mod tidy -diff

race:
name: Race detector
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-

- name: Install tools
run: |
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Format
run: make fmt

- name: Lint
run: make lint

- name: Test
run: make test

- name: Build
run: go build ./...
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: stable
cache-dependency-path: go.sum
- run: make test-race

vulnerability:
name: Vulnerability scan
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: stable
cache-dependency-path: go.sum
- name: Install govulncheck
run: go install "golang.org/x/vuln/cmd/govulncheck@${GOVULNCHECK_VERSION}"
- name: Run govulncheck
shell: bash
run: |
for attempt in 1 2 3; do
if govulncheck ./...; then
exit 0
else
status=$?
fi

if [[ ${status} -eq 3 ]]; then
exit "${status}"
fi

if [[ ${status} -ne 1 ]]; then
exit "${status}"
fi

if [[ ${attempt} -eq 3 ]]; then
exit "${status}"
fi

if [[ ${attempt} -eq 1 ]]; then
delay=10
else
delay=30
fi

echo "::warning::govulncheck failed with an operational error (exit ${status}); retrying in ${delay}s"
sleep "${delay}"
done
43 changes: 0 additions & 43 deletions .github/workflows/static-analysis.yml

This file was deleted.

141 changes: 77 additions & 64 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,18 @@
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
govet:
enable:
- shadow
- fieldalignment
gocyclo:
min-complexity: 15
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/ziflex/dbx
gocritic:
enabled-tags:
- diagnostic
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
depguard:
rules:
main:
deny:
- pkg: "unsafe"
desc: "unsafe package should not be used"

version: "2"
run:
issues-exit-code: 1
linters:
disable-all: true
default: none
enable:
- bodyclose
- depguard
- dupl
- errcheck
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -61,28 +23,79 @@ linters:
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- lll
- govet
- gocritic
exclude:
# Exclude some staticcheck messages
- "SA1029:" # should not use built-in type string as key for value

run:
timeout: 5m
issues-exit-code: 1
settings:
depguard:
rules:
main:
deny:
- pkg: unsafe
desc: unsafe package should not be used
dupl:
threshold: 100
errcheck:
check-type-assertions: true
check-blank: true
goconst:
min-len: 2
min-occurrences: 2
gocritic:
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
enabled-tags:
- diagnostic
- performance
- style
gocyclo:
min-complexity: 15
govet:
enable:
- shadow
- fieldalignment
lll:
line-length: 140
misspell:
locale: US
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- gocritic
- gocyclo
- gosec
- govet
- lll
path: _test\.go
- path: (.+)\.go$
text: 'SA1029:'
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/ziflex/dbx
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
default: fmt lint test
default: fmt-check lint test

test:
go test ./...

lint:
go vet ./... && \
staticcheck -tests=false ./...
golangci-lint run

fmt:
go fmt ./... && \
goimports -w .
goimports -w -local github.com/ziflex/dbx .

fmt-check:
@files="$$(gofmt -l .)"; if [ -n "$$files" ]; then echo "gofmt required for:"; echo "$$files"; exit 1; fi
@files="$$(goimports -l -local github.com/ziflex/dbx .)"; if [ -n "$$files" ]; then echo "goimports required for:"; echo "$$files"; exit 1; fi

test-race:
go test -race ./...
Loading