首页 > 解决方案 > 如何在 Github Actions 中获取子模块的最新提交文件,以便在构建过程中使用它?

问题描述

最近我创建了一个依赖于来自另一个存储库的数据的 React 网站。所以我在我自己的 Github 存储库中添加了这个远程存储库作为子模块。这个子模块的文件在我建网站的时候用到。在本地,我目前使用以下流程将远程文件合并到我的构建中:

cd public/remote-data
git pull
cd ../..
yarn build

瞧,子模块的文件被烘焙到我的构建中。

现在,我想在 Github Actions 中自动化这个过程,这样每次提交都会触发一个新的构建,其中包含来自远程存储库的最新数据。为此,我尝试使用 checkout 操作中的Checkout multiple repos (nested)功能,并结合一些 yarn 命令来安装依赖项并构建网站:

- name: Checkout tools repo
  uses: actions/checkout@v2
  with:
    repository: remote-org/remote-data
    path: public/remote-data
- uses: Borales/actions-yarn@v2.1.0
  with:
    cmd: install
- uses: Borales/actions-yarn@v2.1.0
  with:
    cmd: build

但是,当我尝试这样做时,似乎 Github Actions 的整个上下文都转移到了远程存储库。因此,以下yarn install命令yarn build无法按预期工作,因为它们需要正确的文件夹上下文才能正常工作。

那么我的问题是:使用 Github Actions,我如何在我自己的存储库的构建过程中使用远程存储库的最新版本?

PS。如果您觉得使用结帐操作不是要走的路,请随意建议另一种方法来达到想要的结果。

标签: gitgithubgit-submodulesgithub-actions

解决方案


使用以下步骤签出带有子模块的存储库:

- name: Checkout
  uses: actions/checkout@v2
  with:
    # Whether to checkout submodules: `true` to checkout submodules or `recursive` to
    # recursively checkout submodules.
    submodules: true

来源:https ://github.com/actions/checkout#usage


推荐阅读