GitHub操作对于golangci-lint失败,出现无法加载fmt的错误。

huangapple go评论90阅读模式
英文:

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

问题

我正在使用GitHub操作https://github.com/golangci/golangci-lint-action。

我遇到了以下错误:

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/go-critic@v0.6.1/checkers/checkers.go:58 +0x4b4
  
  Error: golangci-lint exit with code 2
  Ran golangci-lint in 13383ms

这是golangci-lint与golang v1.18.0存在的已知问题https://github.com/golangci/golangci-lint/issues/2374。

我的GitHub操作文件是:

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

我还尝试了以下方法:

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

但两者都失败了,在这种情况下我该怎么办?

我在该项目中提了一个问题,希望能有所帮助https://github.com/golangci/golangci-lint-action/issues/442

英文:

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/go-critic@v0.6.1/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

答案1

得分: 8

将 golangci/golangci-lint-action、actions/setup-go 和 actions/checkout 升级到 v3 对我来说起到了作用。

英文:

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

答案2

得分: 0

问题442已经通过PR 275commit 6ee1db2(v1.4.1)进行了修复,基于评论

> 矩阵键似乎不匹配,修正后是否能解决问题?

    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 }}

并且在问题2374中由Charlie Revett提到的当前解决方法:

> go version go1.17.11 darwin/arm64
>
> - 从Homebrew卸载所有Go版本
> - 从Homebrew卸载所有golangci-lint版本
> - 使用find / -type d -name go 2> /dev/null进行一些目录清理
> - 使用find / -type d -name "golangci-lint" 2> /dev/null进行一些目录清理
> - 使用安装程序(.pkg)通过go.dev/dl安装go1.17.11.darwin-arm64.pkg
> - 使用go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2当前最新版本)安装golangci-lint。参见“从源代码安装”。

英文:

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/golangci-lint@v1.46.2 (current latest version).
See "Install from source"

答案3

得分: 0

在我的MacOS上,我只需通过以下命令删除所有先前的版本并安装最新版本:

brew install golangci-lint
英文:

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

brew install golangci-lint

答案4

得分: 0

我在这里看到了相同的问题,并发现在使用go 1.19工具链与golangci-lint时存在问题。

如果我使用go 1.18运行它,它可以正常工作。但是在go 1.19下,它会出现与此处给出的相同错误。

英文:

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.

答案5

得分: 0

我的情况有点棘手。

我同时从brew installgo get安装了golangci-lint。(这就是为什么brew install golangci-lintbrew upgrade golangci-lint对我不起作用的原因...)

所以我首先运行which golangci-lint来查看哪个不起作用,然后按照这里的其他答案来升级或重新安装它。

英文:

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.

huangapple
  • 本文由 发表于 2022年4月6日 05:58:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/71758856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定