如何在 GitHub 操作中签出子模块?

Nel*_*mbo 0 git github github-actions

我有一个带有子模块的存储库,当我推送到某些分支或标签时,我正在创建一个构建。我遇到的问题是我的结帐步骤无法访问我的子模块。设置是:

  1. 两个存储库都在 GitHub 上。
  2. 我是两个存储库的所有者。
  3. 两个存储库都是私有的。
  4. 存储库只能通过 ssh(禁用 https)访问。

我试过使用 GitHub Actionactions/checkout@v2无济于事。如下所示,我尝试使用“ssh-key”选项,其中我已将公钥添加到子模块存储库部署密钥,并将私钥添加到我运行操作的存储库的机密中。我收到以下错误消息:

Fetching the repository
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin __myrepo__
  ERROR: Repository not found.
  Error: fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  The process '/usr/bin/git' failed with exit code 128
  Waiting 13 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin __myrepo__
  ERROR: Repository not found.
  Error: fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  The process '/usr/bin/git' failed with exit code 128
  Waiting 19 seconds before trying again
  /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin __myrepo__
  ERROR: Repository not found.
  Error: fatal: Could not read from remote repository.
  
  Please make sure you have the correct access rights
  and the repository exists.
  Error: The process '/usr/bin/git' failed with exit code 128
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用和不使用ssh-key以及使用truerecursive选项submodules。子模块的目标位于名为src. 我的工作流程中的结帐步骤如下:

Step-01:
  runs-on: ubuntu-18.04
  steps:
    - name: Checkout repository
      uses: actions/checkout@v2
      with:
        submodules: 'true'
        ssh-key: ${{ secrets.PRIVATE_KEY_FOR_DEPLOY_KEY_IN_SUBMODULE }}
Run Code Online (Sandbox Code Playgroud)

.gitmodules 是:

[submodule "name"]
    path = src/name
    url = git@github.com:user/repository.git
    branch = master
Run Code Online (Sandbox Code Playgroud)

我对 GitHub Actions(整体 CI/CD)非常陌生,对子模块不太满意,所以我很可能犯了一些基本错误。

Nel*_*mbo 5

我终于让它工作了,完全感谢这个

为了澄清情况,SAML SSO 被强制执行。因此,我没有使用 SSH 尝试访问子模块,而是使用了 SSO 已获得授权的个人访问令牌 (PAT)。

我做了什么:

  1. 我在帐户设置中生成了 PAT。
  2. 我启用了 SSO 并对其进行了授权。
  3. 我在存储库(想要访问子模块)秘密中添加了令牌。
  4. 我将工作流程更新为以下内容(只需更改 ssh-key 行)。

Step-01:
  runs-on: ubuntu-18.04
  steps:
    - name: Checkout repository
      uses: actions/checkout@v2
      with:
        submodules: 'true'
        token: ${{ secrets.PAT_TOKEN }}
Run Code Online (Sandbox Code Playgroud)


use*_*448 5

我对 github actions 很陌生,这是我喜欢的解决方案。

1. 按如下方式更新 CI 配置:

steps:
- uses: actions/checkout@v3
  with:
    submodules: recursive
    token: ${{ secrets.PAT_TOKEN }}
Run Code Online (Sandbox Code Playgroud)

2. 生成个人访问令牌 (PAT)

设置 -> 开发者设置 -> 个人令牌(经典)

然后Generate New Token(经典)。

然后使用repo复选框就是我用的。你也许可以少花钱。然后,一旦创建,COPY令牌就会被添加到剪贴板。将其粘贴到某个地方以便妥善保管。

3. 存储您的个人访问令牌 (PAT)

  1. 转到包含子模块的存储库
  2. 前往设置
  3. 在侧栏中,展开 Secrets and Variables
  4. 单击操作
  5. 添加您的“新存储库机密”PAT_TOKEN,以及从 PAT 复制的值。

  • 这对我来说失败了“致命:无法读取“https://github.com”的用户名:没有这样的设备或地址” (3认同)