go - Github 操作 go test 找不到包错误。我怎样才能解决这个问题?

标签 go github github-actions

我有一个简单的 go 包,但在 Github Actions 中测试期间,它失败并出现以下错误:

##[错误]keywords.go:8:2:在以下任一位置找不到包“github.com/securisec/go-keywords/languages”:

当我在本地运行测试时(我使用的是 go mod),所有测试都工作正常。

对于 Github 操作,我尝试将 GO111MODULE 设置为 onoff,但仍然遇到相同的错误。

可以观察到错误here 。我的测试工作流程是:

name: tests

on:
  - push
  - pull_request

jobs:
  test:
    name: Test package
    strategy:
      max-parallel: 3
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
        go:
          - "1.11"
          - "1.13"
          - "1.14"
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        env:
          GOPATH: ${{ runner.workspace }}
          GO111MODULE: "on"

      - name: Go setup
        uses: actions/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e6f0e1e0e5b8f2fad5e3a4bba5bba5" rel="noreferrer noopener nofollow">[email protected]</a>
        with:
          go-version: ${{matrix.go}}
        env:
          GOPATH: ${{ runner.workspace }}
          GO111MODULE: "on"
      - name: Run test
        env:
          GOPATH: ${{ runner.workspace }}
          GO111MODULE: "on"
        run: |
          go get -u github.com/grokify/html-strip-tags-go
          go test ./...
      - if: failure()
        run: ls -R

Go 模组文件:

module github.com/securisec/go-keywords

go 1.14

require github.com/grokify/html-strip-tags-go v0.0.0-20200322061010-ea0c1cf2f119

如何修复此错误?

最佳答案

因此,如果您查看完整的错误消息:

##[error]keywords.go:8:2: cannot find package "github.com/securisec/go-keywords/languages" in any of:
    /opt/hostedtoolcache/go/1.10.0/x64/src/github.com/securisec/go-keywords/languages (from $GOROOT)
    /home/runner/work/go-keywords/src/github.com/securisec/go-keywords/languages (from $GOPATH)
##[error]Process completed with exit code 1.

您会注意到您正在尝试在 Go 1.10 中运行代码。 Go 模块是在 Go 1.11 中引入的,因此它总是会提示应用程序没有安装依赖项。

然后,如果您查看 Go 设置日志:

Go setup
    GO111MODULE: on
##[warning]Unexpected input 'go-version', valid inputs are ['version']
Run actions/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3340564746431e545c7345021d031d03" rel="noreferrer noopener nofollow">[email protected]</a>
  with:
    go-version: 1.11
    version: 1.10
  env:
    GOPATH: /home/runner/work/go-keywords
    GO111MODULE: on
/bin/tar xzC /home/runner/work/_temp/0ce9b622-d798-400e-b86a-42d36359ad78 -f /home/runner/work/_temp/80f228cc-4b21-427f-b111-d9f296ed4990

您会看到安装程序发出警告并默认为您安装 go 1.10。

这是因为您的目标版本是 v1.0.0,它不理解 go-version 标志。 (我认为是在 v1.1.0 中添加的)

解决方案:

更改uses: actions/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfacbaabaaaff2b8b09fa9eef1eff1ef" rel="noreferrer noopener nofollow">[email protected]</a>uses: actions/setup-go@v1获取最新的 v1 版本。

或者更好地使用 v2。

关于go - Github 操作 go test 找不到包错误。我怎样才能解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62399981/

相关文章:

eclipse - 如何在 Eclipse Joomla 开发项目中设置 EGit 以在 GitHub 上托管的第三方模块上工作?

git - 如何减少 Github 上 repo 的大小

node.js - 使用github Action 进行部署时如何在node.js进程中设置环境变量

azure - Azure Web App 上的自定义 golang 启动命令

用于构建 API 的类似 Express 的框架

api - 未在Vue页面上检测到Cookie

go - 安装gobuffalo后如何修复 '/gobuffalo/buffalo/plugins/plugdeps/plugin.go:15:11: undefined: meta.BuildTags'错误

go - 数据库/SQL行。扫描在35万行后挂起

android - 在android studio中添加库?

github - 在 Github Actions 工作流中获取当前作业名称