Menu

GitHub action to audit a Hugo site build

Description: Build a Hugo website and audit for silent errors. Optionally generate output and/or an artifact for use by other jobs in a GitHub Actions Workflow (e.g. for other tests or deployment).
Repository URL: https://github.com/wildtechgarden/audit-build-action-hugo
Site: https://www.audit-build-action-default.wtg-demos.ca
CI Status: pre-commit.ci status test-build-audit

Contents

  1. Contents
  2. Configuration and Usage
    1. Action inputs variables
    2. Action outputs variables
    3. Sample usage
      1. Single hugo.toml
      2. With an extra configuration file
  3. Development
  4. Colophon

Configuration and Usage

Action inputs variables

InputDescriptionRequiredDefault
base-urlSet the baseURL for the site (for this build only)false
build-for-downstreamBuild for use by another action or step (aka bundle) without an artifact (string: “true” or “false”true“false”
checkout-fetch-depthFetch depth (recommend using 0 to fetch all history if using .GitInfo or .Lastmod)true0
checkout-submodulesFetch git submodules: false, true, or recursivetruefalse
code-directoryDirectory under which repo and modules will livetrue${{ github.workspace }}/code
config-fileHugo configuration file to use for the build(s) (may be a comma-separated list of files, relative to the ‘source’ dir)true“config.toml”
do-minify-auditIf present, minify site using –minify before auditfalse
do-minify-bundleIf present, minify site using –minify before last buildfalse
hugo-cache-directoryWhere to place the Hugo module cache, under the code-directorytruehugo_cache
hugo-envHugo environment (production, development, etc)trueproduction
hugo-extendedHugo Extendedtruetrue
hugo-versionHugo Versiontrue’latest’
image-formatsImage formats to include in resource hash keytrue[‘webp’, ‘svg’, ‘png’, ‘jpg’, ‘jpeg’,‘gif’, ’tiff’, ’tif’, ‘bmp’]
include-drafts-auditBuild with --buildDrafts during audittruetrue
include-future-auditBuild with --buildFuture during audittruetrue
include-drafts-artifactBuild with --buildDrafts when building for another stage (generating an artifact)truefalse
include-future-artifactBuild with --buildFuturewhen building for another stage (generating an artifact)truefalse
output-directoryLocation of the site output by Hugo, relative to the workspacetruepublic
repo-directoryWhere to checkout the repo, under the code-directorytruerepo
source-directoryWhere the source for the site lives, within the repofalse
upload-site-asArtifact to create containing the Hugo sitefalse
upload-site-filenameFilename for tarball of site to upload to artifacttruehugo-site.tar
upload-site-retentionRetention period in days for Hugo site artifacttrue1
use-lfsUse LFS when checking out out repotruefalse

Action outputs variables

None

Sample usage

Single hugo.toml

name: test-build-on-pr
on:
  pull_request:
    types:
    - assigned
    - opened
    - synchronize
    - reopened
  push:
    branches:
    - main
jobs:
  build-unminified-site:
    runs-on: ubuntu-22.04
    steps:
     - name: "Build site with Hugo and audit"
       uses: wildtechgarden/audit-build-action-hugo
       with:
         base-url: https://www.example.com/
         build-for-downstream: "true"
         use-lfs: true

With an extra configuration file

Create hugo.toml as usual, except put all site-wide parameters in config-params.toml (beside hugo.toml in the directory structure; includes [params] top-level key).

This can be useful for passing information into the build (e.g. for unit tests).

name: test-build-on-pr
on:
  pull_request:
    types:
    - assigned
    - opened
    - synchronize
    - reopened
  push:
    branches:
    - main
jobs:
  build-unminified-site:
    runs-on: ubuntu-22.04
    steps:
    - name: "Build site with Hugo and audit"
      uses: wildtechgarden/audit-build-action-hugo
      with:
        base-url: https://www.example.com/
        build-for-downstream: "true"
        config-file: hugo.toml,hugo.params.toml
        use-lfs: true

Development

TBD


Colophon

Copyright © 2023 Wild Tech ‘Garden’
Released under an MIT License

Authored