Quick Hugo Deploy with GitHub Actions

If you want a quick (and free) way to deploy your Hugo site, using GitHub Action is a great option!

Once you have your Hugo project setup, all you need to do is push the following GitHub Action to deploy!

name: Build
on:
  push:
    branches: [main]
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
          fetch-depth: 0
      - uses: peaceiris/actions-hugo@v2
      - run: hugo --minify
      - uses: JamesIves/github-pages-deploy-action@v4
        with:
          branch: gh-pages
          folder: public
.github/workflows/build.yml

This action does three things each time you push to main:

  1. Pulls your repository, including all submodules.
  2. Builds your site with the Hugo CLI.
  3. Deploys the build to GitHub Pages via the gh-pages branch.

That’s it. After a few moments, your site should now be live at:

https://<username>.github.io/<repository>/

If you want a custom domain for this site, you can configure a custom domain with GitHub Pages.

Reply via email