Skip to content

Commit

Permalink
Add a golint action
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Dec 14, 2024
1 parent cb49ffc commit a02cd00
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
41 changes: 30 additions & 11 deletions .github/actions/lint-go/action.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
name: "Go lint"
name: "lint-go"
description: "This action will install go linting tools (golangci-lint and goimports-reviser), and executes them on the codebase."
inputs:
cache-dependency-path:
description: 'Used to specify the path to a dependency file - go.sum'
strategy:
description: "See intall-go for info"
description: "See install-go for info"
goos:
description: "The GOOS we want to lint for"
_golangci_version:
description: "Internal: the golangci version we want"
default: "89476e7a1eaa0a8a06c17343af960a5fd9e7edb7" # v1.62.2
_goimports_version:
description: "Internal: the goimports reviser version we want"
default: "f034195cc8a7ffc7cc70d60aa3a25500874eaf04" # v3.8.2

runs:
using: composite
steps:
- name: "Install go"
- name: "Install golang"
uses: ./.github/actions/install-go
with:
strategy: ${{ inputs.strategy }}
- name: "Run golangci-lint"
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
with:
args: --verbose
skip-save-cache: true
skip-cache: true
- name: "Check that go imports ordering is ok"
- name: "`go install` needed tools"
shell: bash
run: |
err="$(go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@${{ inputs._golangci_version }} 2>&1)" || {
echo "Failed installing golangci:"
echo "$err"
}
err="$(go install -v github.com/incu6us/goimports-reviser/v3@${{ inputs._goimports_version }} 2>&1)" || {
echo "Failed installing goimports-reviser:"
echo "$err"
}
- name: "`make lint-imports`"
# Import ordering is not influenced by GOOS - running it multiple times is thus unnecessary
# Note we are picking freebsd as the GOOS to run it on, as linux is running multiple times (eg: canary)
if: ${{ inputs.goos=='freebsd' }}
shell: bash
run: |
go install -v github.com/incu6us/goimports-reviser/v3@f034195cc8a7ffc7cc70d60aa3a25500874eaf04 # v3.8.2
make lint-imports
- name: "`make lint-go` for ${{ inputs.goos }} and $GO_VERSION"
shell: bash
run: |
VERBOSE=true GOOS=${{ inputs.goos }} make lint-go
25 changes: 5 additions & 20 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ jobs:
timeout-minutes: 5
name: "go | ${{ matrix.goos }} | ${{ matrix.goversion }}"
runs-on: "${{ matrix.os }}"
defaults:
run:
shell: bash
strategy:
matrix:
include:
Expand All @@ -32,37 +29,25 @@ jobs:
- os: ubuntu-24.04
goos: linux
goversion: canary
env:
GOOS: "${{ matrix.goos }}"
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- name: "Install go"
uses: ./.github/actions/install-go
- name: "Run go linters"
uses: ./.github/actions/lint-go
with:
strategy: ${{ matrix.goversion }}
- name: golangci-lint
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
with:
args: --verbose
goos: ${{ matrix.goos }}

other:
timeout-minutes: 5
name: yaml | shell | imports order
name: yaml | shell
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- name: "Install go"
uses: ./.github/actions/install-go
with:
strategy: latest-stable
- name: yaml
run: make lint-yaml
- name: shell
run: make lint-shell
- name: go imports ordering
run: |
go install -v github.com/incu6us/goimports-reviser/v3@latest
make lint-imports
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ clean:
find . -name \#\* -delete
rm -rf $(CURDIR)/_output/* $(MAKEFILE_DIR)/vendor

lint: lint-go lint-imports lint-yaml lint-shell
lint: lint-go-all lint-imports lint-yaml lint-shell

lint-go:
lint-go-all:
cd $(MAKEFILE_DIR) && GOOS=linux golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
GOOS=windows golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
GOOS=freebsd golangci-lint run $(VERBOSE_FLAG_LONG) ./...

lint-go:
cd $(MAKEFILE_DIR) && golangci-lint run $(VERBOSE_FLAG_LONG) ./...

lint-imports:
cd $(MAKEFILE_DIR) && ./hack/lint-imports.sh

Expand Down

0 comments on commit a02cd00

Please sign in to comment.