Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

Authentication problem when updating private submodule within github actions

My repository includes a submodule, the submodule is a private repository. Whenever a push happens, a test-script is executed using GitHub actions. When GitHub actions updates the submodule, it runs into an authentication problem and cannot access the submodule with GitHub actions.

I followed the discussion on how to authenticate to private repositories, here and here.

Currently, my main issue is how to access and use the personal access token as discussed in the links above.

One of discussion contributors uses a secret.GITHUB_PAT variable, the other one uses secret.CI_PAT. Following this github documentation, there might be a secret.GITHUB_TOKEN but I have no idea how they created the other two.

-> Are they all the same? How do I create these variables and how do I get my correct PAT put into these variables?

Naively running the code from Lauszus reply gives me the following error.

My Code assuming SUBREPO is the submodule,

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout reposistory
      uses: actions/checkout@v2
    - name: Checkout submodule
      run: |
      git config --file=.gitmodules SUBREPO.url https://${{ secrets.GITHUB_TOKEN }}:${{ secrets.GITHUB_TOKEN }}@github.com/COMP/SUBREPO.git
      git submodule sync
      git submodule update --init --recursive

Output

Run git config --file=.gitmodules SUBREPO.url ***github.com/COMP/SUBREPO.git
  git config --file=.gitmodules SUBREPO.url ***github.com/COMP/SUBREPO.git
  git submodule sync
  git submodule update --init --recursive
  shell: /bin/bash -e {0}
Submodule 'SUBREPO' (https://github.com/COMP/SUBREPO.git) registered for path 'MYREPO/SUBREPO'
Cloning into '/home/runner/work/MYREPO/MYREPO/MYREPO/SUBREPO'...
fatal: could not read Username for 'https://github.com': No such device or address
fatal: clone of 'https://github.com/COMP/SUBREPO.git' into submodule path '/home/runner/work/MYREPO/MYREPO/MYREPO/SUBREPO' failed
Failed to clone 'MYREPO/SUBREPO'. Retry scheduled
Cloning into '/home/runner/work/MYREPO/MYREPO/MYREPO/SUBREPO'...
fatal: could not read Username for 'https://github.com': No such device or address
fatal: clone of 'https://github.com/COMP/SUBREPO.git' into submodule path '/home/runner/work/MYREPO/MYREPO/MYREPO/SUBREPO' failed
Failed to clone 'MYREPO/SUBREPO' a second time, aborting
Error: Process completed with exit code 1.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My main issue was the secrets from GitHub, which can be found at settings within ones repository, see picture attached secret setting. I added my PAT as a secret with name <PAT>, so GitHub actions can access it via ${{ secret.<PAT> }}

I further updated my code to use my PAT as follows,

Submodule Code-part for GitHub actions

  uses: actions/[email protected]
  with:
    token: '${{ secrets.<PAT> }}'
    repository: <COMP>/<SUBMOD>
    path: <relative_path_to_submod>
    ref: '<branch>'

End of workflow Output

From https://github.com/<COMP>/<SUBMOD>
* [new branch]      <branch>        -> origin/<branch>
/usr/bin/git branch --list --remote origin/<branch> origin/<branch>
/usr/bin/git checkout --progress --force -B <branch> refs/remotes/origin/<branch>
Switched to a new branch '<branch>'
Branch '<branch>' set up to track remote branch '<branch>' from 'origin'.

<COMP> and <SUBMOD> are the user and the submodule repository. <branch> refers to the branch of the submodule you'd like to be tracking.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...