Sunday, May 2, 2021

github actions and golang 1.16 or higher - no required module provides package - working directory is not part of a module.

In your environment your app might work out of the box for go 1.16.x but github actions it might say:
main.go:20:2: no required module provides package github.com/myuser/project/pkg/deployment: working directory is not part of a module.

In go lang 1.16 GO111COMPILE is on by default which means the packages will be stored via GOPATH/go/pkg or for example /home/foobar/go/pkg/github.com/mypackagelibrary. To make it work via github actions use:

jobs:

  my-job-name:

    runs-on: [ ubuntu-18.04 ]

    env:

      GOPATH: /home/runner/work/MYPACKAGELIBRARYNAME/go

      GO111MODULE: auto


....

OR 

for every go command, including get, build, run add GO111MODULE=off in front, like GO111MODULE=off go get github.com/foobar && GO111MODULE=off go run main.go