Skip to content

Commit e584461

Browse files
committed
Add building, linting, and testing to CI.
1 parent 4e602c7 commit e584461

4 files changed

Lines changed: 157 additions & 0 deletions

File tree

.github/workflows/golang.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: golang
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
test:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
go-version: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v3
17+
- name: setup-go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
cache: true
22+
cache-dependency-path: go.sum
23+
- name: go build
24+
run: go build -o ./bin/sql-migrate ./sql-migrate && ./bin/sql-migrate --help
25+
- name: go test
26+
run: go test ./...
27+
lint:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: checkout
31+
uses: actions/checkout@v3
32+
- name: setup-go
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: '1.20'
36+
cache: true
37+
cache-dependency-path: go.sum
38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@v3
40+
with:
41+
version: v1.52.2
42+
- name: go mod tidy
43+
run: go mod tidy
44+
- name: check for any changes
45+
run: >
46+
[[ $(git status --porcelain) == "" ]] || (echo "changes detected" && exit 1)

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55

66
/sql-migrate/test.db
77
/test.db
8+
.vscode/
9+
bin/

.golangci.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
linters-settings:
2+
gocritic:
3+
disabled-checks:
4+
- ifElseChain
5+
goimports:
6+
local-prefixes: github.com/rubenv/sql-migrate
7+
govet:
8+
enable-all: true
9+
disable:
10+
- fieldalignment
11+
depguard:
12+
list-type: blacklist
13+
include-go-root: true
14+
include-go-std-lib: true
15+
exhaustive:
16+
default-signifies-exhaustive: true
17+
nolintlint:
18+
allow-unused: false
19+
allow-leading-space: false
20+
allow-no-explanation:
21+
- depguard
22+
require-explanation: true
23+
require-specific: true
24+
revive:
25+
enable-all-rules: false
26+
rules:
27+
- name: atomic
28+
- name: blank-imports
29+
- name: bool-literal-in-expr
30+
- name: call-to-gc
31+
- name: constant-logical-expr
32+
- name: context-as-argument
33+
- name: context-keys-type
34+
- name: dot-imports
35+
- name: duplicated-imports
36+
- name: empty-block
37+
- name: empty-lines
38+
- name: error-naming
39+
- name: error-return
40+
- name: error-strings
41+
- name: errorf
42+
- name: exported
43+
- name: identical-branches
44+
- name: imports-blacklist
45+
- name: increment-decrement
46+
- name: indent-error-flow
47+
- name: modifies-parameter
48+
- name: modifies-value-receiver
49+
- name: package-comments
50+
- name: range
51+
- name: range-val-address
52+
- name: range-val-in-closure
53+
- name: receiver-naming
54+
- name: string-format
55+
- name: string-of-int
56+
- name: struct-tag
57+
- name: time-naming
58+
- name: unconditional-recursion
59+
- name: unexported-naming
60+
- name: unexported-return
61+
- name: superfluous-else
62+
- name: unreachable-code
63+
- name: var-declaration
64+
- name: waitgroup-by-value
65+
- name: unused-receiver
66+
- name: unnecessary-stmt
67+
- name: unused-parameter
68+
run:
69+
tests: true
70+
timeout: 1m
71+
linters:
72+
disable-all: true
73+
enable:
74+
- asciicheck
75+
- depguard
76+
- errcheck
77+
- exhaustive
78+
- gocritic
79+
- gofmt
80+
- gofumpt
81+
- goimports
82+
- govet
83+
- ineffassign
84+
- nolintlint
85+
- revive
86+
- staticcheck
87+
- typecheck
88+
- unused
89+
- whitespace
90+
- errorlint
91+
- gosimple
92+
- unparam
93+
issues:
94+
exclude:
95+
- 'declaration of "err" shadows declaration at' # Allow shadowing of `err` because it's so common
96+
- 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
97+
max-same-issues: 10000
98+
max-issues-per-linter: 10000

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: test lint build
2+
3+
test:
4+
go test ./...
5+
6+
lint:
7+
golangci-lint run --fix --config .golangci.yaml
8+
9+
build:
10+
mkdir -p bin
11+
go build -o ./bin/sql-migrate ./sql-migrate

0 commit comments

Comments
 (0)