Skip to content

Commit 9ce895e

Browse files
Update Pages workflow: Hugo, Node, caching
Bump Hugo to 0.150.1 and add Node 20 support. Add setup for Node.js and pnpm, install frontend deps if package.json is present, and generate a Pagefind index when applicable. Introduce caching for Hugo deps, node_modules and Hugo resources to speed builds. Upgrade upload/deploy actions to newer versions and adjust job ordering/permissions (add needs: build and pages write/id-token permissions) and minor formatting/consistency tweaks in the workflow.
1 parent 75d6761 commit 9ce895e

1 file changed

Lines changed: 85 additions & 36 deletions

File tree

‎.github/workflows/publish.yaml‎

Lines changed: 85 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: Deploy website to GitHub Pages
22

33
env:
4-
WC_HUGO_VERSION: '0.124.1'
4+
WC_HUGO_VERSION: '0.150.1'
5+
NODE_VERSION: '20'
56

67
on:
78
# Trigger the workflow every time you push to the `main` branch
89
push:
9-
branches: ["main"]
10-
# Allows you to run this workflow manually from the Actions tab on GitHub.
10+
branches: ['main']
11+
# Allows you to run this workflow manually from the Actions tab on GitHub
1112
workflow_dispatch:
1213

1314
# Provide permission to clone the repo and deploy it to GitHub Pages
@@ -17,7 +18,7 @@ permissions:
1718
id-token: write
1819

1920
concurrency:
20-
group: "pages"
21+
group: 'pages'
2122
cancel-in-progress: false
2223

2324
jobs:
@@ -26,45 +27,93 @@ jobs:
2627
if: github.repository_owner != 'HugoBlox'
2728
runs-on: ubuntu-latest
2829
steps:
29-
- name: Checkout
30-
uses: actions/checkout@v4
31-
with:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
with:
3233
# Fetch history for Hugo's .GitInfo and .Lastmod
33-
fetch-depth: 0
34-
- name: Setup Hugo
35-
uses: peaceiris/actions-hugo@v3
36-
with:
37-
hugo-version: ${{ env.WC_HUGO_VERSION }}
38-
extended: true
39-
- uses: actions/cache@v4
40-
with:
41-
path: /tmp/hugo_cache_runner/
42-
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.mod') }}
43-
restore-keys: |
44-
${{ runner.os }}-hugomod-
45-
- name: Setup Pages
46-
id: pages
47-
uses: actions/configure-pages@v5
48-
- name: Build with Hugo
49-
env:
50-
HUGO_ENVIRONMENT: production
51-
run: |
52-
echo "Hugo Cache Dir: $(hugo config | grep cachedir)"
53-
hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
54-
- name: Upload artifact
55-
uses: actions/upload-pages-artifact@v3
56-
with:
57-
path: ./public
34+
fetch-depth: 0
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: ${{ env.NODE_VERSION }}
40+
41+
- name: Setup pnpm
42+
if: hashFiles('package.json') != ''
43+
uses: pnpm/action-setup@v4
44+
45+
- name: Install dependencies
46+
run: |
47+
# Install Tailwind CLI if package.json exists
48+
if [ -f "package.json" ]; then
49+
echo "Installing Tailwind dependencies..."
50+
pnpm install || npm install
51+
fi
52+
53+
- name: Setup Hugo
54+
uses: peaceiris/actions-hugo@v3
55+
with:
56+
hugo-version: ${{ env.WC_HUGO_VERSION }}
57+
extended: true
58+
59+
# Cache dependencies (Go modules, node_modules) - stable, rarely changes
60+
- uses: actions/cache@v4
61+
with:
62+
path: |
63+
/tmp/hugo_cache_runner/
64+
node_modules/
65+
modules/*/node_modules/
66+
key: ${{ runner.os }}-hugo-deps-${{ hashFiles('**/go.mod', '**/package-lock.json',
67+
'**/pnpm-lock.yaml') }}
68+
restore-keys: |
69+
${{ runner.os }}-hugo-deps-
70+
71+
# Cache Hugo resources (processed images, CSS) - invalidates only when assets/config change
72+
- uses: actions/cache@v4
73+
with:
74+
path: resources/
75+
key: ${{ runner.os }}-hugo-resources-${{ hashFiles('assets/**/*', 'config/**/*',
76+
'hugo.yaml', 'package.json') }}
77+
restore-keys: |
78+
${{ runner.os }}-hugo-resources-
79+
80+
- name: Setup Pages
81+
id: pages
82+
uses: actions/configure-pages@v5
83+
84+
- name: Build with Hugo
85+
env:
86+
HUGO_ENVIRONMENT: production
87+
run: |
88+
echo "Hugo Cache Dir: $(hugo config | grep cachedir)"
89+
hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
90+
91+
- name: Generate Pagefind search index (if applicable)
92+
run: |
93+
# Check if site uses Pagefind search
94+
if [ -f "package.json" ] && grep -q "pagefind" package.json; then
95+
pnpm dlx pagefind --source "public" || npx pagefind --source "public"
96+
fi
97+
98+
- name: Upload artifact
99+
uses: actions/upload-pages-artifact@v4
100+
with:
101+
path: ./public
58102

59103
# Deploy website to GitHub Pages hosting
60104
deploy:
61105
if: github.repository_owner != 'HugoBlox'
106+
needs: build
107+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
108+
permissions:
109+
pages: write # to deploy to Pages
110+
id-token: write # to verify the deployment originates from an appropriate source
111+
# Deploy to the github-pages environment
62112
environment:
63113
name: github-pages
64114
url: ${{ steps.deployment.outputs.page_url }}
65115
runs-on: ubuntu-latest
66-
needs: build
67116
steps:
68-
- name: Deploy to GitHub Pages
69-
id: deployment
70-
uses: actions/deploy-pages@v4
117+
- name: Deploy to GitHub Pages
118+
id: deployment
119+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)