I have this go.yml for github actions
name: Test
on: [push, pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go
- name: Check out code
uses: actions/checkout@v2
- name: Get dependencies
run: |
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
It builds with error: home/runner/work/project/project is not within a known GOPATH/src Error: Process completed with exit code 1.
How to fix it problem?
The default value of
GOPATHis$HOME/go.Your project folder is outside of this
GOPATHhence the error.You have two ways to fix this problem.
GOPATH.Assuming you are using Go version newer than 1.12, Remove the
Gopkg.tomlandGopkg.lock(if you have it).Run,
a.
go mod init <project-name>Replace<project-name>with the name of your project.b. Run
go mod tidyand it'll add all the dependencies you are using in your project.c. Run
go buildonce to make sure your project still builds. If it doesn't, You can add the missing dependencies manually ingo.mod.Commit
go.modandgo.sum(if you need deterministic builds).Removed this from your CI config,
and just build the project. It should work.
GOPATHcorrectly in your CI config before callingdep ensure. I thinkGOPATH=/home/runner/work/project/projectshould work but I am not aware of the exact specifics related toGOPATHso you'll just have to try.