This article explains how to deploy sites to GitHub Pages using GitHub Actions.
Workflow
Create .github/workflows/gh-pages.yml
in the site root.
1name: GitHub Pages
2on:
3 push:
4 branches:
5 - main
6permissions:
7 contents: write
8jobs:
9 build-and-deploy:
10 concurrency: ci-${{ github.ref }}
11 runs-on: ubuntu-latest
12 steps:
13 - name: Checkout 🛎️
14 uses: actions/checkout@v3
15 with:
16 submodules: true
17 fetch-depth: 0
18
19 - name: Setup Node
20 uses: actions/setup-node@v3
21 with:
22 node-version: '16'
23
24 - name: Cache dependencies
25 uses: actions/cache@v2
26 with:
27 path: ~/.npm
28 key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
29 restore-keys: |
30 ${{ runner.os }}-node-
31
32 - name: Install dependencies
33 run: npm install
34
35 - name: Setup Hugo
36 uses: peaceiris/actions-hugo@v2
37 with:
38 hugo-version: 'latest'
39 extended: true
40
41 - name: Build
42 run: hugo --minify --gc --enableGitInfo
43
44 - name: Deploy 🚀
45 uses: peaceiris/actions-gh-pages@v3
46 with:
47 github_token: ${{ secrets.GITHUB_TOKEN }}
48 publish_dir: ./public
See also Starter Template GitHub Pages Workflow。
Comments