Skip to content

Commit 4f6c704

Browse files
committed
1 parent 42f7c78 commit 4f6c704

3 files changed

Lines changed: 42 additions & 29 deletions

File tree

.agent/working-memory/session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
- Workflow: `.github/workflows/gh-pages.yml`
1313
- Trigger: push to `develop` branch
14-
- Build: Hugo v0.159.1 (extended), Node.js 22, `npm ci`, `hugo --minify --gc`
14+
- Build: containerized via Docker Compose (`docker compose build hugo` + `docker compose run hugo hugo build --gc --minify`), mirroring local deployment toolchain and image
1515
- Deploy method: `actions/upload-pages-artifact` + `actions/deploy-pages` (OIDC, no branch write)
1616
- **No `main` branch is used for deployment.** The old `peaceiris/actions-gh-pages` approach that pushed to `main` has been replaced. The `main` branch is obsolete.
1717
- Required repo setting: Settings → Pages → Source must be **GitHub Actions** (not "Deploy from a branch").

.github/workflows/gh-pages.yml

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- develop
7+
workflow_dispatch:
78

89
# Required for GitHub Pages OIDC deployment
910
permissions:
@@ -13,48 +14,60 @@ permissions:
1314

1415
# Allow only one concurrent deployment; queue the next, cancel any in-between
1516
concurrency:
16-
group: "pages"
17+
group: pages
1718
cancel-in-progress: false
1819

20+
defaults:
21+
run:
22+
shell: bash
23+
1924
jobs:
2025
build:
2126
runs-on: ubuntu-latest
27+
env:
28+
HUGO_CACHEDIR: ./.hugo_cache
2229
steps:
23-
- uses: actions/checkout@v4
30+
- name: Checkout
31+
uses: actions/checkout@v4
2432
with:
2533
fetch-depth: 0 # full history for Hugo .GitInfo / .Lastmod
2634

27-
- name: Read Hugo version from .env
28-
id: hugo-version
29-
run: |
30-
. ./.env
31-
echo "HUGO_VERSION=${HUGO_VERSION}" >> $GITHUB_OUTPUT
35+
- name: Setup Pages
36+
id: pages
37+
uses: actions/configure-pages@v5
3238

33-
- name: Setup Node.js
34-
uses: actions/setup-node@v4
35-
with:
36-
node-version: "22"
37-
cache: 'npm'
39+
- name: Configure Git
40+
run: |
41+
git config core.quotepath false
3842
39-
- name: Setup Hugo
40-
uses: peaceiris/actions-hugo@v3
43+
- name: Restore build cache
44+
uses: actions/cache/restore@v4
4145
with:
42-
# sync version with .env / Dockerfile
43-
hugo-version: "${{ steps.hugo-version.outputs.HUGO_VERSION }}"
44-
extended: true
46+
path: ${{ env.HUGO_CACHEDIR }}
47+
key: hugo-${{ runner.os }}-${{ github.run_id }}
48+
restore-keys: |
49+
hugo-${{ runner.os }}-
4550
46-
- name: Configure Pages
47-
uses: actions/configure-pages@v5
48-
49-
- name: Install npm dependencies
50-
run: npm ci
51-
52-
- name: Build Hugo site
51+
- name: Build in Docker Compose
5352
env:
54-
HUGO_ENV: "production"
55-
run: hugo --minify --gc
53+
BASE_URL: ${{ steps.pages.outputs.base_url }}
54+
run: |
55+
docker compose build --pull hugo
56+
docker compose run --rm --no-deps \
57+
--user "$(id -u):$(id -g)" \
58+
-e HUGO_ENV=production \
59+
-e HUGO_CACHEDIR="${HUGO_CACHEDIR}" \
60+
-e BASE_URL="${BASE_URL}" \
61+
hugo sh -lc 'git config --global --add safe.directory /src && git config --global core.quotepath false && hugo build --gc --minify --baseURL "${BASE_URL%/}/" --cacheDir "${HUGO_CACHEDIR}"'
62+
63+
- name: Save build cache
64+
if: always()
65+
uses: actions/cache/save@v4
66+
with:
67+
path: ${{ env.HUGO_CACHEDIR }}
68+
key: hugo-${{ runner.os }}-${{ github.run_id }}
5669

57-
- name: Upload Pages artifact
70+
- name: Upload artifact
5871
uses: actions/upload-pages-artifact@v3
5972
with:
6073
path: ./public

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The site is deployed to GitHub Pages via the workflow at `.github/workflows/gh-p
2525

2626
### How it works
2727

28-
1. The `build` job checks out `develop`, installs Node.js 22 and Hugo (extended), runs `npm ci` and `hugo --minify --gc`, then uploads the built `public/` directory as a Pages artifact.
28+
1. The `build` job checks out `develop`, configures the Pages base URL, then builds the site inside the same Docker Compose `hugo` service used for local development (`docker compose build hugo` + `docker compose run hugo ...`). This mirrors local toolchain versions and container behavior in CI.
2929
2. The `deploy` job receives that artifact and publishes it directly to GitHub Pages via GitHub's OIDC-based Pages API (`actions/deploy-pages`).
3030

3131
**No "built" branch is used.** The old approach pushed compiled HTML to a `main` branch using `peaceiris/actions-gh-pages`. That is no longer the case — the deployment artifact goes straight to GitHub's Pages infrastructure. The `main` branch (if it still exists in the remote) is a leftover and is no longer updated.

0 commit comments

Comments
 (0)