Skip to content

Commit 48110a9

Browse files
Merge pull request #2 from muzzammilshahid/ci-and-linter
Add basic CI and linting rules
2 parents 7266bac + 4aa649f commit 48110a9

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-0
lines changed

.github/workflows/main.yaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: workerpool CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Setup go
19+
uses: actions/setup-go@v3
20+
with:
21+
go-version-file: 'go.mod'
22+
cache: true
23+
- run: go version
24+
25+
- name: Pull in all Go dependencies
26+
run: |
27+
go mod vendor
28+
29+
- name: golangci-lint
30+
uses: golangci/golangci-lint-action@v3
31+
with:
32+
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest`
33+
version: latest
34+
# skip all additional steps
35+
skip-pkg-cache: true
36+
skip-build-cache: true
37+
38+
- name: Check that code is formatted via go fmt tool
39+
run: |
40+
if [ "$(gofmt -s -l . | grep -v vendor | wc -l)" -gt 0 ]; then
41+
exit 1;
42+
fi
43+
44+
- name: Check that go modules are in synced state
45+
run: |
46+
go mod tidy -v
47+
if [ -n "$(git status --porcelain go.mod go.sum)" ]; then
48+
echo "Go modules are dirty or not in a good state. Please run go mod tidy"
49+
exit 1;
50+
fi
51+
52+
- name: Run unit tests
53+
run: |
54+
make test

.golangci.yml

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
run:
2+
# default concurrency is a available CPU number
3+
#concurrency: 4
4+
5+
# timeout for analysis, e.g. 30s, 5m, default is 1m
6+
timeout: 5m
7+
8+
# exit code when at least one issue was found, default is 1
9+
# issues-exit-code: 1
10+
11+
# include test files or not, default is true
12+
tests: true
13+
14+
# list of build tags, all linters use it. Default is empty list.
15+
#build-tags:
16+
# - mytag
17+
18+
# which dirs to skip: issues from them won't be reported;
19+
# can use regexp here: generated.*, regexp is applied on full path;
20+
# default value is empty list, but default dirs are skipped independently
21+
# from this option's value (see skip-dirs-use-default).
22+
# "/" will be replaced by current OS file path separator to properly work
23+
# on Windows.
24+
#skip-dirs:
25+
# - src/external_libs
26+
# - autogenerated_by_my_lib
27+
28+
# default is true. Enables skipping of directories:
29+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
30+
skip-dirs-use-default: true
31+
32+
# which files to skip: they will be analyzed, but issues from them
33+
# won't be reported. Default value is empty list, but there is
34+
# no need to include all autogenerated files, we confidently recognize
35+
# autogenerated files. If it's not please let us know.
36+
# "/" will be replaced by current OS file path separator to properly work
37+
# on Windows.
38+
# skip-files:
39+
# - export_test.go
40+
41+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
42+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
43+
# automatic updating of go.mod described above. Instead, it fails when any changes
44+
# to go.mod are needed. This setting is most useful to check that go.mod does
45+
# not need updates, such as in a continuous integration and testing system.
46+
# If invoked with -mod=vendor, the go command assumes that the vendor
47+
# directory holds the correct copies of dependencies and ignores
48+
# the dependency descriptions in go.mod.
49+
# modules-download-mode: readonly|release|vendor
50+
51+
# Allow multiple parallel golangci-lint instances running.
52+
# If false (default) - golangci-lint acquires file lock on start.
53+
allow-parallel-runners: false
54+
55+
# output configuration options
56+
output:
57+
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
58+
# format: colored-line-number
59+
60+
# print lines of code with issue, default is true
61+
# print-issued-lines: true
62+
63+
# print linter name in the end of issue text, default is true
64+
# print-linter-name: true
65+
66+
# make issues output unique by line, default is true
67+
# uniq-by-line: true
68+
69+
# add a prefix to the output file references; default is no prefix
70+
path-prefix: ""
71+
72+
# all available settings of specific linters
73+
# @see all available linters and options here: https://golangci-lint.run/usage/linters/
74+
linters-settings:
75+
gci:
76+
# Section configuration to compare against.
77+
# Section names are case-insensitive and may contain parameters in ().
78+
# The default order of sections is `standard > default > custom > blank > dot`,
79+
# If `custom-order` is `true`, it follows the order of `sections` option.
80+
# Default: ["standard", "default"]
81+
sections:
82+
- standard # Standard section: captures all standard packages.
83+
- default # Default section: contains all imports that could not be matched to another section type.
84+
- prefix(github.com/xconnio) # Custom section: groups all imports with the specified Prefix.
85+
# Skip generated files.
86+
# Default: true
87+
#skip-generated: false
88+
# Enable custom order of sections.
89+
# If `true`, make the section order the same as the order of `sections`.
90+
# Default: false
91+
custom-order: true
92+
93+
linters:
94+
# enable the following linters
95+
enable:
96+
- errcheck
97+
- gosimple
98+
- govet
99+
- ineffassign
100+
- misspell
101+
- typecheck
102+
- asciicheck
103+
- bidichk
104+
- contextcheck
105+
- decorder
106+
- durationcheck
107+
- errorlint
108+
- execinquery
109+
- exportloopref
110+
- gci
111+
- gochecknoglobals
112+
- goconst
113+
- godot
114+
- gofmt
115+
#- gomnd
116+
- gosec
117+
- nakedret
118+
- nilerr
119+
- testpackage
120+
- unused
121+
- unconvert
122+
- unparam
123+
- lll
124+
# disable everything else
125+
disable-all: true
126+
127+
issues:
128+
# List of regexps of issue texts to exclude, empty list by default.
129+
# But independently from this option we use default exclude patterns,
130+
# it can be disabled by `exclude-use-default: false`. To list all
131+
# excluded by default patterns execute `golangci-lint run --help`
132+
# exclude:
133+
# - abcdef
134+
135+
# Excluding configuration per-path, per-linter, per-text and per-source
136+
exclude-rules:
137+
# Exclude some linters from running on tests files.
138+
- path: _test\.go
139+
linters:
140+
- gocyclo
141+
- errcheck
142+
- dupl
143+
- gosec
144+
145+
- path: export.*_test\.go
146+
linters:
147+
- testpackage
148+
- gochecknoglobals
149+
150+
# benchmarks are little noisy
151+
- path: benchmarks/*
152+
linters:
153+
- unparam
154+
- unused
155+
156+
# disable noise from errcheck
157+
- linters:
158+
- errcheck
159+
text: ".AbortWithReason"
160+
161+
# Independently from option `exclude` we use default exclude patterns,
162+
# it can be disabled by this option. To list all
163+
# excluded by default patterns execute `golangci-lint run --help`.
164+
# Default value for this option is true.
165+
exclude-use-default: true
166+
167+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
168+
max-per-linter: 0
169+
170+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
171+
max-same-issues: 0
172+
173+
# Show only new issues: if there are unstaged changes or untracked files,
174+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
175+
# It's a super-useful option for integration of golangci-lint into existing
176+
# large codebase. It's not practical to fix all existing issues at the moment
177+
# of integration: much better don't allow issues in new code.
178+
# Default is false.
179+
new: false

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
lint:
2+
golangci-lint run
3+
14
test:
25
go test ./...
36

0 commit comments

Comments
 (0)