How do I get a Yocto build to access a private GitHub repo when using Actions?

Viewed 1063

In my workflow I can clone the repos and submodules fine and the build starts but when a recipe that pulls from our GitHub private repos run, I get an error (all out repos are peers to one another in the same Organization). Note that the recipes that clone from the Internet are working fine and it builds fine when I clone and build locally. It's just when I use GitHub Actions I get the following error.

Cloning into bare repository '/home/runner/yocto_cache/downloads/git2/github.com.xxxxx.yyyyy.git'...
fatal: could not read Username for 'https://github.com': No such device or address

Recipe is like...

SRC_URI = "git://github.com/xxxxx/yyyyy.git;protocol=https;nobranch=1;subpath=<folder>/<folder>;rev=${BUILD_REV}"

Workflow

  build:
    runs-on: ubuntu-latest
    steps:  
    - uses: actions/checkout@v2
      with:
        token: ${{ secrets.REPO_ACCESS }}
        submodules: recursive
    
    - name: Configure Git
      run: |
        git config --unset-all "http.https://github.com/.extraheader"
        git config --add "http.https://github.com/.extraheader" "AUTHORIZATION: \ 
            Basic $(base64 <<< ${{ secrets.REPO_ACCESS }}:x-oauth-basic)"
               
    - name: Running on VM
      env:
        CC: gcc-9
      run: |
        sudo apt-get install -y diffstat
        gcc --version
        ./yocto-setup.sh
        source ./poky/oe-init-build-env
        bitbake image

I'm having issues finding answers to this specific failure and wondering if someone out there has run into something similar and can provide some assistance.

1 Answers

Judging from the error message

fatal: could not read Username for 'https://github.com': No such device or address

it seems that your private repository located at $SRC_URI wants the Git client (used internally by BitBake) to authenticate itself so it asked for credentials to be provided on the terminal input. GitHub actions are run in a non-interactive mode so there's no terminal input available (thus the error message):

No such device or address

To overcome this, if you want to access your private Git repository by HTTP(S) protocol without providing the credentials on the terminal input then you have to configure git to include basic access authentication header in the HTTP request.

The authentication header can be configured using http.extraHeader git-config option. You can do it directly in your build job by simply adding this extra step before Running on VM:

- name: Configure Git
  run: |
    git config --unset-all "http.https://github.com/.extraheader"
    git config --add "http.https://github.com/.extraheader" \
              "AUTHORIZATION: Basic $(base64 <<< ${{ secrets.REPO_ACCESS }}:x-oauth-basic)"
- name: Running on VM
...

After adding the above the Running on VM step should succeed with git cloning operation.

(I'm assuming that provided GitHub REPO_ACCESS secret is the access token with at least read access to the private repository denoted by $SRC_URI).

You can read more about access tokens here and here.

Related