Jon*_*rey 9 git git-submodules gitlab hexo
我正在测试在 GitLab Pages 上部署 Hexo 站点。我目前正在使用某人发布到 GitHub 的主题,因此themes我的 Hexo 项目的文件夹中有一个 Git 子模块,因此顶级.gitmodules文件如下所示:
[submodule "themes/Hacker"]
path = themes/Hacker
url = https://github.com/CodeDaraW/Hacker.git
Run Code Online (Sandbox Code Playgroud)
我正在使用 Hexo 文档推荐的 YAML 文件(针对当前 Node 进行更新)进行 CI 设置,并且 CI 作业似乎进展顺利,只是它随机决定跳过 Git 子模块设置:
Getting source from Git repository 00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/jjeffrey/jjeffrey.gitlab.io/.git/
Created fresh repository.
Checking out 76f8757a as master...
Skipping Git submodules setup
Restoring cache 00:01
Checking cache for default...
FATAL: file does not exist
Run Code Online (Sandbox Code Playgroud)
这会阻止网站正确生成 HTML/CSS 文件,因为不存在主题:
$ hexo generate
INFO Validating config
INFO Start processing
INFO Files loaded in 100 ms
WARN No layout: 1970/01/01/hello-world/index.html
WARN No layout: 1970/01/01/test_new/index.html
WARN No layout: archives/index.html
WARN No layout: archives/1970/index.html
WARN No layout: archives/1970/01/index.html
WARN No layout: index.html
INFO Generated: archives/index.html
INFO Generated: archives/1970/index.html
INFO Generated: archives/1970/01/index.html
INFO Generated: index.html
INFO Generated: 1970/01/01/hello-world/index.html
INFO Generated: 1970/01/01/test_new/index.html
INFO 6 files generated in 13 ms
Run Code Online (Sandbox Code Playgroud)
如何确保 GitLab 实际上正确加载 Git 子模块以便加载我的主题?
Kam*_*Cuk 20
来自gitlab 文档Using Git submodules with GitLab CI/CD:
在 CI/CD 作业中使用 Git 子模块
要使子模块在 CI/CD 作业中正常工作:
确保对位于同一 GitLab 服务器中的子模块使用相对 URL 。
您可以将GIT_SUBMODULE_STRATEGY 变量设置为正常或递归,以告诉运行程序在作业之前获取子模块:
Run Code Online (Sandbox Code Playgroud)variables: GIT_SUBMODULE_STRATEGY: recursive
另请参阅https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-submodule-strategy。
.gitlab-ci.yml我通过在继续脚本的其余部分之前添加一行来更新 Git 子模块来解决我的问题。
image: node:14.17.1
cache:
paths:
- node_modules/
before_script:
- git submodule update --init
- npm install hexo-cli -g
- npm install
pages:
script:
- hexo generate
artifacts:
paths:
- public
only:
- master
Run Code Online (Sandbox Code Playgroud)