我有一个简单的 go 包,但在 Github Actions 中测试期间,它失败并出现以下错误:
##[错误]keywords.go:8:2:在以下任一位置找不到包“github.com/securisec/go-keywords/languages”:
。
当我在本地运行测试时(我使用的是 go mod),所有测试都工作正常。
对于 Github 操作,我尝试将 GO111MODULE
设置为 on
和 off
,但仍然遇到相同的错误。
可以观察到错误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/