Rodolfo
Rodolfo

Reputation: 1181

GitHub action for golangci-lint fails with can't load fmt

I'm using the GitHub action https://github.com/golangci/golangci-lint-action

I'm getting the error:

Installed golangci-lint into /home/runner/golangci-lint-1.43.0-linux-amd64/golangci-lint in 458ms
Prepared env in 606ms

run golangci-lint
  Running [/home/runner/golangci-lint-1.43.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
  
  goroutine 1 [running]:
  github.com/go-critic/go-critic/checkers.init.9()
    github.com/go-critic/[email protected]/checkers/checkers.go:58 +0x4b4
  
  Error: golangci-lint exit with code 2
  Ran golangci-lint in 13383ms

Which is a known issue for golangci-lint with golang v1.18.0 https://github.com/golangci/golangci-lint/issues/2374

My GitHub action file is:

name: golangci-lint
on:
  push:
    tags:
      - v*
    branches:
      - master
      - main
  pull_request:
permissions:
  contents: read
jobs:
  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-go@v2
      - uses: actions/checkout@v2
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: v1.43

I've also tried to use:

name: golangci-lint
on:
  push:
    tags:
      - v*
    branches:
      - master
      - main
  pull_request:
permissions:
  contents: read
jobs:
  golangci:
    strategy:
      matrix:
        go-version: [1.17.x]
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.go }}
      - uses: actions/checkout@v3
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: v1.43

But both are failing, what can I do in that case?

I have open this issue in the project, in case it helps https://github.com/golangci/golangci-lint-action/issues/442

Upvotes: 14

Views: 16044

Answers (6)

25b3nk
25b3nk

Reputation: 184

I had the issue even after using v3 packages. I had to update the version of the golang-ci to the latest one available. Please note that, my go-version is 1.22

Upvotes: 0

HelloThere
HelloThere

Reputation: 1040

My case is a little tricky.

I have golangci-lint installed from both brew install and go get. (That's why brew install golangci-lint or brew upgrade golangci-lint is not working for me...)

So I ran which golangci-lint first to see which one is not working, and then follow other answers here to upgrade it or reinstall it.

Upvotes: 0

Craig Ringer
Craig Ringer

Reputation: 324531

I've seen the same issue here, and found that it's a problem when using the go 1.19 toolchain with golangci-lint.

If I run it with go 1.18, it works fine. With go 1.19, it fails with the same error as given here.

Upvotes: 0

Dmytro Boichenko
Dmytro Boichenko

Reputation: 5407

On my MacOS I simply removed all previous versions and installed the newest one by the following command

brew install golangci-lint

Upvotes: 0

VonC
VonC

Reputation: 1325047

Issue 442 is fixed by PR 275 and commit 6ee1db2 (v1.4.1), based on comment:

The matrix keys do not seem to match, would correcting that solve the problem?

    strategy:
      matrix:
        go-version: [1.17.x]
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.go-version }}

And the current workaround mentioned in issue 2374 by Charlie Revett:

go version go1.17.11 darwin/arm64
  • Uninstall all versions of Go from Homebrew
  • Uninstall all versions of golangci-lint from Homebrew
  • Do some directory cleanup using find / -type d -name go 2> /dev/null
  • Do some directory cleanup using find / -type d -name "golangci-lint" 2> /dev/null
  • Install go1.17.11.darwin-arm64.pkg via go.dev/dl using the installer (.pkg)
  • Install golangci-lint using go install github.com/golangci/golangci-lint/cmd/[email protected] (current latest version).
    See "Install from source"

Upvotes: 0

bcl
bcl

Reputation: 161

Bumping golangci/golangci-lint-action, actions/setup-go, and actions/checkout to v3 did the trick for me.

Upvotes: 8

Related Questions