Stopping GitLab from skipping Git submodules during CI job?
Asked Answered
D

2

10

I'm testing out deploying a Hexo site on GitLab Pages. I'm currently using a theme that someone has posted to GitHub, and thus have a Git submodule in the themes folder of my Hexo project such that the top-level .gitmodules file looks like:

[submodule "themes/Hacker"]
    path = themes/Hacker
    url = https://github.com/CodeDaraW/Hacker.git

I'm using the Hexo doc's recommended YAML file (updated for current Node) for CI settings, and the CI job seems to go smoothly except that it randomly decides to skip Git submodules setup:

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

This prevents the site from properly generating the HTML/CSS files because no theme is present:

$ 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

How do I ensure that GitLab actually loads the Git submodule properly so that my theme loads?

Dorkus answered 20/6, 2021 at 2:11 Comment(3)
Did you try googling your question?Inexertion
I did, and I saw the reference you mentioned, but I might have skimmed reading it too quickly.Dorkus
There's not enough documentation. There's too much documentation.Inexertion
I
22

From gitlab documenation Using Git submodules with GitLab CI/CD:

Use Git submodules in CI/CD jobs

To make submodules work correctly in CI/CD jobs:

  1. Make sure you use relative URLs for submodules located in the same GitLab server.

  2. You can set the GIT_SUBMODULE_STRATEGY variable to either normal or recursive to tell the runner to fetch your submodules before the job:

    variables:
         GIT_SUBMODULE_STRATEGY: recursive
    

Also see https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-submodule-strategy .

Inexertion answered 20/6, 2021 at 15:57 Comment(0)
D
3

I resolved my issue by adding a line to .gitlab-ci.yml to update the Git submodule before continuing with the rest of the script.

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
Dorkus answered 20/6, 2021 at 12:53 Comment(1)
guess: you'll want to change git submodule update --init to git submodule update --init --recursiveIngathering

© 2022 - 2024 — McMap. All rights reserved.