【问题标题】:Authentication problem when updating private submodule within github actions在 github 操作中更新私有子模块时的身份验证问题
【发布时间】:2021-04-16 06:38:42
【问题描述】:

我的存储库包含一个子模块,该子模块是一个私有存储库。 每当推送发生时,都会使用 GitHub 操作 执行测试脚本。 GitHub 操作 更新子模块时,会遇到身份验证问题,无法使用 GitHub 操作访问子模块。

我关注了关于如何对私有存储库进行身份验证的讨论,herehere

目前,我的主要问题是如何访问和使用上面链接中讨论的个人访问令牌。

一位讨论贡献者使用secret.GITHUB_PAT 变量,另一位使用secret.CI_PAT。 在this github documentation 之后,可能会有secret.GITHUB_TOKEN,但我不知道他们是如何创建另外两个的。

-> 它们都一样吗?如何创建这些变量以及如何将正确的 PAT 放入这些变量中?

天真地从Lauszus reply 运行代码会出现以下错误。

我的代码 假设SUBREPO 是子模块,

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

输出

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.

【问题讨论】:

    标签: github git-submodules github-actions


    【解决方案1】:

    我的主要问题是来自 GitHub 的 secrets,可以在存储库中的设置中找到,请参见附图secret setting。我将我的 PAT 添加为名为 的机密,因此 GitHub 操作可以通过 ${{ secret. }}

    访问它

    我进一步更新了我的代码以使用我的 PAT,如下所示,

    GitHub 操作的子模块代码部分

      uses: actions/checkout@v2.0.0
      with:
        token: '${{ secrets.<PAT> }}'
        repository: <COMP>/<SUBMOD>
        path: <relative_path_to_submod>
        ref: '<branch>'
    

    工作流输出结束

    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'.
    

    是用户和子模块存储库。 是指您要跟踪的子模块的分支。

    【讨论】:

      猜你喜欢
      • 2015-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2017-08-29
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多