[英]Github Action : golang cannot find package
我将示例 github 操作设置到我的存储库。 片段在这里。
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
但工作在Get dependencies
失败。 错误在这里。
package github.com/<organization-account>/<repo-name>/api/domain/repo: cannot find package "github.com/<organization-account>/<repo-name>/api/domain/repo" in any of:
/opt/hostedtoolcache/go/1.14.4/x64/src/github.com/<organization-account>/<repo-name>/api/domain/repo (from $GOROOT)
/home/runner/go/src/github.com/<organization-account>/<repo-name>/api/domain/repo (from $GOPATH)
当然。 当go run main.go
时,我的代码在本地工作。 我有go.mod
, go.sum
。
这不是 OP 的正确答案,但可以帮助某人通过搜索到达这里。
在 go 项目的根目录中:
go mod init
go mod tidy
提交并推送到 github,它现在应该可以工作了。
您需要为 go get 或 go mod 设置一个令牌来下载私人存储库,这就是您获得 404 的原因
然后您需要配置 git 以使用该令牌。
- name: Setup Git
run: git config --global url."https://${{ secrets.TOKEN }}:@github.com/".insteadOf "https://github.com"
我不使用 dep,但你应该使用 go mod download 而不是 go get 或 dep 因为你有一个 mod 文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.