sumarsono.com
Take it with a grain of salt


Github Actions Build Hugo Static Site and Archive Build Result to Artifact

Posted on

cat .github/workflows/main.yml
name: Build Hugo Static Website

on:
  push:
    branches: [ hugo.sumarsono.com ]
  pull_request:
    branches: [ main ]

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

jobs:
  deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - name: Git checkout and update theme
        uses: actions/checkout@v2
        with:
          submodules: true  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Get commit short SHA
        run: echo "SHORT_SHA=`git rev-parse --short HEAD`" >> $GITHUB_ENV

      - name: Setup hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: "0.92.2"
          extended: true

      - name: Cache Hugo module
        uses: actions/cache@v2
        with:
          path: /tmp/hugo_cache
          key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-hugomod-

      - name: Build website
        run: hugo --minify

      - name: Archive build result to artifacts
        uses: actions/upload-artifact@v2
        with:
          name: build-result-${{ env.SHORT_SHA }}
          path: |
            public