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 2e953b7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
35 changes: 35 additions & 0 deletions .github/actions/install-go-linters/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 install-go for info"
_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 golang"
uses: ./.github/actions/install-go
with:
strategy: ${{ inputs.strategy }}
- name: "`go install` needed tools"
shell: bash
run: |
# go install golangci-lint and goimports-reviser
err="$(go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@${{ inputs._golangci_version }} 2>&1)" || {
echo "Failed installing golangci:"
echo "$err"
exit 1
}
err="$(go install -v github.com/incu6us/goimports-reviser/v3@${{ inputs._goimports_version }} 2>&1)" || {
echo "Failed installing goimports-reviser:"
echo "$err"
exit 1
}
26 changes: 0 additions & 26 deletions .github/actions/lint-go/action.yml

This file was deleted.

38 changes: 18 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,38 @@ 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: "Install go linters"
uses: ./.github/actions/install-go-linters
with:
strategy: ${{ matrix.goversion }}
- name: golangci-lint
uses: golangci/golangci-lint-action@774c35bcccffb734694af9e921f12f57d882ef74 # v6.1.1
with:
args: --verbose
- 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: ${{ matrix.goos=='freebsd' }}
shell: bash
run: |
make lint-imports
- name: "`make lint-go` for ${{ matrix.goos }}"
env:
VERBOSE: true
GOOS: ${{ matrix.goos }}
shell: bash
run: |
make lint-go
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 2e953b7

Please sign in to comment.