我一直在GitHub操作、GoReleaser和Ssh代理的指令之间徘徊,无法让我的简单发布构建脚本正常工作.我的目标很简单...我有一个go私有存储库,其中包含一个CLI应用程序及其go.mod file依赖于我们创建的另一个私有存储库.在本地构建应用程序是成功的.

问题是,当我try 在GitHub操作中构建这个简单的应用程序时,事情很快就会变得非常复杂...存储库机密、部署密钥和其他一些移动部件.尽管这个用例很常见,但我没有找到一个示例,其中有人为它实现了发布构建脚本...出于沮丧,我准备转向单一回购.

细节...github构建脚本在使用GoReleaser进行实际构建之前一直正常工作,但最终失败如下:

"6serror=hook失败后释放失败:go mod tidy:退出状态1;输出:go:下载…"

"致命:无法读取'https://github.com":终端提示已禁用"

From my underst和ing, Ssh-Agent should be setting up access using the SSH private key that I've configured in our account. Hence, GoReleaser should have no trouble accessing any repository that has a DEPLOY_KEY containing the SSH public key.

我非常感谢您的帮助,让所有这些移动部件一起工作.我确信还有很多其他人也在为这个问题争论.

Thanks for your time 和 interest

name: Release

on:
  push:
    tags:
      - "v*.*.*"

jobs:
  build:
    name: Build Release Binaries
    runs-on: ubuntu-latest
    permissions:
      contents: write
      #packages: write
    steps:

      - name: Install SSH Client
        uses: webfactory/ssh-agent@v0.5.4
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}


      - name: Configure Go 1.18
        uses: actions/setup-go@v3
        with:
          go-version: 1.18

      - name: Debug
        run: |
          pwd
          echo ${HOME}
          echo ${GITHUB_WORKSPACE}
          echo ${GOPATH}
          echo ${GOROOT}

      - name: Debug2
        run: go env

      - name: Check out the code into the Go module directory.
        uses: actions/checkout@v3
        with:
          repository: 'myorg/myrepo'
          fetch-depth: 0            # See: https://goreleaser.com/ci/actions/
          path: go/src/github.com/myorg/myrepo

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v3
        with:
        # either 'goreleaser' (default) or 'goreleaser-pro'
          distribution: goreleaser
          version: latest
          args: release --rm-dist
          workdir: ${{ github.workspace }}/go/src/github.com/myorg/myrepo
        env:
          GITHUB_TOKEN: ${{ secrets.TOKEN }}
Run goreleaser/goreleaser-action@v3
  with:
    distribution: goreleaser
    version: latest
    args: release --rm-dist
    workdir: /home/runner/work/myrepo/myrepo/go/src/github.com/myorg/myrepo
    install-only: false
  env:
    SSH_AUTH_SOCK: /tmp/ssh-HIEFX12pQLiS/agent.1733
    SSH_AGENT_PID: 1734
    APP_VERSION: v2.1.3
    BUILD_TIME: Tue Jul 19 07:03:53 UTC 2022
    GITHUB_TOKEN: ***
  
Downloading https://github.com/goreleaser/goreleaser/releases/download/v1.10.2/goreleaser_Linux_x86_64.tar.gz
Extracting GoReleaser
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/0d57d027-19c9-4eee-b395-8e6b3c534c98 -f /home/runner/work/_temp/2d3cd5e7-7087-4ff0-b2db-c036bb8c5bc8
GoReleaser latest installed successfully
Using /home/runner/work/myrepo/myrepo/go/src/github.com/myorg/myrepo as working directory
v2.1.3 tag found for commit 'b94e310'
/opt/hostedtoolcache/goreleaser-action/1.10.2/x64/goreleaser release --rm-dist
  •starting release...
  • loading config file                              file=.goreleaser.yaml
  •loading environment variables
  •getting 和 validating git state
    • building...                                    commit=b94e310435835d012155fce67176ef54a687326e latest tag=v2.1.3
  •parsing tag
  •setting defaults
  •running before hooks
    • running                                        hook=go mod tidy
    •took: 6s
  ⨯release failed after 6serror=hook failed: go mod tidy: exit status 1; output: go: downloading 

推荐答案

我建议在Github操作中添加Configure git for private modules,在您的工作流中添加一个简单的步骤,如:

  - name: Configure git for private modules
    env:
      GITHUB_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
    run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"

并在repo中添加GH_API_TOKEN个秘密,以便能够在go mod tidy命令期间下载go模块.

Go相关问答推荐

在Golang中,@LATEST和@UPGRADE特殊查询有什么不同?

难以为多个平台添加Go Bazel构建选项

创建服务时云运行触发器执行失败

是不是有什么原因导致`Strings.EqualFold`不先进行长度比较?

GO框架Echo中间件的使用

使用!NOT运算符的Golang文本/模板多个条件

Kafka架构注册表-Broker:Broker无法验证记录

如何解析Go-Gin多部分请求中的 struct 切片

有没有办法让sqlc生成可以使用pgxpool的代码

Go 中如何判断 struct 体是否包含另一个 struct 体?

Golang text/template中的startswith函数 - 入门教程

在 Go 中解组编号的 XML 标签

如何在 fyne-io/fyne 中设置文本的字母间距?

Golang 到 wasm 编译使用 tinygo.使用 wasmtime 执行

如何在 Go 中编写示例测试?

Go http.FileServer 给出意外的 404 错误

如何在 golang 中同时加载 .env 文件和 os 环境变量

是否可以使用按位运算在随机 unicode 字符串中找到重复字符?

HTTP 重定向不呈现新页面

为什么在 unsafe.Sizeof() 中取消引用 nil 指针不会导致panic ?