skip to Main Content

My GitbHub action job keeps failing at the "git pull" script with the following error:
err: fatal: could not read Username for ‘https://github.com’: No such device or address.

Here’s what my yaml file looks like

name: Deploy to DigitalOcean

on:
  # run it on push to the develop repository branch
  push:
    branches: [develop]
    
  # run it during pull request
  pull_request:
    branches: [develop]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        ssh-key: ${{ secrets.GH_SSH_KEY }}
        fetch-depth: 0
        ref: develop

    - name: Set up Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '18'

    - name: Install dependencies
      run: yarn install

    - name: Build application
      run: yarn build

    - name: Set up Git
      env:
        GIT_AUTH_TOKEN: ${{ secrets.GH_TOKEN }}
      run: |
        git config --global user.email "${{ secrets.GH_USER_EMAIL }}"
        git config --global user.name "${{ secrets.GH_USERNAME }}"

    - name: Deploy application to DigitalOcean
      uses: appleboy/[email protected]
      with:
        host: ${{ secrets.STAGING_SSH_HOST }}
        username: ${{ secrets.STAGING_SSH_USERNAME }}
        key: ${{ secrets.STAGING_SSH_KEY }}
        script: |
          cd my-app
          git switch develop
          git pull
          echo "${{ secrets.STAGING_ENV_FILE }}" > .env
          npm run reload

I am not sure how to solve this, been at this for hours now.

I tried adding the ssh url for the repository to Checkout code step

- name: Checkout code
      uses: actions/checkout@v2
      with:
        ssh-key: ${{ secrets.GH_SSH_KEY }}
        fetch-depth: 0
        repository: [email protected]:My-CoPilot/my_copilot_backend.git
        ref: develop

But that didn’t work either 🙁

2

Answers


  1. Chosen as BEST ANSWER

    Thanks VonC for your answer.

    It turned out that when I logged into my droplet console and ran the "git pull" command, it prompted me to authenticate the github user. After doing that, running "git pull" subsequently went without a hitch or need for authentication.

    So that's all I had to do really.

    When I re-ran the failed job, the "git pull" command this time around did not throw an error, but ran successfully.


  2. The ‘could not read Username for 'https://github.com': means:

    • The remote server where you have ssh’d to is using an HTTPS URL: any SSH key will be irrelevant, and not used at all.
    • The remote server does not have your credentials (GitHub user account/token)

    In other words:

    • the actions/checkout@v2 (using an SSH URL) that you have added is executed on a GitHub runner, a Azure server on Microsoft/GitHub side
    • the appleboy/[email protected] will connect to a remote server (no longer a GitHub runner) and execute your git pull there.

    The local repository in ‘~remoteUser/my-app‘ on that remote server is configured to use HTTPS.
    You could at least add in your script: commands:

    git remote set-url origin [email protected]:My-CoPilot/my_copilot_backend.git
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search