简体   繁体   English

Github 动作 go 测试找不到 package 错误。 我怎样才能解决这个问题?

[英]Github actions go test cannot find package error. How can I fix this?

I have a simple go package, but during testing within Github Actions, it is failing with this error:我有一个简单的 go package,但是在 Github Actions 中进行测试期间,它失败并出现以下错误:

##[error]keywords.go:8:2: cannot find package "github.com/securisec/go-keywords/languages" in any of: . ##[error]keywords.go:8:2: cannot find package "github.com/securisec/go-keywords/languages" in any of: .

When I run the tests locally (I am using go mod), all the tests works fine.当我在本地运行测试时(我使用的是 go mod),所有测试都运行良好。

For Github actions, I have tried setting GO111MODULE to both on and off , but still getting the same error.对于 Github 操作,我尝试将GO111MODULE设置为onoff ,但仍然出现相同的错误。

The error can be observed here .可以在此处观察到错误。 My testing workflow is:我的测试工作流程是:

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/setup-go@v1.0.0
        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 mod file: Go 模组文件:

module github.com/securisec/go-keywords

go 1.14

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

How can I fix this error?我该如何解决这个错误?

So if you look at the full error messages:因此,如果您查看完整的错误消息:

##[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.

You will notice that you are trying to run code in Go 1.10.您会注意到您正在尝试在 Go 1.10 中运行代码。 Go module was introduced in Go 1.11 so it will always complain that the application does not have a dependency installed. Go 模块是在 Go 1.11 中引入的,因此它总是会抱怨应用程序没有安装依赖项。

And then if you look at your Go setup log:然后,如果您查看 Go 设置日志:

Go setup
    GO111MODULE: on
##[warning]Unexpected input 'go-version', valid inputs are ['version']
Run actions/setup-go@v1.0.0
  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

You see that setup is giving a warning and installing go 1.10 for you by default.您会看到安装程序发出警告并默认为您安装 go 1.10。

That is because you have targeted the specific version v1.0.0 which does not understand the go-version flag.那是因为您已针对不了解 go-version 标志的特定版本 v1.0.0。 (it was added in v1.1.0 I think) (我认为它是在 v1.1.0 中添加的)

Solution :解决方案

Change uses: actions/setup-go@v1.0.0 to uses: actions/setup-go@v1 to get latest v1 version. uses: actions/setup-go@v1.0.0更改为uses: actions/setup-go@v1以获取最新的 v1 版本。

Or even better use v2.或者甚至更好地使用 v2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM