Skip to content

Commit 196f7bd

Browse files
cussroxvearutop
andauthored
Update CI and linter, fix issues (#23)
Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
1 parent a3d8329 commit 196f7bd

File tree

11 files changed

+119
-129
lines changed

11 files changed

+119
-129
lines changed

.github/workflows/cloc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717
with:
1818
path: pr
1919
- name: Checkout base code
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121
with:
2222
ref: ${{ github.event.pull_request.base.sha }}
2323
path: base

.github/workflows/golangci-lint.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
name: golangci-lint
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/setup-go@v3
22+
- uses: actions/setup-go@v5
2323
with:
24-
go-version: 1.20.x
25-
- uses: actions/checkout@v2
24+
go-version: stable
25+
- uses: actions/checkout@v4
2626
- name: golangci-lint
27-
uses: golangci/golangci-lint-action@v3.4.0
27+
uses: golangci/golangci-lint-action@v8.0.0
2828
with:
2929
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
30-
version: v1.51.1
30+
version: v2.4.0
3131

3232
# Optional: working directory, useful for monorepos
3333
# working-directory: somedir

.github/workflows/gorelease.yml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,19 @@ concurrency:
99
cancel-in-progress: true
1010

1111
env:
12-
GO_VERSION: 1.20.x
12+
GO_VERSION: stable
1313
jobs:
1414
gorelease:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Install Go stable
18-
if: env.GO_VERSION != 'tip'
19-
uses: actions/setup-go@v4
17+
- name: Install Go
18+
uses: actions/setup-go@v5
2019
with:
2120
go-version: ${{ env.GO_VERSION }}
22-
- name: Install Go tip
23-
if: env.GO_VERSION == 'tip'
24-
run: |
25-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
26-
ls -lah gotip.tar.gz
27-
mkdir -p ~/sdk/gotip
28-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
29-
~/sdk/gotip/bin/go version
30-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
3121
- name: Checkout code
32-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
3323
- name: Gorelease cache
34-
uses: actions/cache@v3
24+
uses: actions/cache@v4
3525
with:
3626
path: |
3727
~/go/bin/gorelease

.github/workflows/release-assets.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,18 @@ on:
88
- created
99
env:
1010
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11-
GO_VERSION: 1.20.x
11+
GO_VERSION: stable
1212
jobs:
1313
build:
1414
name: Upload Release Assets
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Install Go stable
18-
if: env.GO_VERSION != 'tip'
19-
uses: actions/setup-go@v4
17+
- name: Install Go
18+
uses: actions/setup-go@v5
2019
with:
2120
go-version: ${{ env.GO_VERSION }}
22-
- name: Install Go tip
23-
if: env.GO_VERSION == 'tip'
24-
run: |
25-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
26-
ls -lah gotip.tar.gz
27-
mkdir -p ~/sdk/gotip
28-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
29-
~/sdk/gotip/bin/go version
30-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
3121
- name: Checkout code
32-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
3323
- name: Build artifacts
3424
run: |
3525
make release-assets
@@ -41,6 +31,14 @@ jobs:
4131
asset_path: ./linux_amd64.tar.gz
4232
asset_name: linux_amd64.tar.gz
4333
asset_content_type: application/tar+gzip
34+
- name: Upload linux_amd64_dbg.tar.gz
35+
if: hashFiles('linux_amd64_dbg.tar.gz') != ''
36+
uses: actions/upload-release-asset@v1
37+
with:
38+
upload_url: ${{ github.event.release.upload_url }}
39+
asset_path: ./linux_amd64_dbg.tar.gz
40+
asset_name: linux_amd64_dbg.tar.gz
41+
asset_content_type: application/tar+gzip
4442
- name: Upload linux_arm64.tar.gz
4543
if: hashFiles('linux_arm64.tar.gz') != ''
4644
uses: actions/upload-release-asset@v1

.github/workflows/test-unit.yml

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,25 @@ concurrency:
1515
env:
1616
GO111MODULE: "on"
1717
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
18-
COV_GO_VERSION: 1.20.x # Version of Go to collect coverage
18+
COV_GO_VERSION: stable # Version of Go to collect coverage
1919
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
2020
jobs:
2121
test:
2222
strategy:
2323
matrix:
24-
go-version: [ 1.13.x, 1.19.x, 1.20.x ]
24+
go-version: [ 1.13.x, stable, oldstable ]
2525
runs-on: ubuntu-latest
2626
steps:
27-
- name: Install Go stable
28-
if: matrix.go-version != 'tip'
29-
uses: actions/setup-go@v4
27+
- name: Install Go
28+
uses: actions/setup-go@v5
3029
with:
3130
go-version: ${{ matrix.go-version }}
3231

33-
- name: Install Go tip
34-
if: matrix.go-version == 'tip'
35-
run: |
36-
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
37-
ls -lah gotip.tar.gz
38-
mkdir -p ~/sdk/gotip
39-
tar -C ~/sdk/gotip -xzf gotip.tar.gz
40-
~/sdk/gotip/bin/go version
41-
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
42-
4332
- name: Checkout code
44-
uses: actions/checkout@v3
33+
uses: actions/checkout@v4
4534

4635
- name: Go cache
47-
uses: actions/cache@v3
36+
uses: actions/cache@v4
4837
with:
4938
# In order:
5039
# * Module download cache
@@ -59,7 +48,7 @@ jobs:
5948
- name: Restore base test coverage
6049
id: base-coverage
6150
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
62-
uses: actions/cache@v2
51+
uses: actions/cache@v4
6352
with:
6453
path: |
6554
unit-base.txt
@@ -88,14 +77,15 @@ jobs:
8877
id: annotate
8978
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
9079
run: |
91-
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.3.6/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
80+
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz
9281
gocovdiff_hash=$(git hash-object ./gocovdiff)
93-
[ "$gocovdiff_hash" == "8e507e0d671d4d6dfb3612309b72b163492f28eb" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1)
94-
git fetch origin master ${{ github.event.pull_request.base.sha }}
95-
REP=$(./gocovdiff -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV})
82+
[ "$gocovdiff_hash" == "c37862c73a677e5a9c069470287823ab5bbf0244" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1)
83+
# Fetch PR diff from GitHub API.
84+
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} > pull_request.diff
85+
REP=$(./gocovdiff -diff pull_request.diff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV})
9686
echo "${REP}"
9787
cat gha-unit.txt
98-
DIFF=$(test -e unit-base.txt && ./gocovdiff -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file")
88+
DIFF=$(test -e unit-base.txt && ./gocovdiff -mod github.com/$GITHUB_REPOSITORY -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file")
9989
TOTAL=$(cat delta-cov-unit.txt)
10090
echo "rep<<EOF" >> $GITHUB_OUTPUT && echo "$REP" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
10191
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$DIFF" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
@@ -130,7 +120,7 @@ jobs:
130120

131121
- name: Upload code coverage
132122
if: matrix.go-version == env.COV_GO_VERSION
133-
uses: codecov/codecov-action@v1
123+
uses: codecov/codecov-action@v5
134124
with:
135-
file: ./unit.coverprofile
125+
files: ./unit.coverprofile
136126
flags: unittests

.golangci.yml

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,85 @@
1-
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
1+
# See https://golangci-lint.run/docs/linters/configuration/
2+
version: "2"
23
run:
34
tests: true
4-
5-
linters-settings:
6-
errcheck:
7-
check-type-assertions: true
8-
check-blank: true
9-
gocyclo:
10-
min-complexity: 20
11-
dupl:
12-
threshold: 100
13-
misspell:
14-
locale: US
15-
unused:
16-
check-exported: false
17-
unparam:
18-
check-exported: true
19-
cyclop:
20-
max-complexity: 15
21-
225
linters:
23-
enable-all: true
6+
default: all
247
disable:
8+
- nilnil
259
- tparallel
26-
- goerr113
10+
- err113
2711
- errorlint
28-
- lll
29-
- maligned
30-
- gochecknoglobals
31-
- gomnd
32-
- wrapcheck
33-
- paralleltest
12+
- noinlineerr
13+
- wsl_v5
14+
- funcorder
15+
- copyloopvar
16+
- depguard
17+
- dupword
18+
- errname
19+
- exhaustruct
3420
- forbidigo
35-
- exhaustivestruct
36-
- interfacer # deprecated
3721
- forcetypeassert
38-
- scopelint # deprecated
39-
- ifshort # too many false positives
40-
- golint # deprecated
41-
- varnamelen
42-
- tagliatelle
43-
- errname
22+
- gochecknoglobals
23+
- intrange
4424
- ireturn
45-
- exhaustruct
25+
- lll
26+
- mnd
4627
- nonamedreturns
47-
- nosnakecase
48-
- structcheck
49-
- varcheck
50-
- deadcode
28+
- paralleltest
29+
- recvcheck
30+
- tagalign
31+
- tagliatelle
5132
- testableexamples
52-
- dupword
53-
54-
issues:
55-
exclude-use-default: false
56-
exclude-rules:
57-
- linters:
58-
- gomnd
59-
- goconst
60-
- goerr113
61-
- noctx
62-
- funlen
63-
- dupl
64-
- structcheck
65-
- unused
66-
- unparam
67-
- nosnakecase
68-
path: "_test.go"
69-
- linters:
70-
- errcheck # Error checking omitted for brevity.
71-
- gosec
72-
path: "example_"
73-
33+
- testifylint
34+
- varnamelen
35+
- wrapcheck
36+
settings:
37+
dupl:
38+
threshold: 100
39+
errcheck:
40+
check-type-assertions: true
41+
check-blank: true
42+
gocyclo:
43+
min-complexity: 20
44+
cyclop:
45+
max-complexity: 15
46+
misspell:
47+
locale: US
48+
unparam:
49+
check-exported: true
50+
exclusions:
51+
generated: lax
52+
rules:
53+
- linters:
54+
- gosec
55+
- dupl
56+
- funlen
57+
- goconst
58+
- mnd
59+
- noctx
60+
- unparam
61+
- unused
62+
path: _test.go
63+
- linters:
64+
- errcheck
65+
- gosec
66+
path: example_
67+
- linters:
68+
- revive
69+
text: 'unused-parameter: parameter'
70+
paths:
71+
- third_party$
72+
- builtin$
73+
- examples$
74+
formatters:
75+
enable:
76+
- gci
77+
- gofmt
78+
- gofumpt
79+
- goimports
80+
exclusions:
81+
generated: lax
82+
paths:
83+
- third_party$
84+
- builtin$
85+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#GOLANGCI_LINT_VERSION := "v1.51.1" # Optional configuration to pinpoint golangci-lint version.
1+
#GOLANGCI_LINT_VERSION := "v2.5.0" # Optional configuration to pinpoint golangci-lint version.
22

33
# The head of Makefile determines location of dev-go to include standard targets.
44
GO ?= go

cmd/jsoncompact/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() { //nolint
4040

4141
input = flag.Arg(0)
4242
if input == "" {
43-
_, _ = fmt.Fprintln(flag.CommandLine.Output(), "Missing input path argument, use `-` for stdin.")
43+
_, _ = fmt.Fprintln(flag.CommandLine.Output(), "Missing input path argument, use `-` for stdin.") //nolint
4444
flag.Usage()
4545

4646
return

equal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (c Comparer) filterExpected(expected []byte) ([]byte, error) {
198198
return nil, fmt.Errorf("failed to marshal var %s: %v", k, err) // Not wrapping to support go1.12.
199199
}
200200

201-
expected = bytes.Replace(expected, []byte(`"`+k+`"`), j, -1) //nolint:gocritic // To support go1.11.
201+
expected = bytes.Replace(expected, []byte(`"`+k+`"`), j, -1) //nolint:gocritic,staticcheck // To support go1.11.
202202
}
203203
}
204204

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/swaggest/assertjson
33
go 1.17
44

55
require (
6-
github.com/bool64/dev v0.2.29
6+
github.com/bool64/dev v0.2.43
77
github.com/bool64/shared v0.1.5
88
github.com/iancoleman/orderedmap v0.3.0
99
github.com/stretchr/testify v1.4.0

0 commit comments

Comments
 (0)