act icon indicating copy to clipboard operation
act copied to clipboard

Issue: Git commands on private repos cause act to hang up

Open ajrice6713 opened this issue 3 years ago • 3 comments

System information

  • Operating System: macOS latest
  • Architecture: x64 (64-bit)
  • Apple M1: no
  • Docker version: 20.10.12
  • Docker image used in act: ghcr.io/catthehacker/ubuntu
  • act version: act version 0.2.25

Expected behaviour

Should be able to clone/push to private repositories in act

Actual behaviour

Act simply stops dead in its tracks on git clone or git push`

Workflow and/or repository

Workflow Example

name: Listner Test

on:
  workflow_call:
    inputs:
      branch_name:
        description: 'Branch name passed from the caller workflow'
        required: true
        type: string
 
 workflow_dispatch: 
    inputs:
      branch_name:
        description: 'Branch name passed from the caller workflow'
        required: true
        type: string

jobs:
  run_listner_test:
    name: Publish Staging Docsite
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Create and Push Branch
      run: |
        git checkout -b ${{ github.event.inputs.branch_name }}
        mkdir dest-directory
        git clone --branch ${{ github.event.inputs.branch_name }} https://github.com/{my-org}/{my-private-repo} dest-directory
        rm -r dest-directory/*.
        git add .
        git commit -m "Clone Specs from my-private-repo repo"
        git push origin ${{ github.event.inputs.branch_name }}

Steps to reproduce

Call git clone or git pull on a private repository

act output

act -j run_listner_test --secret-file ./.secrets --eventpath ./listener.event
[Listner Test/Publish Staging Docsite] 🚀  Start image=ghcr.io/catthehacker/ubuntu:act-latest
[Listner Test/Publish Staging Docsite]   🐳  docker pull image=ghcr.io/catthehacker/ubuntu:act-latest platform= username= forcePull=false
[Listner Test/Publish Staging Docsite]   🐳  docker create image=ghcr.io/catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Listner Test/Publish Staging Docsite]   🐳  docker run image=ghcr.io/catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Listner Test/Publish Staging Docsite]   🐳  docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root workdir=
[Listner Test/Publish Staging Docsite]   🐳  docker cp src=/Users/arice/Documents/GitHub/my-repo/. dst=/Users/arice/Documents/GitHub/my-repo
[Listner Test/Publish Staging Docsite]   🐳  docker exec cmd=[mkdir -p /Users/arice/Documents/GitHub/my-repo] user= workdir=
[Listner Test/Publish Staging Docsite] ⭐  Run actions/checkout@v2
[Listner Test/Publish Staging Docsite]   ✅  Success - actions/checkout@v2
[Listner Test/Publish Staging Docsite] ⭐  Run Create and Push Branch
[Listner Test/Publish Staging Docsite]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /Users/arice/Documents/GitHub/api-docs-internal/workflow/1] user= workdir=
| Switched to a new branch 'test-branch'
| Cloning into 'dest-directory'...

The run just pauses here and never continues to the next step

I believe it is getting hung up on needing git credentials

I am setting GITHUB_TOKEN in a .env file

# .env file

GITHUB_TOKEN={my secret token}

ajrice6713 avatar Feb 03 '22 20:02 ajrice6713

Running inside of Github Actions i get fatal: could not read Username for 'https://github.com/': No such device or address

Assuming that this is what act is encountering and just not surfacing to the user

I believe my syntax is also incorrect in that i should be using `git clone [email protected]:{username}/{repo}

but i still believe that this error not being surfaced to the user is a bug

ajrice6713 avatar Feb 03 '22 20:02 ajrice6713

Indeed, when your action (or code) tries to clone from a HTTPS endpoint, act will hang waiting for the password prompt. You can set GIT_TERMINAL_PROMPT=0 in the top-level env in your workflow. The error you'll see will be slightly different.

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

I think this env var should be set (in act) by default since github actions are non-interactive anyway.

sosedoff avatar Feb 13 '22 00:02 sosedoff

Issue is stale and will be closed in 14 days unless there is new activity

github-actions[bot] avatar Mar 16 '22 00:03 github-actions[bot]

Same issue here. It hangs when i want to do gh repo clone <my-repo> Even have the issue when using gh auth login (with token) before the clone.

A workaround could be using the following line git clone https://<username>:<PAT>@github.com/<owner>/<repo>.git

BenjaminYdeVintecc avatar Mar 02 '23 09:03 BenjaminYdeVintecc

For anyone still struggling with using private repos, I was building a docker image and scanning with Grype. The building of the docker image required pulling the Dockerfile from the private repo.

When running this with no env vars I'd get: fatal: could not read Username for 'https://github.com': terminal prompts disabled

My solution to this was to run:

GIT_TERMINAL_PROMPT=0
act -j <job_name> -s GITHUB_TOKEN=<github_pat_token>

This allowed the job to succeed.

Hope this helps.

drew-viles avatar Mar 03 '23 09:03 drew-viles