Skip to content

Commit 674aee9

Browse files
authored
feat: implement golangci-lint support (ipdxco#112)
* feat: implement golangci-lint support * feat: use golangci-lint's version of some checks * fix: tie golangci-lint versions to go versions * chore: restore previous implementation of staticcheck * chore: update default versions of staticcheck and golangci-lint * chore: restore original staticcheck versions * chore: disable golangci-lint's statichckeck and govet * chore: remove new from merge base * chore: run checks over all the files in some cases * chore: fix the changed files extraction
1 parent 6cfa304 commit 674aee9

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/go-check.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ jobs:
2222
uses: actions/checkout@v4
2323
with:
2424
submodules: recursive
25+
- name: Extend the GitHub context
26+
id: github
27+
env:
28+
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
29+
run: |
30+
if [[ -n "$BASE_SHA" ]]; then
31+
echo "base_sha=$BASE_SHA" | tee -a $GITHUB_OUTPUT
32+
git fetch origin "$BASE_SHA"
33+
git diff --name-only "$BASE_SHA" |
34+
jq -Rnc '[inputs]' |
35+
xargs -I {} -0 echo "changed_files={}" |
36+
tee -a $GITHUB_OUTPUT
37+
fi
2538
- name: Check out the latest stable version of Go
2639
id: stable
2740
uses: actions/setup-go@v5
@@ -46,6 +59,22 @@ jobs:
4659
if: hashFiles('./.github/actions/go-check-setup') != ''
4760
- name: Install staticcheck
4861
env:
62+
# TODO: Update the staticcheck versions to the latest we should be able to use with each Go version.
63+
# STATICCHECK_VERSIONS: | # 2025.1.1, 2025.1.1, 2024.1.1, 2023.1.7, 2023.1.7, 2023.1.7, 2022.1.3, 2022.1.3, 2021.1.2, 2021.1.2, 2021.1.2, 2020.1.6
64+
# {
65+
# "1.24": "b8ec13ce4d00445d75da053c47498e6f9ec5d7d6",
66+
# "1.23": "b8ec13ce4d00445d75da053c47498e6f9ec5d7d6",
67+
# "1.22": "56172d41b117cc2c2f99f65fe0a790c8d7d7ea66",
68+
# "1.21": "a093f7c2d3d45d5104fb3414ae939a98be37be02",
69+
# "1.20": "a093f7c2d3d45d5104fb3414ae939a98be37be02",
70+
# "1.19": "a093f7c2d3d45d5104fb3414ae939a98be37be02",
71+
# "1.18": "376210a89477dedbe6fdc4484b233998650d7b3c",
72+
# "1.17": "376210a89477dedbe6fdc4484b233998650d7b3c",
73+
# "1.16": "c8caa92bad8c27ae734c6725b8a04932d54a147b",
74+
# "1.15": "c8caa92bad8c27ae734c6725b8a04932d54a147b",
75+
# "1.14": "c8caa92bad8c27ae734c6725b8a04932d54a147b",
76+
# "1.13": "5b7de96f09104e2be384aa93a7c821eb5e77378b"
77+
# }
4978
STATICCHECK_VERSIONS: |
5079
{
5180
"1.24": "5af2e5fc3b08ba46027eb48ebddeba34dc0bd02c",
@@ -67,6 +96,33 @@ jobs:
6796
version="$(jq -nr 'env.STATICCHECK_VERSIONS | fromjson | .[env.GO_VERSION | sub("\\.[^.]+$"; "")] // "latest"')"
6897
echo "Installing staticcheck@$version"
6998
go install honnef.co/go/tools/cmd/staticcheck@$version || go get honnef.co/go/tools/cmd/staticcheck@$version
99+
- name: Install golangci-lint
100+
if: hashFiles('.golangci.yml', '.golangci.toml', '.golangci.json', '.golangci.yaml') != ''
101+
env:
102+
GOLANGCI_LINT_VERSIONS: | # v2.1.6, v2.1.6, v1.63.4, v1.59.1, v1.55.2, v1.53.3, v1.47.3, v1.44.2, v1.44.2, v1.42.1, v1.39.0, v1.37.1
103+
{
104+
"1.24": "eabc2638a66daf5bb6c6fb052a32fa3ef7b6600d",
105+
"1.23": "eabc2638a66daf5bb6c6fb052a32fa3ef7b6600d",
106+
"1.22": "c1149695535fda62f6b574bc55dfbc333693647e",
107+
"1.21": "1a55854aff4ef60cd8c4e709b650b281303ca7aa",
108+
"1.20": "e3c2265f4939976874989e159386b3bb7dcf8e1f",
109+
"1.19": "2dcd82f331c9e834f283075b23ef289435be9354",
110+
"1.18": "d186efe918b91431b6d615d7968eb14ba7c6614a",
111+
"1.17": "d58dbde584c801091e74a00940e11ff18c6c68bd",
112+
"1.16": "d58dbde584c801091e74a00940e11ff18c6c68bd",
113+
"1.15": "54f4301ddfc884a7eac5b6ebf68868d6078279d3",
114+
"1.14": "9aea4aee1c0d47f74c016c1f0066cb90e2f7d2e8",
115+
"1.13": "b39dbcd694baddce38eff2cb2aa86d4e4cf06753"
116+
}
117+
GO_VERSION: ${{ steps.go.outputs.go-version }}
118+
GO111MODULE: on
119+
run: |
120+
version="$(jq -nr 'env.GOLANGCI_LINT_VERSIONS | fromjson | .[env.GO_VERSION | sub("\\.[^.]+$"; "")] // "latest"')"
121+
echo "Installing golangci-lint@$version"
122+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$version ||
123+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$version ||
124+
go get github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$version ||
125+
go get github.com/golangci/golangci-lint/cmd/golangci-lint@$version
70126
- name: Check that go.mod is tidy
71127
uses: protocol/[email protected]
72128
with:
@@ -97,6 +153,24 @@ jobs:
97153
run: |
98154
set -o pipefail
99155
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
156+
- name: golangci-lint run
157+
if: (success() || failure()) && hashFiles('.golangci.yml', '.golangci.toml', '.golangci.json', '.golangci.yaml') != ''
158+
uses: protocol/[email protected]
159+
env:
160+
NEW_FROM_REV: ${{
161+
steps.github.outputs.base_sha && !(
162+
contains(fromJSON(steps.github.outputs.changed_files), 'go.mod') ||
163+
contains(fromJSON(steps.github.outputs.changed_files), '.github/workflows/go-check.yml') ||
164+
(
165+
contains(fromJSON(steps.github.outputs.changed_files), '.golangci.yml') ||
166+
contains(fromJSON(steps.github.outputs.changed_files), '.golangci.toml') ||
167+
contains(fromJSON(steps.github.outputs.changed_files), '.golangci.json') ||
168+
contains(fromJSON(steps.github.outputs.changed_files), '.golangci.yaml')
169+
)
170+
) && steps.github.outputs.base_sha || ''
171+
}}
172+
with:
173+
run: golangci-lint run --disable govet --disable staticcheck --new=false --new-from-patch= --new-from-rev=$NEW_FROM_REV --verbose
100174
- name: go generate
101175
uses: protocol/[email protected]
102176
if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true

0 commit comments

Comments
 (0)