GoReleaser和ssh-agent Github Actions:为什么无法读取用户名…终端提示被禁用?

huangapple go评论80阅读模式
英文:

GoReleaser and ssh-agent Github Actions: Why could not read Username ... terminal prompts disabled?

问题

我一直在GitHub Actions、GoReleaser和Ssh-Agent之间循环往复,但无法使我的简单发布构建脚本正常工作。我的目标很简单...我有一个包含CLI应用程序的go私有存储库,它的go.mod文件依赖于我们创建的另一个私有存储库。在本地构建应用程序是成功的。

问题是,当我尝试在GitHub Action中构建这个简单的应用程序时,事情变得非常复杂...存储库密钥、部署密钥和其他一些移动部分。尽管这种用例非常常见,但我找不到一个单一的示例,其中有人实现了一个用于发布构建脚本的示例...我准备因为沮丧而切换到单一存储库。

细节...GitHub构建脚本在使用GoReleaser进行实际构建之前正常工作,但在构建过程中失败,出现以下错误:

"release failed after 6serror=hook failed: go mod tidy: exit status 1; output: go: downloading..."

"fatal: could not read Username for 'https://github.com': terminal prompts disabled"

据我了解,Ssh-Agent应该使用我在我们的帐户中配置的SSH私钥设置访问权限。因此,GoReleaser应该可以轻松访问包含SSH公钥的任何存储库。

我非常感谢您帮助我使所有这些移动部分协同工作。我相信还有很多其他人在处理这个问题。

谢谢您的时间和关注。

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 and 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 
英文:

I have been going around and around between instructions for GitHub Actions, GoReleaser, and Ssh-Agent and cannot get my simple release build script to work. My goal is simple... I have a go private repository containing a CLI application and its go.mod file has a dependency on another private repository that we've created. Building the application locally is successful.

The issue is that when I try to build this simple application in a GitHub Action, things become really complicated very quickly... repository secrets, deploy key, an a few other moving parts. As common as this use-case is, I failed to find a single example where someone has implemented a release build script for it... I am about ready to switch to a mono-repo out of frustration.

Details... The github build script works properly until the actual build using GoReleaser, which fails with the following:

"release failed after 6serror=hook failed: go mod tidy: exit status 1; output: go: downloading..."

and

"fatal: could not read Username for 'https://github.com': terminal prompts disabled"

From my understanding, 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.

I would really appreciate your help in getting all of these moving parts to work together. I am sure that there are a lot of other folks wrangling with this issue, too.

Thanks for your time and 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 and 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 

答案1

得分: 0

我建议在Github操作中为私有模块配置git,可以在工作流程中添加一个简单的步骤,如下所示:

  - name: 配置git以用于私有模块
    env:
      GITHUB_API_TOKEN: ${{ secrets.GH_API_TOKEN }}
    run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"

并且在存储库中添加GH_API_TOKEN密钥,以便在执行go mod tidy命令期间能够下载go模块。

英文:

I would suggest to Configure git for private modules in the Github action, adding one simple step in your workflow like:

  - 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"

And add the GH_API_TOKEN secrets in the repo in order to be able to download the go modules during the go mod tidy command.

huangapple
  • 本文由 发表于 2022年7月19日 15:38:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/73032911.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定