From de7953a198995f6835c6f39bbfed536fa344bde1 Mon Sep 17 00:00:00 2001 From: sotashimozono Date: Wed, 9 Sep 2026 09:21:57 +0000 Subject: [PATCH] fix: the docs-preview link pointed at a sinkholed domain for every repo using the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `preview-base` defaulted to `https://codes.sota-shimozono.com`. Measured 2026-09-09: $ getent hosts codes.sota-shimozono.com 198.135.184.22 sinkhole.paloaltonetworks.com $ curl -o /dev/null -w '%{http_code}' https://codes.sota-shimozono.com/ExperimentalAPI.jl/previews/PR35/ 000 Five of the seven repositories calling this workflow use that default — DataVault.jl, ExperimentalAPI.jl, AbstractQAtlas.jl, ParamIO.jl, TestShards.jl — so every preview comment in them names a host that does not answer. The other two, templateHPC.jl and SweepRunner.jl, already pass `preview-base: 'https://qatlashub.github.io'` by hand; two repositories carrying the same compensation is what says the default is wrong rather than the callers. The URL is now asked of the Pages API instead of assembled from a constant, because a constant cannot know about a custom domain and the API already does: default (Pages API) https://qatlashub.github.io/ExperimentalAPI.jl/previews/PR35/ → 200 explicit preview-base https://example.org/ExperimentalAPI.jl/previews/PR35/ fallback (no Pages yet) https://qatlashub.github.io/ExperimentalAPI.jl/previews/PR35/ `preview-base` still wins when given, so a repository served from somewhere the API cannot report keeps its override. The fallback lowercases the owner, because Pages serves from a lowercase host while `github.repository_owner` is spelled as the org is. `pages: read` added for the API call, and the fallback covers a repository whose Pages site does not exist yet or whose token cannot read it. After this, the two hand-written `preview-base` lines can be deleted — they now say what the default computes. Co-Authored-By: Claude Opus 5 --- .github/workflows/docs-preview.yml | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml index 0f08bd8..d651d5a 100644 --- a/.github/workflows/docs-preview.yml +++ b/.github/workflows/docs-preview.yml @@ -13,9 +13,12 @@ on: type: string default: '' preview-base: - description: 'Base URL where docs are served; the preview link is //previews/PR/.' + description: >- + Base URL where docs are served; the preview link is //previews/PR/. + Empty asks the Pages API where this repository's site actually is, which already + accounts for a custom domain. type: string - default: 'https://codes.sota-shimozono.com' + default: '' secrets: DOCUMENTER_KEY: required: false @@ -23,6 +26,7 @@ permissions: contents: write pull-requests: write statuses: write + pages: read jobs: preview: runs-on: ubuntu-latest @@ -51,6 +55,30 @@ jobs: -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${{ github.repository }}/pages/builds" + # The published URL is asked of GitHub rather than assembled from a constant. A constant + # cannot know about a custom domain, and the one that was here — + # `https://codes.sota-shimozono.com` — resolves to `sinkhole.paloaltonetworks.com`, so every + # preview comment in a repository using the default pointed at an unreachable host. + - name: Resolve the published site URL + id: site + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE: ${{ inputs.preview-base }} + REPO: ${{ github.repository }} + NAME: ${{ github.event.repository.name }} + OWNER: ${{ github.repository_owner }} + PR: ${{ github.event.pull_request.number }} + run: | + if [ -n "$BASE" ]; then + root="${BASE%/}/$NAME" + else + root=$(gh api "repos/$REPO/pages" --jq '.html_url' 2>/dev/null || true) + # No Pages site yet, or no permission to read it: fall back to the host GitHub would + # serve it from. Lowercased, because the owner may be spelled in mixed case. + [ -n "$root" ] || root="https://$(printf '%s' "$OWNER" | tr '[:upper:]' '[:lower:]').github.io/$NAME" + fi + echo "url=${root%/}/previews/PR$PR/" >> "$GITHUB_OUTPUT" + - name: Find existing preview comment id: find-comment uses: peter-evans/find-comment@v4 @@ -66,6 +94,6 @@ jobs: issue-number: ${{ github.event.pull_request.number }} edit-mode: replace body: | - 📚 **Docs preview**: ${{ inputs.preview-base }}/${{ github.event.repository.name }}/previews/PR${{ github.event.pull_request.number }}/ + 📚 **Docs preview**: ${{ steps.site.outputs.url }} *(updates on each push to this PR)*