Problems with GitInfo in CI

Hi. I’ve been running into problems with using GitInfo for .LastMod. I’ve enabled enableGitInfo = true in one of my projects. Locally, when using hugo server, my front page looks correct, so all pages have their appropriate .LastMod according to the latest git commit of their markdown file, e.g.:

First post: posted 12/22 - updated 12/24
Second post: posted 12/16 - updated 12/17
Third post: posted 12/14 - updated 12/17

When pushing it to my GitHub which deploys the website to gh-pages using GitHub Actions, the .LastMod for all pages results in the deployment datetime, e.g. for today 12/25:

First post: posted 12/22 - updated 12/25
Second post: posted 12/16 - updated 12/25
Third post: posted 12/14 - updated 12/25

I tried it using the --enableGitInfo flag instead of the config.toml option but the results are the same. --debug does not show anything related. Any ideas why the .Lastmod is wrong inside the CI?

By default, the GitHub “checkout” action only fetches a single commit (for the ref/SHA that triggered the workflow). This results in the behavior you describe – i.e. the current date/time is used for .Lastmod.

If you modify the checkout action to fetch the entire history (by specifying fetch-depth: 0), then .GitInfo and .Lastmod works as expected:

jobs:
  build_and_deploy_job:
    ...
    steps:
      - uses: actions/checkout@v2
        with:
          ...
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod