Skip to content

Commit d7b4cf5

Browse files
authored
Create a Hugo Build and Deploy for GitHub Pages
1 parent a39db21 commit d7b4cf5

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

.github/workflows/hugo.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Build and deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
concurrency:
12+
group: pages
13+
cancel-in-progress: false
14+
defaults:
15+
run:
16+
shell: bash
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
env:
21+
DART_SASS_VERSION: 1.91.0
22+
GO_VERSION: 1.25.0
23+
HUGO_VERSION: 0.149.0
24+
NODE_VERSION: 22.18.0
25+
TZ: UTC
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v5
29+
with:
30+
submodules: recursive
31+
fetch-depth: 0
32+
- name: Setup Go
33+
uses: actions/setup-go@v5
34+
with:
35+
go-version: ${{ env.GO_VERSION }}
36+
cache: false
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: ${{ env.NODE_VERSION }}
41+
- name: Setup Pages
42+
id: pages
43+
uses: actions/configure-pages@v5
44+
- name: Create directory for user-specific executable files
45+
run: |
46+
mkdir -p "${HOME}/.local"
47+
- name: Install Dart Sass
48+
run: |
49+
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
50+
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
51+
rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
52+
echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}"
53+
- name: Install Hugo
54+
run: |
55+
curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
56+
mkdir "${HOME}/.local/hugo"
57+
tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
58+
rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
59+
echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}"
60+
- name: Verify installations
61+
run: |
62+
echo "Dart Sass: $(sass --version)"
63+
echo "Go: $(go version)"
64+
echo "Hugo: $(hugo version)"
65+
echo "Node.js: $(node --version)"
66+
- name: Install Node.js dependencies
67+
run: |
68+
[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true
69+
- name: Configure Git
70+
run: |
71+
git config core.quotepath false
72+
- name: Cache restore
73+
id: cache-restore
74+
uses: actions/cache/restore@v4
75+
with:
76+
path: ${{ runner.temp }}/hugo_cache
77+
key: hugo-${{ github.run_id }}
78+
restore-keys:
79+
hugo-
80+
- name: Build the site
81+
run: |
82+
hugo \
83+
--gc \
84+
--minify \
85+
--baseURL "${{ steps.pages.outputs.base_url }}/" \
86+
--cacheDir "${{ runner.temp }}/hugo_cache"
87+
- name: Cache save
88+
id: cache-save
89+
uses: actions/cache/save@v4
90+
with:
91+
path: ${{ runner.temp }}/hugo_cache
92+
key: ${{ steps.cache-restore.outputs.cache-primary-key }}
93+
- name: Upload artifact
94+
uses: actions/upload-pages-artifact@v3
95+
with:
96+
path: ./public
97+
deploy:
98+
environment:
99+
name: github-pages
100+
url: ${{ steps.deployment.outputs.page_url }}
101+
runs-on: ubuntu-latest
102+
needs: build
103+
steps:
104+
- name: Deploy to GitHub Pages
105+
id: deployment
106+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)