golangci-lint 的 GitHub 操作失败,无法加载 fmt

分享于2022年07月17日 github-actions go 问答
【问题标题】:golangci-lint 的 GitHub 操作失败,无法加载 fmt(GitHub action for golangci-lint fails with can't load fmt)
【发布时间】:2022-06-12 16:41:38
【问题描述】:

我正在使用 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

对于使用 golang v1.18.0 https://github.com/golangci/golangci-lint/issues/2374 golangci-lint ,这是一个已知问题

我的 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


【解决方案1】:

将 golangci/golangci-lint-action、actions/setup-go 和 actions/checkout 升级到 v3 对我来说很有效。