Hugo serve randomly fails to load pages and alias

Hi folks,

Ever since updating to Hugo over the last weeks (v112) I think, my Github build is randomly failing. Does anyone have a clue of what I might be doing wrong?

Comparing the logs (working vs not working), I see this line is missing when the build fails

Write redirect to main language en: //localhost:1313/en/

The command I execute in a custom Github Action is listed below. I run hugo serve because I need hugo to be up and running so I can execute Muffet (broken link checker).

hugo server --config hugo.toml --configDir config \
--disableKinds=taxonomy,term,rss,sitemap,robotsTXT --disableBrowserError \
--disableLiveReload --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false \
 -e development

This is what a broken build looks like (on ubuntu), you will see only one page and one alias is being generated.

Start building sites … 
hugo v0.113.0+extended linux/amd64 BuildDate=unknown
INFO 2023/06/12 10:47:46 syncing static files to /
INFO 2023/06/12 10:47:46 process in 67 ms
INFO 2023/06/12 10:47:46 assemble in 79 ms
INFO 2023/06/12 10:47:46 render in 2 ms
INFO 2023/06/12 10:47:46 postProcess in 0 ms

                   |  EN  |  FR   
-------------------+------+-------
  Pages            |    1 |    0  
  Paginator pages  |    0 |    0  
  Non-page files   |    0 |    0  
  Static files     | 1299 | 1299  
  Processed images |    0 |    0  
  Aliases          |    0 |    0  
  Sitemaps         |    1 |    0  
  Cleaned          |    0 |    0  

Built in 1527 ms
Watching for changes in /home/runner/work/docs/docs/{assets,content,i18n,layouts,package.json,static}
Watching for config changes in /home/runner/work/docs/docs/config/_default
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

This is what a clean build looks like (on my mac)

Start building sites …
hugo v0.113.0+extended darwin/arm64 BuildDate=unknown
INFO 2023/06/12 11:29:22 syncing static files to /
INFO 2023/06/12 11:29:22 process in 84 ms
INFO 2023/06/12 11:29:22 assemble in 133 ms
DEBUG 2023/06/12 11:29:28 Write redirect to main language en: //localhost:1313/en/
INFO 2023/06/12 11:29:28 render in 6531 ms
INFO 2023/06/12 11:29:28 postProcess in 0 ms

                   |  EN  |  FR
-------------------+------+-------
  Pages            | 1281 |    0
  Paginator pages  |    0 |    0
  Non-page files   |  222 |    0
  Static files     | 1301 | 1301
  Processed images |    2 |    0
  Aliases          | 1028 |    0
  Sitemaps         |    2 |    0
  Cleaned          |    0 |    0

Built in 6796 ms
Watching for changes in /Users/xxx/dev/docs-temp-2/{assets,content,i18n,layouts,package.json,static}
Watching for config changes in /xxxx/docs-temp-2/config/_default
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at //localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop

This is what my relevant GH Jobs definition looks like.

jobs:
  broken-link-check:
    runs-on: ubuntu-22.04
    name: Check for broken links
    steps:
    - name: Install Hugo and Muffet
      run: |
        mkdir -p ~/bin 
        eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
        brew install hugo --force --quiet
        brew install muffet --force --quiet
      shell: bash
    - uses: actions/checkout@v3
      name: Checkout Repository
      with:
        fetch-depth: 1
    - uses: actions/setup-node@v3
      name: Get NPM (from Cache if available)
      with:
        node-version: 16
        cache: 'npm'
        cache-dependency-path: '**/package-lock.json'
    - uses: actions/cache@v3
      name: Hugo modules cache
      with:
        path: /tmp/hugo_cache
        key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
    - run: |
        npm ci
        npm ls
      name: NPM ci (Docsy pre-requisite)
    - name: Start Hugo Server
      timeout-minutes: 3
      run: |
        touch ${RUNNER_TEMP}/build.output 
        eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
        echo ":hourglass: Waiting for Hugo Server to build and start" >> "$GITHUB_STEP_SUMMARY"
        hugo server --config hugo.toml --configDir config --disableKinds=taxonomy,term,rss,sitemap,robotsTXT --disableBrowserError --disableLiveReload --noBuildLock --noChmod --noTimes --watch=false --enableGitInfo=false -e development >>${RUNNER_TEMP}/build.output 2>&1 &
        sleep 1
        ( tail -f -n0 ${RUNNER_TEMP}/build.output & ) | grep -q "Built in"
        sleep 1
        echo ":white_check_mark: Hugo has finished building the docs website." >> "$GITHUB_STEP_SUMMARY"
      shell: bash

My guess is that this is somehow related to this line hugo/site_render.go at 73779707a2d5fefd4915f8ee2021f265d841dea2 · gohugoio/hugo · GitHub introduced by @bep last month.

I need to dig deeper.

A far fetched attempt, I changed this
DefaultContentLanguage = "en" into this (notice case)
defaultContentLanguage = "en"

Running the same version and same command both locally and with a GitHub Action yields different results?

I haven’t been able to understand the Root Cause just yet.

Local always works.
Github randomly breaks.

To me it looks like your output formats configuration gets blanked out (or at least missing the HTML format).

How that happens is harder to digest. Since it works locally, but fails on GitHub I can just guess that there is some error situation that’s not caught that allows the build to continue with an invalid config state.

Last week I saw a site configuration that looked like this:

[outputs]
page = []

This didn’t have any negative effect < v0.112, but it should have. To me, the config above says, "don’t output any formats for kind = page…

What bugs me is that, within the same PR, across several commits where only docs contents are changed, some builds succeed, while others fail.

I will add some debug logs to see if I can narrow things down.

This is what I have on my local

hugo config -e development

[outputs]
  home = ['html', 'rss']
  page = ['html']
  rss = ['rss']
  section = ['html', 'rss']
  taxonomy = ['html', 'rss']
  term = ['html', 'rss']

On the build that occasionally fails, I get the same result

[outputs]
  home = ['html', 'rss']
  page = ['html']
  rss = ['rss']
  section = ['html', 'rss']
  taxonomy = ['html', 'rss']
  term = ['html', 'rss']

I have created this issue to track this, I suggest we move the discussion here:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.