【问题标题】:Github actions, problem with dep installingGithub 操作,dep 安装问题
【发布时间】:2020-11-26 16:31:42
【问题描述】:

我有这个用于 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。

如何解决这个问题?

【问题讨论】:

    标签: go github-actions dep


    【解决方案1】:

    GOPATH 的默认值为$HOME/go

    您的项目文件夹在此 GOPATH 之外,因此出现错误。

    您有两种方法可以解决此问题。

    1. (首选)更新您的项目以使用 go.mod。它是 Go 中更新、更好的依赖管理解决方案,并且不需要您的项目位于 GOPATH

    假设您使用的 Go 版本高于 1.12,请删除 Gopkg.tomlGopkg.lock(如果有的话)。

    运行,

    一个。 go mod init <project-name><project-name> 替换为您的项目名称。

    b.运行go mod tidy,它将添加您在项目中使用的所有依赖项。

    c。运行一次go build 以确保您的项目仍然可以构建。如果没有,您可以在go.mod 中手动添加缺少的依赖项。

    提交 go.modgo.sum(如果您需要确定性构建)。

    从你的 CI 配置中删除了这个,

     if [ -f Gopkg.toml ]; then
                  curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
                  dep ensure
              fi
    

    然后构建项目。它应该可以工作。

    1. 在调用 dep ensure 之前,在 CI 配置中正确设置 GOPATH。我认为 GOPATH=/home/runner/work/project/project 应该可以工作,但我不知道与 GOPATH 相关的具体细节,所以你只需要尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-19
      • 2022-01-22
      • 1970-01-01
      • 2020-07-20
      • 2021-05-12
      • 2021-04-13
      • 2022-11-02
      • 2022-11-09
      相关资源
      最近更新 更多