Deploy Site on Github Pages

This guide shows how to deploy your site on GitHub Pages via GitHub Actions.

Enable GitHub Pages on Repo

  1. Click to Settings tab.
  2. Navigate to Pages.
  3. Pick the GitHUb Actions as Source.
  4. Optional: setup the custom domain.

Create GitHub Pages Workflow

Create the following workflow and commit it to repo.

.github/workflows/gh-pages.yaml
 1name: GitHub Pages
 2
 3on:
 4  # auto deploy when pushing to specified branches.
 5  push:
 6    branches:
 7      - main
 8
 9  # allow deploying manually.
10  workflow_dispatch:
11
12permissions:
13  contents: read
14  pages: write
15  id-token: write
16
17concurrency:
18  group: "pages"
19  cancel-in-progress: false
20
21defaults:
22  run:
23    shell: bash
24
25jobs:
26  build:
27    runs-on: ubuntu-latest
28    steps:
29      - name: Checkout
30        uses: actions/checkout@v3
31        with:
32          submodules: recursive
33
34      - name: Setup Pages
35        id: pages
36        uses: actions/configure-pages@v3
37
38      - name: Setup Node
39        uses: actions/setup-node@v3
40        with:
41          node-version: "18"
42
43      - name: Setup Hugo
44        uses: peaceiris/actions-hugo@v2
45        with:
46          hugo-version: "latest"
47          extended: true
48
49      - name: Install Node.js dependencies
50        run: npm ci
51
52      - name: Build with Hugo
53        env:
54          HUGO_ENVIRONMENT: production
55          HUGO_ENV: production
56        run: |
57          hugo \
58            --gc \
59            --enableGitInfo \
60            --minify \
61            --baseURL "${{ steps.pages.outputs.base_url }}/"          
62
63      - name: Upload artifact
64        uses: actions/upload-pages-artifact@v1
65        with:
66          path: ./public
67
68  deploy:
69    environment:
70      name: github-pages
71      url: ${{ steps.deployment.outputs.page_url }}
72    runs-on: ubuntu-latest
73    needs: build
74    steps:
75      - name: Deploy to GitHub Pages
76        id: deployment
77        uses: actions/deploy-pages@v2