简体   繁体   English

Github 操作,dep 安装问题

[英]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.您有两种方法可以解决此问题。

  1. (Preferred) Update your project to use go.mod. (首选)更新您的项目以使用 go.mod。 It's the newer, nicer dependency management solution in go and doesn't require your project to be in GOPATH .它是 go 中更新、更好的依赖管理解决方案,并且不需要您的项目位于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.tomlGopkg.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.modgo.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.它应该工作。

  1. Set the 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM