Github操作:golang找不到包



我将示例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

但作业失败,其中CCD_。这里有错误。

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.modgo.sum

这不是OP的正确答案,但可能有助于搜索此处。

在你的go项目的根:

go mod init
go mod tidy

提交并推送到github,它现在应该可以工作了。

你需要为go get或go mod设置一个令牌来下载私人转发,这就是为什么你会得到404。

首先,您需要将私有repos添加到GO_private环境变量中。

env:
GO_PRIVATE: github.com/<organization-account>/*

然后您需要配置git来使用该令牌。

- name: Setup Git
run: git config --global url."https://${{ secrets.TOKEN }}:@github.com/".insteadOf "https://github.com"
- name: Get dependencies
run: go mod download

将令牌添加到github.com 中的动作机密

我不使用dep,但你应该使用go mod下载,而不是go get或dep,因为你有一个mod文件。我不知道你为什么同时使用dep-AND-go模块和go-get。奇怪的

最新更新