@@ -24,12 +24,12 @@ jobs:
2424 ref : ${{ github.event.pull_request.head.sha }}
2525 fetch-depth : 0
2626
27- - name : Checkout for cleanup
27+ - name : Checkout base branch for cleanup
2828 if : github.event.action == 'closed'
2929 uses : actions/checkout@v6
3030 with :
31- ref : gh-pages
32- fetch-depth : 0
31+ ref : ${{ github.event.pull_request.base.ref }}
32+ fetch-depth : 1
3333
3434 - name : Setup Node
3535 if : github.event.action != 'closed'
@@ -41,33 +41,24 @@ jobs:
4141 if : github.event.action != 'closed'
4242 run : " [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
4343
44- # Project Pages URLs are https://<owner>.github.io/<repo>/… so Gatsby pathPrefix must
45- # include <repo> (e.g. layer5/pr-preview/pr-9), not only /pr-preview/pr-9 — otherwise JS/CSS
46- # load from the wrong path and the shell renders without client-side content.
4744 - name : Resolve preview URLs
4845 if : github.event.action != 'closed'
4946 id : preview-vars
5047 env :
5148 PREVIEW_SITE_URL : ${{ vars.PREVIEW_SITE_URL }}
52- GITHUB_PAGES_ORIGIN : ${{ vars.GITHUB_PAGES_ORIGIN }}
49+ PUBLIC_SITE_URL : ${{ vars.PUBLIC_SITE_URL }}
5350 run : |
5451 owner="${GITHUB_REPOSITORY%%/*}"
5552 repo_name="${GITHUB_REPOSITORY#*/}"
5653 pr="pr-${{ github.event.pull_request.number }}"
54+ base="${PREVIEW_SITE_URL:-${PUBLIC_SITE_URL:-}}"
5755
58- if [[ -n "${PREVIEW_SITE_URL:-}" ]]; then
59- base="${PREVIEW_SITE_URL%/}"
60- pages_origin="$(printf '%s' "$base" | sed -E 's|(https?://[^/]+).*|\1|')"
61- repo_path="$(printf '%s' "$base" | sed -E 's|https?://[^/]+||' | sed 's|^/||;s|/$||')"
62- if [[ -n "$repo_path" ]]; then
63- path_prefix="${repo_path}/pr-preview/${pr}"
64- else
65- path_prefix="pr-preview/${pr}"
66- fi
67- preview_url="${base}/pr-preview/${pr}/"
56+ if [[ -n "$base" ]]; then
57+ pages_origin="${base%/}"
58+ path_prefix="pr-preview/${pr}"
59+ preview_url="${pages_origin}/pr-preview/${pr}/"
6860 else
69- pages_origin="${GITHUB_PAGES_ORIGIN:-https://${owner}.github.io}"
70- pages_origin="${pages_origin%/}"
61+ pages_origin="https://${owner}.github.io"
7162 if [[ "$repo_name" == "${owner}.github.io" ]]; then
7263 path_prefix="pr-preview/${pr}"
7364 preview_url="${pages_origin}/pr-preview/${pr}/"
0 commit comments