Skip to content

Commit 4b04c20

Browse files
author
Splitter
committed
build: refactor build scripts
1 parent ba3734e commit 4b04c20

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

.github/workflows/publish.yaml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Deploy website to GitHub Pages
22

33
env:
44
WC_HUGO_VERSION: '0.148.2'
5+
NODE_VERSION: '20'
56

67
on:
78
# Trigger the workflow every time you push to the `main` branch
@@ -29,30 +30,62 @@ jobs:
2930
- name: Checkout
3031
uses: actions/checkout@v4
3132
with:
32-
# Fetch history for Hugo's .GitInfo and .Lastmod
33+
# Fetch history for Hugo's .GitInfo and .Lastmod
3334
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+
3453
- name: Setup Hugo
35-
uses: peaceiris/actions-hugo@v2
54+
uses: peaceiris/actions-hugo@v3
3655
with:
3756
hugo-version: ${{ env.WC_HUGO_VERSION }}
3857
extended: true
39-
- uses: actions/cache@v3
58+
59+
- uses: actions/cache@v4
4060
with:
41-
path: /tmp/hugo_cache_runner/
42-
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.mod') }}
61+
path: |
62+
/tmp/hugo_cache_runner/
63+
node_modules/
64+
modules/*/node_modules/
65+
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.mod', '**/package-lock.json', '**/pnpm-lock.yaml') }}
4366
restore-keys: |
4467
${{ runner.os }}-hugomod-
68+
4569
- name: Setup Pages
4670
id: pages
4771
uses: actions/configure-pages@v5
72+
4873
- name: Build with Hugo
4974
env:
5075
HUGO_ENVIRONMENT: production
5176
run: |
5277
echo "Hugo Cache Dir: $(hugo config | grep cachedir)"
5378
hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
54-
- name: Generate Pagefind search index
55-
run: npx pagefind --site "public"
79+
80+
- name: Generate Pagefind search index (if applicable)
81+
run: |
82+
# Check if site uses Pagefind
83+
if [ -f "package.json" ] && grep -q "pagefind" package.json; then
84+
pnpm dlx pagefind --source "public" || npx pagefind --source "public"
85+
elif [ -f "netlify.toml" ] && grep -q "pagefind" netlify.toml; then
86+
pnpm dlx pagefind --source "public" || npx pagefind --source "public"
87+
fi
88+
5689
- name: Upload artifact
5790
uses: actions/upload-pages-artifact@v3
5891
with:

0 commit comments

Comments
 (0)