Skip to content

Commit 200f87f

Browse files
committed
Add a golint action
Signed-off-by: apostasie <[email protected]>
1 parent cb49ffc commit 200f87f

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

.github/actions/lint-go/action.yml

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
1-
name: "Go lint"
1+
name: "lint-go"
22
description: "This action will install go linting tools (golangci-lint and goimports-reviser), and executes them on the codebase."
33
inputs:
44
cache-dependency-path:
55
description: 'Used to specify the path to a dependency file - go.sum'
66
strategy:
7-
description: "See intall-go for info"
7+
description: "See install-go for info"
8+
goos:
9+
description: "The GOOS we want to lint for"
10+
_golangci_version:
11+
description: "Internal: the golangci version we want"
12+
default: "89476e7a1eaa0a8a06c17343af960a5fd9e7edb7" # v1.62.2
13+
_goimports_version:
14+
description: "Internal: the goimports reviser version we want"
15+
default: "f034195cc8a7ffc7cc70d60aa3a25500874eaf04" # v3.8.2
816

917
runs:
1018
using: composite
1119
steps:
12-
- name: "Install go"
20+
- name: "Install golang"
1321
uses: ./.github/actions/install-go
1422
with:
1523
strategy: ${{ inputs.strategy }}
16-
- name: "Run golangci-lint"
17-
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
18-
with:
19-
args: --verbose
20-
skip-save-cache: true
21-
skip-cache: true
22-
- name: "Check that go imports ordering is ok"
24+
- name: "`go install` needed tools"
25+
shell: bash
26+
run: |
27+
# go install golangci-lint and goimports-reviser
28+
err="$(go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@${{ inputs._golangci_version }} 2>&1)" || {
29+
echo "Failed installing golangci:"
30+
echo "$err"
31+
}
32+
err="$(go install -v github.com/incu6us/goimports-reviser/v3@${{ inputs._goimports_version }} 2>&1)" || {
33+
echo "Failed installing goimports-reviser:"
34+
echo "$err"
35+
}
36+
- name: "`make lint-imports`"
37+
# Import ordering is not influenced by GOOS - running it multiple times is thus unnecessary
38+
# Note we are picking freebsd as the GOOS to run it on, as linux is running multiple times (eg: canary)
39+
if: ${{ inputs.goos=='freebsd' }}
2340
shell: bash
2441
run: |
25-
go install -v github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 # v3.8.2
2642
make lint-imports
43+
- name: "`make lint-go` for ${{ inputs.goos }} and $GO_VERSION"
44+
env:
45+
VERBOSE: true
46+
GOOS: ${{ inputs.goos }}
47+
shell: bash
48+
run: |
49+
make lint-go

.github/workflows/lint.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ jobs:
1212
timeout-minutes: 5
1313
name: "go | ${{ matrix.goos }} | ${{ matrix.goversion }}"
1414
runs-on: "${{ matrix.os }}"
15-
defaults:
16-
run:
17-
shell: bash
1815
strategy:
1916
matrix:
2017
include:
@@ -32,37 +29,25 @@ jobs:
3229
- os: ubuntu-24.04
3330
goos: linux
3431
goversion: canary
35-
env:
36-
GOOS: "${{ matrix.goos }}"
3732
steps:
3833
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3934
with:
4035
fetch-depth: 1
41-
- name: "Install go"
42-
uses: ./.github/actions/install-go
36+
- name: "Run go linters"
37+
uses: ./.github/actions/lint-go
4338
with:
4439
strategy: ${{ matrix.goversion }}
45-
- name: golangci-lint
46-
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
47-
with:
48-
args: --verbose
40+
goos: ${{ matrix.goos }}
41+
4942
other:
5043
timeout-minutes: 5
51-
name: yaml | shell | imports order
44+
name: yaml | shell
5245
runs-on: ubuntu-24.04
5346
steps:
5447
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
5548
with:
5649
fetch-depth: 1
57-
- name: "Install go"
58-
uses: ./.github/actions/install-go
59-
with:
60-
strategy: latest-stable
6150
- name: yaml
6251
run: make lint-yaml
6352
- name: shell
6453
run: make lint-shell
65-
- name: go imports ordering
66-
run: |
67-
go install -v github.com/incu6us/goimports-reviser/v3@latest
68-
make lint-imports

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ clean:
6767
find . -name \#\* -delete
6868
rm -rf $(CURDIR)/_output/* $(MAKEFILE_DIR)/vendor
6969

70-
lint: lint-go lint-imports lint-yaml lint-shell
70+
lint: lint-go-all lint-imports lint-yaml lint-shell
7171

72-
lint-go:
72+
lint-go-all:
7373
cd $(MAKEFILE_DIR) && GOOS=linux golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
7474
GOOS=windows golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
7575
GOOS=freebsd golangci-lint run $(VERBOSE_FLAG_LONG) ./...
7676

77+
lint-go:
78+
cd $(MAKEFILE_DIR) && golangci-lint run $(VERBOSE_FLAG_LONG) ./...
79+
7780
lint-imports:
7881
cd $(MAKEFILE_DIR) && ./hack/lint-imports.sh
7982

0 commit comments

Comments
 (0)