Deploy Site on Github Pages

Donate

Become a backer or sponsor to support our work.

Sponsors

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    # Must runs on Ubuntu, since this workflow use snap to install Dart Sass.
28    runs-on: ubuntu-latest
29    steps:
30      - name: Checkout
31        uses: actions/checkout@v3
32        with:
33          submodules: recursive
34
35      - name: Setup Pages
36        id: pages
37        uses: actions/configure-pages@v3
38
39      - name: Setup Node
40        uses: actions/setup-node@v3
41        with:
42          node-version: "18"
43
44      - name: Setup Dart Sass
45        run: sudo snap install dart-sass && sudo snap alias dart-sass sass
46
47      - name: Setup Hugo
48        uses: peaceiris/actions-hugo@v2
49        with:
50          hugo-version: "latest"
51          extended: true
52
53      - name: Install Node.js dependencies
54        run: npm ci
55
56      - name: Build with Hugo
57        env:
58          HUGO_ENVIRONMENT: production
59          HUGO_ENV: production
60        run: |
61          hugo \
62            --gc \
63            --enableGitInfo \
64            --minify \
65            --baseURL "${{ steps.pages.outputs.base_url }}/"          
66
67      - name: Upload artifact
68        uses: actions/upload-pages-artifact@v1
69        with:
70          path: ./public
71
72  deploy:
73    environment:
74      name: github-pages
75      url: ${{ steps.deployment.outputs.page_url }}
76    runs-on: ubuntu-latest
77    needs: build
78    steps:
79      - name: Deploy to GitHub Pages
80        id: deployment
81        uses: actions/deploy-pages@v2
razonyang
Saturday, December 21, 2024 Friday, April 14, 2023