简体   繁体   中英

Github actions go test cannot find package error. How can I fix this?

I have a simple go package, but during testing within Github Actions, it is failing with this error:

##[error]keywords.go:8:2: cannot find package "github.com/securisec/go-keywords/languages" in any of: .

When I run the tests locally (I am using go mod), all the tests works fine.

For Github actions, I have tried setting GO111MODULE to both on and off , but still getting the same error.

The error can be observed here . My testing workflow is:

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/setup-go@v1.0.0
        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 mod file:

module github.com/securisec/go-keywords

go 1.14

require github.com/grokify/html-strip-tags-go v0.0.0-20200322061010-ea0c1cf2f119

How can I fix this error?

So if you look at the full error messages:

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

You will notice that you are trying to run code in Go 1.10. Go module was introduced in Go 1.11 so it will always complain that the application does not have a dependency installed.

And then if you look at your Go setup log:

Go setup
    GO111MODULE: on
##[warning]Unexpected input 'go-version', valid inputs are ['version']
Run actions/setup-go@v1.0.0
  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

You see that setup is giving a warning and installing go 1.10 for you by default.

That is because you have targeted the specific version v1.0.0 which does not understand the go-version flag. (it was added in v1.1.0 I think)

Solution :

Change uses: actions/setup-go@v1.0.0 to uses: actions/setup-go@v1 to get latest v1 version.

Or even better use v2.

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