Skip to content

Commit f70476b

Browse files
gas2ownclaude
andcommitted
workspace: make Quarto PR preview robust (un-failable comment + correct URL on private repos)
Two latent bugs in the reusable Quarto deploy workflow made a freshly scaffolded repo's first PR look broken (red deploy check, no/wrong preview link) even when the site published fine: 1. The preview-comment gh api read was unguarded under set -e; a transient 5xx HTML body breaks --jq and abORTS the deploy after publish. Now the block runs under set +e and closes on a guaranteed-success command. 2. The preview URL was hardcoded to <owner>.github.io/<repo>, dead on private/internal repos that serve from an obfuscated *.pages.github.io domain. Now resolved from the Pages API with fallback; deploy job and scaffold docs.yml template grant pages: read. Supersedes #91, #92, #93. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0c4c089 commit f70476b

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

.github/workflows/workspace-quarto-site.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ jobs:
8787
permissions:
8888
contents: write
8989
pull-requests: write
90+
# `pages: read` lets us resolve the site's real served URL from the Pages
91+
# API (private/internal repos serve from an obfuscated *.pages.github.io
92+
# domain, not <owner>.github.io/<repo>). Degrades gracefully if absent.
93+
pages: read
9094
concurrency:
9195
group: pages-${{ github.event.pull_request.number || github.ref }}
9296
cancel-in-progress: true
@@ -145,19 +149,33 @@ jobs:
145149
146150
# For a PR, ensure exactly one preview-link comment (create or update),
147151
# independent of whether the content changed. Best-effort — a comment
148-
# hiccup shouldn't fail an otherwise-successful publish.
152+
# hiccup shouldn't fail an otherwise-successful publish, so the whole
153+
# block runs with errexit disabled and closes on a guaranteed success.
149154
if [ "${{ github.event_name }}" = "pull_request" ]; then
150-
url="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-$PR_NUMBER/"
155+
set +e
156+
# Resolve the site's real base URL from the Pages config. Private and
157+
# internal repos serve from an obfuscated <random>.pages.github.io
158+
# domain, NOT <owner>.github.io/<repo>, so hardcoding the latter
159+
# yields a dead preview link there. Fall back to the canonical form
160+
# if the Pages API is unavailable (e.g. token lacks `pages: read`).
161+
base=$(gh api "repos/${{ github.repository }}/pages" --jq '.html_url' 2>/dev/null)
162+
base="${base%/}"
163+
[ -n "$base" ] || base="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}"
164+
url="$base/pr-preview/pr-$PR_NUMBER/"
151165
body="📄 Preview: $url"
166+
# Guard the read: it runs the same set of transient failure modes as
167+
# the writes below (a 5xx returns an HTML body that --jq can't parse),
168+
# so an unguarded assignment would abort the step mid-publish.
152169
existing=$(gh api "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \
153-
--jq 'map(select(.body | startswith("📄 Preview:"))) | .[0].id // empty')
170+
--jq 'map(select(.body | startswith("📄 Preview:"))) | .[0].id // empty' 2>/dev/null)
154171
if [ -n "$existing" ]; then
155172
gh api "repos/${{ github.repository }}/issues/comments/$existing" -X PATCH -f body="$body" >/dev/null \
156173
|| echo "::warning::could not update preview comment"
157174
else
158175
gh api "repos/${{ github.repository }}/issues/$PR_NUMBER/comments" -f body="$body" >/dev/null \
159176
|| echo "::warning::could not create preview comment"
160177
fi
178+
set -e
161179
fi
162180
163181
# Remove a PR's preview when the PR closes. Shares that PR's concurrency group

plugins/asta-tools/skills/workspace/assets/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ on:
1313
#
1414
# The token needs write access for gh-pages pushes and PR preview comments;
1515
# the called workflow's jobs individually downscope to least privilege.
16+
# `pages: read` lets the deploy job resolve the real served URL for the preview
17+
# link (private/internal repos use an obfuscated *.pages.github.io domain).
1618
permissions:
1719
contents: write
1820
pull-requests: write
21+
pages: read
1922

2023
jobs:
2124
docs:

0 commit comments

Comments
 (0)