11name : Deploy website to GitHub Pages
22
3- env :
4- NODE_VERSION : ' 20'
5-
63on :
74 # Trigger the workflow every time you push to the `main` branch
85 push :
@@ -21,95 +18,39 @@ concurrency:
2118 cancel-in-progress : false
2219
2320jobs :
24- # Build website
25- build :
21+ # Check deployment configuration
22+ config :
2623 if : github.repository_owner != 'HugoBlox'
2724 runs-on : ubuntu-latest
25+ outputs :
26+ deploy-host : ${{ steps.check.outputs.host }}
2827 steps :
2928 - name : Checkout
3029 uses : actions/checkout@v4
3130 with :
32- # Fetch history for Hugo's .GitInfo and .Lastmod
33- fetch-depth : 0
34-
35- - name : Setup Node.js
36- uses : actions/setup-node@v4
37- with :
38- node-version : ${{ env.NODE_VERSION }}
39-
40- - name : Setup pnpm
41- if : hashFiles('package.json') != ''
42- uses : pnpm/action-setup@v4
43-
44- - name : Get Hugo Version
45- id : hugo-version
46- run : |
47- VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\"")
48- echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
49-
50- - name : Install dependencies
51- run : |
52- # Install Tailwind CLI if package.json exists
53- if [ -f "package.json" ]; then
54- echo "Installing Tailwind dependencies..."
55- pnpm install --no-frozen-lockfile || npm install
56- fi
57-
58- - name : Setup Hugo
59- uses : peaceiris/actions-hugo@v3
60- with :
61- hugo-version : ${{ env.HUGO_VERSION }}
62- extended : true
31+ sparse-checkout : hugoblox.yaml
32+ sparse-checkout-cone-mode : false
6333
64- # Cache dependencies (Go modules, node_modules) - stable, rarely changes
65- - uses : actions/cache@v4
66- with :
67- path : |
68- /tmp/hugo_cache_runner/
69- node_modules/
70- modules/*/node_modules/
71- key : ${{ runner.os }}-hugo-deps-${{ hashFiles('**/go.mod', '**/package-lock.json',
72- ' **/pnpm-lock.yaml' ) }}
73- restore-keys : |
74- ${{ runner.os }}-hugo-deps-
75-
76- # Cache Hugo resources (processed images, CSS) - invalidates only when assets/config change
77- - uses : actions/cache@v4
78- with :
79- path : resources/
80- key : ${{ runner.os }}-hugo-resources-${{ hashFiles('assets/**/*', 'config/**/*',
81- ' hugo.yaml' , 'package.json') }}
82- restore-keys : |
83- ${{ runner.os }}-hugo-resources-
84-
85- - name : Setup Pages
86- id : pages
87- uses : actions/configure-pages@v5
88-
89- - name : Build with Hugo
90- env :
91- HUGO_ENVIRONMENT : production
92- HUGO_BLOX_LICENSE : ${{ secrets.HUGO_BLOX_LICENSE }}
34+ - name : Check deploy host
35+ id : check
9336 run : |
94- echo "Hugo Cache Dir: $(hugo config | grep cachedir)"
95- hugo --minify --baseURL "${{ steps.pages.outputs.base_url }}/"
37+ # Read deploy.host from hugoblox.yaml, default to github-pages
38+ HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
39+ HOST=${HOST:-github-pages}
40+ echo "host=$HOST" >> $GITHUB_OUTPUT
41+ echo "Deployment target: $HOST"
9642
97- - name : Generate Pagefind search index (if applicable)
98- run : |
99- # Check if site uses Pagefind search
100- if [ -f "package.json" ] && grep -q "pagefind" package.json; then
101- pnpm run pagefind || npx pagefind --site "public"
102- fi
103-
104- - name : Upload artifact
105- uses : actions/upload-pages-artifact@v4
106- with :
107- path : ./public
43+ # Build website using reusable workflow (always runs for CI)
44+ build :
45+ needs : config
46+ if : github.repository_owner != 'HugoBlox'
47+ uses : ./.github/workflows/build.yml
48+ secrets : inherit
10849
109- # Deploy website to GitHub Pages hosting
50+ # Deploy website to GitHub Pages hosting (only if configured)
11051 deploy :
111- if : github.repository_owner != 'HugoBlox'
112- needs : build
52+ needs : [config, build]
53+ if : needs.config.outputs.deploy-host == 'github-pages'
11354 # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
11455 permissions :
11556 pages : write # to deploy to Pages
0 commit comments