Host on GitHub Pages guide seems to be outdated

Hi everyone,

I have a Github repo where there are a few markdowns that I want to deploy as static sites on GitHub Pages using Hugo. I have gone through Host on GitHub Pages | Hugo and tried to use that in Github actions however, it’s failing at the Hugo build step considering the Hugo site is not initiated.

I have made some changes to make it work but now my GitHub page shows a 404 page not found. I have set Github Pages to be deployed from Github Actions.

Can someone help me with what’s wrong here?

# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Github Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches:
      - main

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

# Default to bash
defaults:
  run:
    shell: bash

jobs:
  # Build job
  build:
    runs-on: ubuntu-latest
    env:
      HUGO_VERSION: 0.121.0
    steps:
      - name: Install Hugo CLI
        run: |
          wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
          && sudo dpkg -i ${{ runner.temp }}/hugo.deb          
      - name: Install Dart Sass
        run: sudo snap install dart-sass
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Init Hugo Site
        id: hugo-init
        run: |
          hugo new site documentation
          cd documentation
      - name: Copy markdown content
        id: copy-content
        run: |
          cp -r docs documentation/content/
      - name: Setup Pages
        id: pages
        uses: actions/configure-pages@v4
      - name: Install Node.js dependencies
        run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
      - name: Build with Hugo
        env:
          # For maximum backward compatibility with Hugo modules
          HUGO_ENVIRONMENT: production
          HUGO_ENV: production
        run: |
          cd documentation
          hugo \
            --gc \
            --minify \
            --baseURL "${{ steps.pages.outputs.base_url }}/"          
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v2
        with:
          path: ./

  # Deployment job
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v3

It is not. The workflow file is used by hundreds (if not thousands) of sites. This is a test site using the documented workflow file (verbatim):

https://github.com/jmooring/hosting-github-pages

I’m not sure what that means. You’ll need to provide more information (logs, link to repo, etc.).

The issue I was facing was this

I expect to not push the entire content of Hugo’s site back to the repo, but I want to generate it at runtime in Github action and publish it to Github pages.

It’s telling you that it can’t find the site configuration file in the pwd.

@jmooring yes exactly, as I haven’t pushed the content after running hugo init site to Github repo. Hence I added that as part of Github actions but then the deployed site is showing 404.

Is it possible to just push markdown files without configs for Hugo, and generate the config and deploy the website from Github Actions?

Before I spend any time on this, why are you doing it this way? There might be a much simpler approach.

@jmooring essentially I am developing a composite action that can generate Github pages for any repo without pushing all the configs to each repo. The expectation is this composite works as plug and play for any repo to generate Github Pages.

I am open to hearing about other simpler approaches. Also I am new to this so some of my questions might be very basics

So, that’s not something I’m going to spend any time on… perhaps someone else can help you. But going back to your error, you need a config file/dir in the working directory, or pass its location as a CLI flag.