Step 4 of 4 · 10 minutes

Add a deployment action

Add one workflow file so GitHub rebuilds and republishes your site every time Blograker, or anyone, pushes a change.

A GitHub action is a script that runs on GitHub’s computers when something happens in your repo. This one runs on every push: it installs Hugo, builds the site, and hands the result to GitHub Pages. It’s what makes publishing from your phone work. Blograker commits the post, the action builds it, and the site is up to date a minute or two later, with nothing running on your computer.

Do Turn on GitHub Pages first. The deploy step fails until Pages is set to GitHub Actions.

Add the workflow file

In your site’s folder, create .github/workflows/hugo.yaml (note the dot in .github) containing:

name: Deploy Hugo site to GitHub Pages

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      HUGO_VERSION: 0.166.0
    steps:
      - name: Install Hugo
        run: |
          curl -sSL -o "$RUNNER_TEMP/hugo.tar.gz" \
            "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
          mkdir -p "$RUNNER_TEMP/hugo"
          tar -xzf "$RUNNER_TEMP/hugo.tar.gz" -C "$RUNNER_TEMP/hugo"
          echo "$RUNNER_TEMP/hugo" >> "$GITHUB_PATH"

      - name: Check out the site
        uses: actions/checkout@v7
        with:
          submodules: recursive

      - name: Configure Pages
        id: pages
        uses: actions/configure-pages@v6

      - name: Build
        env:
          HUGO_ENVIRONMENT: production
        run: hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}/"

      - name: Upload the site
        uses: actions/upload-pages-artifact@v5
        with:
          path: ./public

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

Two lines to check against your own setup:

  • HUGO_VERSION: set it to the version hugo version printed on your computer, so both build the same way. When you upgrade Hugo locally, bump it here too.
  • branches: [main]: the branch the site lives on. Older repos often use master; change it to match.

Push it

git add .github
git commit -m "Deploy with GitHub Actions"
git push

Open the repo on GitHub and click the Actions tab. You’ll see the run: a yellow dot while it works, a green check when it’s done. Click into it and the deploy box shows a link to the live site.

From now on, every push publishes, whether it comes from Blograker, your computer, or an edit on github.com. To rebuild without a change (say, to publish a post whose scheduled date has arrived), open Actions, pick the workflow, and click Run workflow.

If the run fails

Click the red ✗, then the failed step, to read the log. The usual causes:

What you seeWhat to do
Get Pages site failed or Not Found in Configure Pages or deployPages isn’t set to GitHub Actions. See Turn on GitHub Pages.
Branch "…" is not allowed to deploy to github-pagesThe workflow ran on a branch other than the one Pages allows. Make branches: match your default branch, or add the branch under Settings → Environments → github-pages.
found no layout file warnings, and a blank siteThe theme didn’t come along. Check it was added with git submodule add and that the checkout step keeps submodules: recursive.
TOCSS or Sass errorsThe theme needs Hugo extended. Keep hugo_extended_ in the download URL.
The site builds but styles and links break, on a /myblog/-style addressThe theme assumes the site sits at the root of the domain. Name the repo username.github.io or use a custom domain.

A post doesn’t show up

The build succeeded but a post is missing? Hugo leaves out posts that are:

  • marked as a draft (Blograker’s Draft switch),
  • dated in the future, until a build runs after that time. A push or a manual Run workflow after the date publishes it.
  • past an expiry date, if your posts use one.

Not using GitHub Pages?

The build steps are the same everywhere; only the hand-off changes.

  • Netlify, Cloudflare Pages, Vercel connect to your GitHub repo and build on every push themselves, so you don’t need this workflow. Point them at the repo, choose Hugo, and set the HUGO_VERSION environment variable in their settings. They also serve private repos on their free plans.
  • Your own server: keep the build steps, drop the Pages steps, and copy public/ over SSH with rsync. Store the SSH key as a repository secret under Settings → Secrets and variables → Actions, never in the workflow file.