简体   繁体   English

Github 操作:golang 找不到 package

[英]Github Action : golang cannot find package

I set sample github action to my repository.我将示例 github 操作设置到我的存储库。 snippet is here.片段在这里。

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

but job is fail where Get dependencies .但工作在Get dependencies失败。 error is here.错误在这里。

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)

of course.当然。 My code is work at local when go run main.go .go run main.go时,我的代码在本地工作。 I have go.mod , go.sum .我有go.modgo.sum

This is not a correct answer for the OP, but may help someone reaching here from searching.这不是 OP 的正确答案,但可以帮助某人通过搜索到达这里。

In the root of your go project:在 go 项目的根目录中:

go mod init
go mod tidy

Commit and push to github, and it should work now.提交并推送到 github,它现在应该可以工作了。

You need to setup a token for go get or go mod to download private repos, thats why you're getting a 404您需要为 go get 或 go mod 设置一个令牌来下载私人存储库,这就是您获得 404 的原因

Then you need to configure git to use that token.然后您需要配置 git 以使用该令牌。

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

I don't use dep, but you should use go mod download instead of go get or dep since you have a mod file.我不使用 dep,但你应该使用 go mod download 而不是 go get 或 dep 因为你有一个 mod 文件。

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

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