当前位置: 首页 > 知识库问答 >
问题:

github - gitHub action checkout@3 submodules 问题?

乌靖
2023-08-31

使用github action 进行CI编译时, 项目使用了 git submodule 子模块
在进行编译的时候总是报错,找不到

  /usr/bin/git submodule sync  /usr/bin/git -c protocol.version=2 submodule update --init --force --depth=1  Submodule 'src/***-setting' (***github.com/****-setting.git) registered for path 'src/dpqd-mdc-common-ui-setting'  Cloning into '/home/runner/work//************/src//************g'...  remote: Repository not found.  Error: fatal: repository 'https://github.com//************.git/' not found  Error: fatal: clone of '***github.com/*****-setting.git' into submodule path '/home/runner/work/****/src/****-setting' failed  Failed to clone 'src/****-setting'. Retry scheduled  Cloning into '/home/runner/work/****/src/****-setting'...  remote: Repository not found.  Error: fatal: repository 'https://github.com/****-setting.git/' not found  Error: fatal: clone of '***github.com/****-setting.git' into submodule path '/home/runner/work/****/src/****-setting' failed  Failed to clone 'src/****-setting' a second time, aborting  Error: The process '/usr/bin/git' failed with exit code 1

部分 cicl.yml

jobs:  # This workflow contains a single job called "build"  build:    # The type of runner that the job will run on    runs-on: ubuntu-latest    # Steps represent a sequence of tasks that will be executed as part of the job    steps:      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it      - uses: actions/checkout@v3        with:          submodules: 'true'          token: ${{ secrets.GITHUB_TOKEN }}      # Runs a single command using the runners shell      - name: Run a one-line script        run: echo start build the project!

.gitsubmodules 文件

[submodule "src/****-setting"]    path = src/***-setting    url = https://******@github.com/***/***-setting.git    branch = DEV

根据文档也设置了 token, 但是还是报错, 请教大佬们了。

共有1个答案

公冶威
2023-08-31

根据你提供的错误信息,看起来是因为在 GitHub Action 的环境中,子模块的仓库无法被访问,导致克隆失败。

在 GitHub Action 中,你可以使用 ${{ secrets.GITHUB_TOKEN }} 提供的令牌来访问该仓库和子模块。但是需要注意的是,该令牌默认情况下不具备对其他仓库的访问权限。因此,如果子模块所在的仓库和你的主仓库不属于同一个组织或用户,可能会导致无法访问子模块。

解决方法之一是为子模块添加一个 Personal Access Token(PAT),该 Token 必须具备访问子模块仓库的权限。然后在 GitHub Action 的配置文件中设置一个新的环境变量来存储该 PAT,并使用它来克隆子模块。

以下是一个示例配置文件的修改:

jobs:  build:    runs-on: ubuntu-latest    steps:      - name: Check out repository        uses: actions/checkout@v2        with:          submodules: recursive      - name: Set up PAT        env:          ACCESS_TOKEN: ${{ secrets.PAT }} # PAT 是你自己的 Personal Access Token        run: git config --global submodule."src/****-setting".oauth-token ${ACCESS_TOKEN}      - name: Update submodules        run: git submodule update --recursive --remote

在这个示例中,通过 git config 命令设置子模块的访问令牌为 ${ACCESS_TOKEN} 环境变量中的值。然后使用 git submodule update --recursive --remote 命令来确保子模块的最新版本被克隆。

请确保在 Secrets 页面中添加了名为 PAT 的仓库级别机密,并将 Personal Access Token 的值作为该机密的内容。

 类似资料:
  • 我试图用Github Api做一个授权请求,传递用户名和密码。但它不起作用,我得到了401状态代码。 文件里有一部分说 这是我的密码:

  • 每当我尝试推送到我的存储库时,我都必须一次又一次地登录。 如果我解开上面的复选框,那么它只会正常工作,但仍然会再次要求我输入用户名和密码,这并不理想。 PC配置:--VSCode版本:1.45 Debian-操作系统版本:Ubuntu 18.04

  • 2.Github使用代码https://reduxapp.herokuapp.com/auth/callback?code=9536286A59228E7784A1重定向回来,并触发githubSendCode('9536286A59228E7784A1')操作 你可以在网络呼叫选项中看到呼叫是通过的,但POST呼叫从来没有发生过。然后出现控制台错误: 下面是我的操作函数:

  • 我在我的Raspberry Pi上克隆了GitHub上的一个项目,创建了一个新的分支,并将所有内容推送到存储库中。为此,我需要下一个命令: 我遇到的问题是我无法将分支推到GitHub.com。我需要输入我的用户名和密码,但我不能使用2FA。这是Git或GitHub中的一个bug吗?是否有方法获得身份验证密钥并输入它? 我不会在GitHub上启用2fa。

  • 在一个脚本中,我试图用oauth令牌克隆Github存储库。 根据本教程: https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth 我应该能够像这样为它构建一个命令: 如果我使用正确的访问令牌手动尝试此操作,它仍会询问我的密码。 如果我在命令行上尝试它,我只是得到一个没有找到