使用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, 但是还是报错, 请教大佬们了。
根据你提供的错误信息,看起来是因为在 GitHub Action 的环境中,子模块的仓库无法被访问,导致克隆失败。
在 GitHub Action 中,你可以使用
${{ secrets.GITHUB_TOKEN }}
提供的令牌来访问该仓库和子模块。但是需要注意的是,该令牌默认情况下不具备对其他仓库的访问权限。因此,如果子模块所在的仓库和你的主仓库不属于同一个组织或用户,可能会导致无法访问子模块。解决方法之一是为子模块添加一个 Personal Access Token(PAT),该 Token 必须具备访问子模块仓库的权限。然后在 GitHub Action 的配置文件中设置一个新的环境变量来存储该 PAT,并使用它来克隆子模块。
以下是一个示例配置文件的修改:
在这个示例中,通过
git config
命令设置子模块的访问令牌为${ACCESS_TOKEN}
环境变量中的值。然后使用git submodule update --recursive --remote
命令来确保子模块的最新版本被克隆。请确保在 Secrets 页面中添加了名为
PAT
的仓库级别机密,并将 Personal Access Token 的值作为该机密的内容。