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

Time:07-20

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/[email protected]
        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 

CodePudding user response:

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.

  • Related