@@ -2,6 +2,9 @@ name: PR build
22
33on :
44 pull_request :
5+ # `closed` is included so the preview deployment is torn down when the PR
6+ # closes; the build/link-check job skips that event
7+ types : [opened, reopened, synchronize, closed]
58 workflow_dispatch : # Allows manual triggering from the GitHub UI
69
710permissions :
@@ -11,6 +14,7 @@ permissions:
1114
1215jobs :
1316 build :
17+ if : github.event.action != 'closed'
1418 runs-on : ubuntu-latest
1519 timeout-minutes : 30
1620 steps :
@@ -116,3 +120,60 @@ jobs:
116120 if (filtered.length > 0) {
117121 core.setFailed("There are broken links in the documentation.");
118122 }
123+
124+ # Deploys the built site to GitHub Pages under pr-preview/pr-<number>/ and
125+ # posts a sticky comment on the PR with the preview URL; the preview is
126+ # removed when the PR closes. Builds separately from the job above because
127+ # the preview needs a different baseUrl than the link check. Fork PRs are
128+ # skipped: they get neither secrets nor a writable GITHUB_TOKEN.
129+ deploy-preview :
130+ if : github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
131+ runs-on : ubuntu-latest
132+ timeout-minutes : 30
133+ # Concurrent runs for the same PR would race on pushing to gh-pages
134+ concurrency : pr-preview-${{ github.ref }}
135+ permissions :
136+ contents : write
137+ pull-requests : write
138+ steps :
139+ - uses : actions/checkout@v7
140+ with :
141+ # Images are Git LFS-tracked; skip fetching them on teardown, where
142+ # the checkout is only needed so the action can push to gh-pages
143+ lfs : ${{ github.event.action != 'closed' }}
144+
145+ - uses : actions/setup-node@v6
146+ if : github.event.action != 'closed'
147+ with :
148+ node-version : 24
149+ cache : npm
150+
151+ # The ADO registry requires auth even to install; the repo .npmrc is
152+ # credential-less so creds go into ~/.npmrc here
153+ - name : Authenticate to codat-npm feed
154+ if : github.event.action != 'closed'
155+ run : |
156+ {
157+ echo "//pkgs.dev.azure.com/codat/Codat/_packaging/codat-npm/npm/registry/:username=codat"
158+ echo "//pkgs.dev.azure.com/codat/Codat/_packaging/codat-npm/npm/registry/:_password=${ADO_NPM_FEED_TOKEN}"
159+ echo "//pkgs.dev.azure.com/codat/Codat/_packaging/codat-npm/npm/registry/:email=npm-requires-email@example.com"
160+ } >> ~/.npmrc
161+ env :
162+ ADO_NPM_FEED_TOKEN : ${{ secrets.ADO_NPM_FEED_TOKEN }}
163+
164+ - name : Install dependencies
165+ if : github.event.action != 'closed'
166+ run : npm ci
167+
168+ - name : Build site for preview
169+ if : github.event.action != 'closed'
170+ run : npm run build
171+ env :
172+ GTM_ID : ${{ vars.GTM_ID }}
173+ # GitHub Pages serves the preview from a subpath (no trailing slash)
174+ BASE_URL : /codat-docs/pr-preview/pr-${{ github.event.number }}
175+
176+ - name : Deploy preview
177+ uses : rossjrw/pr-preview-action@v1
178+ with :
179+ source-dir : ./build
0 commit comments