[英]Github actions, problem with dep installing
I have this go.yml for github actions我有这个 go.yml 用于 github 动作
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.它构建时出现错误:home/runner/work/project/project 不在已知的 GOPATH/src 中错误:进程已完成,退出代码为 1。
How to fix it problem?如何解决它的问题?
The default value of GOPATH
is $HOME/go
. GOPATH
的默认值为$HOME/go
。
Your project folder is outside of this GOPATH
hence the error.您的项目文件夹位于此
GOPATH
之外,因此出现错误。
You have two ways to fix this problem.您有两种方法可以解决此问题。
GOPATH
.GOPATH
中。 Assuming you are using Go version newer than 1.12, Remove the Gopkg.toml
and Gopkg.lock
(if you have it).假设您使用的是高于 1.12 的 Go 版本,请删除
Gopkg.toml
和Gopkg.lock
(如果有的话)。
Run,跑,
a.一个。
go mod init <project-name>
Replace <project-name>
with the name of your project. go mod init <project-name>
将<project-name>
name> 替换为您的项目名称。
b.湾。 Run
go mod tidy
and it'll add all the dependencies you are using in your project.运行
go mod tidy
它将添加您在项目中使用的所有依赖项。
c. c。 Run
go build
once to make sure your project still builds.运行
go build
一次,以确保您的项目仍然可以构建。 If it doesn't, You can add the missing dependencies manually in go.mod
.如果没有,您可以在
go.mod
中手动添加缺少的依赖项。
Commit go.mod
and go.sum
(if you need deterministic builds).提交
go.mod
和go.sum
(如果您需要确定性构建)。
Removed this from your CI config,从您的 CI 配置中删除它,
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
and just build the project.并构建项目。 It should work.
它应该工作。
GOPATH
correctly in your CI config before calling dep ensure
.dep ensure
之前,在 CI 配置中正确设置GOPATH
。 I think GOPATH=/home/runner/work/project/project
should work but I am not aware of the exact specifics related to GOPATH
so you'll just have to try.GOPATH=/home/runner/work/project/project
应该可以工作,但我不知道与GOPATH
相关的确切细节,所以你只需要尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.