@@ -88,3 +88,211 @@ jobs:
8888 env :
8989 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9090 run : npx tsx bin/post-pr-ci-failure-comment/index.ts
91+
92+ build :
93+ name : Build
94+ runs-on : ubuntu-latest
95+ outputs :
96+ link_check_failed : ${{ steps.check_link_result.outputs.failed }}
97+ permissions :
98+ contents : read
99+ pull-requests : write
100+ steps :
101+ - uses : actions/checkout@v4
102+ with :
103+ fetch-depth : 1
104+
105+ - uses : actions/setup-node@v4
106+ with :
107+ node-version : 22.x
108+ cache : npm
109+
110+ - run : |
111+ FILES=$(
112+ find src/content \
113+ -type f \
114+ -not -name '*.mdx' \
115+ -not -name '*.md' \
116+ -not -name '*.json' \
117+ -not -name '*.yml' \
118+ -not -name '*.yaml' \
119+ -not -name '*.txt' \
120+ -not -wholename 'src/content/collections/*'
121+ )
122+
123+ if [ -n "$FILES" ]; then
124+ echo "Found files with invalid file extensions:\n\n$FILES"
125+ exit 1
126+ fi
127+
128+ - run : npm ci
129+
130+ - uses : actions/cache/restore@v4
131+ with :
132+ path : |
133+ node_modules/.astro/assets
134+ key : static
135+
136+ - run : npx tsx bin/post-codeowners-comment/index.ts
137+ continue-on-error : true
138+ env :
139+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140+
141+ - run : npm run check
142+
143+ # The starlight-links-validator plugin runs in astro:build:done, which fires
144+ # AFTER all pages have been written to dist/. If link validation fails, the
145+ # build exits non-zero but dist/ is complete. We use continue-on-error so the
146+ # job succeeds (allowing deploy + validate to run), then check the outcome below.
147+ - run : npm run build
148+ id : build_step
149+ name : Build
150+ continue-on-error : true
151+ env :
152+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
153+ RUN_LINK_CHECK : true
154+
155+ # Distinguish between "link check failed" (dist/ exists) and "real build failure" (no dist/).
156+ # If the build produced no output, we must fail the job immediately.
157+ - name : Check build result
158+ id : check_link_result
159+ run : |
160+ if [ ! -d dist ] || [ -z "$(ls -A dist)" ]; then
161+ echo "Build failed before producing output. Check the Build job logs for the error."
162+ exit 1
163+ fi
164+ if [ "${{ steps.build_step.outcome }}" = "failure" ]; then
165+ echo "failed=true" >> "$GITHUB_OUTPUT"
166+ echo "::warning::Build succeeded but link validation failed. Preview will still be deployed."
167+ else
168+ echo "failed=false" >> "$GITHUB_OUTPUT"
169+ fi
170+
171+ - uses : actions/cache/save@v4
172+ with :
173+ path : |
174+ node_modules/.astro/assets
175+ key : static
176+
177+ - uses : actions/upload-artifact@v4
178+ with :
179+ name : dist
180+ path : dist
181+
182+ validate :
183+ name : Validate
184+ needs : build
185+ runs-on : ubuntu-latest
186+ permissions :
187+ contents : read
188+ pull-requests : write
189+ steps :
190+ - uses : actions/checkout@v4
191+ with :
192+ fetch-depth : 1
193+
194+ - uses : actions/setup-node@v4
195+ with :
196+ node-version : 22.x
197+ cache : npm
198+
199+ - run : npm ci
200+
201+ - uses : actions/download-artifact@v4
202+ with :
203+ name : dist
204+ path : dist
205+
206+ - uses : reviewdog/action-eslint@v1
207+ with :
208+ github_token : ${{ secrets.GITHUB_TOKEN }}
209+ reporter : github-pr-review
210+ fail_level : error
211+ filter_mode : nofilter
212+
213+ - run : npm run format:core:check
214+
215+ - name : Validate redirects
216+ run : npx tsm bin/validate-redirects.ts
217+
218+ - name : Tests
219+ run : npm run test
220+
221+ - name : Link validation
222+ if : needs.build.outputs.link_check_failed == 'true'
223+ run : |
224+ echo "::error::starlight-links-validator found broken internal links during the build. See the Build job logs for details."
225+ exit 1
226+
227+ notify :
228+ name : Notify
229+ needs : [build, validate]
230+ if : always()
231+ runs-on : ubuntu-latest
232+ permissions :
233+ contents : read
234+ pull-requests : write
235+ steps :
236+ - uses : actions/checkout@v4
237+ with :
238+ fetch-depth : 1
239+
240+ - uses : actions/setup-node@v4
241+ with :
242+ node-version : 22.x
243+ cache : npm
244+
245+ - run : npm ci
246+
247+ - name : Post PR CI failure comment
248+ continue-on-error : true
249+ env :
250+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
251+ run : npx tsx bin/post-pr-ci-failure-comment/index.ts
252+
253+ publish-preview :
254+ name : Deploy Preview
255+ needs : build
256+ if : github.repository == 'cloudflare/cloudflare-docs'
257+ runs-on : ubuntu-latest
258+ permissions :
259+ contents : read
260+ pull-requests : write
261+ steps :
262+ - uses : actions/checkout@v4
263+ with :
264+ fetch-depth : 1
265+
266+ - uses : actions/setup-node@v4
267+ with :
268+ node-version : 22.x
269+ cache : npm
270+
271+ - run : npm ci
272+
273+ - uses : actions/download-artifact@v4
274+ with :
275+ name : dist
276+ path : dist
277+
278+ - name : Deploy to Cloudflare Workers
279+ id : deploy
280+ env :
281+ CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
282+ run : |
283+ SHORT_SHA="${{ github.event.pull_request.head.sha }}"
284+ SHORT_SHA="${SHORT_SHA:0:8}"
285+ BRANCH="${{ github.event.pull_request.head.ref }}"
286+ BRANCH_SLUG=$(echo "$BRANCH" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z)
287+
288+ echo "branch_slug=$BRANCH_SLUG" >> "$GITHUB_OUTPUT"
289+
290+ npx wrangler deploy --dispatch-namespace preview-deployments --name $SHORT_SHA
291+ npx wrangler deploy --dispatch-namespace preview-deployments --name $BRANCH_SLUG
292+
293+ - name : Post preview URL on PR
294+ env :
295+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
296+ BRANCH_SLUG : ${{ steps.deploy.outputs.branch_slug }}
297+ run : npx tsx bin/post-preview-url-comment/index.ts
298+ continue-on-error : true
0 commit comments