简体   繁体   中英

Github Action : golang cannot find package

I set sample github action to my repository. 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 . 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 . I have go.mod , go.sum .

This is not a correct answer for the OP, but may help someone reaching here from searching.

In the root of your go project:

go mod init
go mod tidy

Commit and push to github, and it should work now.

You need to setup a token for go get or go mod to download private repos, thats why you're getting a 404

Then you need to configure git to use that token.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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