我有这个用于github操作的go.yml
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 ./...构建时出现错误: home/runner/work/project/project不在已知的GOPATH/src中错误:进程已完成,退出代码为1。
如何解决这个问题?
发布于 2020-11-26 12:17:53
GOPATH的默认值为$HOME/go。
您的项目文件夹在此GOPATH之外,因此出现错误。
您有两种方法来解决此问题。
GOPATH.中
假设您使用的Go版本高于1.12,请删除Gopkg.toml和Gopkg.lock (如果有)。
跑,
a. go mod init <project-name>将<project-name>替换为您的项目名称。
b.运行go mod tidy,它将添加您在项目中使用的所有依赖项。
c.运行一次go build以确保您的项目仍在构建。如果没有,您可以在go.mod中手动添加缺少的依赖项。
提交go.mod和go.sum(如果您需要确定性构建)。
已从您的配置项配置中删除此设置,
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi并且只需构建项目。应该能行得通。
dep ensure之前在您的配置项配置中正确设置了GOPATH。我认为GOPATH=/home/runner/work/project/project应该可以工作,但我不知道与GOPATH相关的具体细节,所以你只能试一试。https://stackoverflow.com/questions/65011370
复制相似问题