Skip to content

Commit dbb8960

Browse files
authored
fix: check links on preview (#2067)
* fix: check links on preview * fix: update * fix: preview only * fix: log preview url * fix: test * fix: refactor * fix: only run on docs changes
1 parent c543660 commit dbb8960

File tree

3 files changed

+97
-62
lines changed

3 files changed

+97
-62
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: 'Generate Fern Docs Preview'
2+
description: 'Generates a Fern documentation preview and comments the URL in a PR'
3+
4+
inputs:
5+
github-token:
6+
description: 'GitHub token for creating deployments and comments'
7+
required: true
8+
fern-token:
9+
description: 'Fern API token for publishing docs'
10+
required: true
11+
ref:
12+
description: 'Git ref to create deployment for (usually github.head_ref for PRs)'
13+
required: true
14+
environment:
15+
description: 'Deployment environment name'
16+
required: false
17+
default: 'docs-preview'
18+
19+
outputs:
20+
preview-url:
21+
description: 'The URL where the preview documentation was published'
22+
value: ${{ steps.generate-preview.outputs.url }}
23+
status:
24+
description: 'The outcome of the preview generation (success, failure, etc.)'
25+
value: ${{ steps.generate-preview.outcome }}
26+
27+
runs:
28+
using: "composite"
29+
steps:
30+
- name: Setup Docs
31+
uses: ./.github/actions/setup-docs
32+
with:
33+
docs-github-token: ${{ inputs.github-token }}
34+
35+
- name: Set Build Comment to In Progress
36+
uses: actions/github-script@v7
37+
with:
38+
github-token: ${{ inputs.github-token }}
39+
script: |
40+
const workspace = process.env.GITHUB_WORKSPACE;
41+
const { updatePreviewComment } = await import(`${workspace}/docs-site/scripts/preview-comment.js`);
42+
43+
await updatePreviewComment({
44+
github,
45+
context,
46+
status: 'building',
47+
});
48+
49+
- name: Generate Fern Docs Preview
50+
id: generate-preview
51+
uses: ./.github/actions/publish-fern
52+
with:
53+
github-token: ${{ inputs.github-token }}
54+
fern-token: ${{ inputs.fern-token }}
55+
environment: ${{ inputs.environment }}
56+
ref: ${{ inputs.ref }}
57+
preview: "true"
58+
59+
- name: Comment Preview URL in PR
60+
uses: actions/github-script@v7
61+
if: always()
62+
with:
63+
github-token: ${{ inputs.github-token }}
64+
script: |
65+
const workspace = process.env.GITHUB_WORKSPACE;
66+
const { updatePreviewComment } = await import(`${workspace}/docs-site/scripts/preview-comment.js`);
67+
68+
await updatePreviewComment({
69+
github,
70+
context,
71+
previewUrl: '${{ steps.generate-preview.outputs.url }}',
72+
status: '${{ steps.generate-preview.outcome }}',
73+
});

.github/workflows/on-pull-request.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ jobs:
3636
env:
3737
TITLE: ${{ github.event.pull_request.title }}
3838
run: echo "$TITLE" | yarn commitlint
39+
40+
preview:
41+
name: Generate Documentation Preview
42+
runs-on: ubuntu-latest
43+
permissions:
44+
contents: read
45+
deployments: write
46+
pull-requests: write
47+
outputs:
48+
preview-url: ${{ steps.preview.outputs.preview-url }}
49+
steps:
50+
- name: Checkout aa-sdk
51+
uses: actions/checkout@v4
52+
53+
- name: Generate Documentation Preview
54+
id: preview
55+
uses: ./.github/actions/preview-fern-docs
56+
with:
57+
github-token: ${{ github.token }}
58+
fern-token: ${{ secrets.FERN_TOKEN }}
59+
ref: ${{ github.head_ref }}
3960

4061
lint_docs:
4162
name: Lint Documentation
@@ -72,10 +93,8 @@ jobs:
7293
check_broken_links:
7394
name: Check Broken Links
7495
runs-on: ubuntu-latest
75-
needs: changes
76-
if: ${{ needs.changes.outputs.docs == 'true' }}
77-
# TODO: Remove this after fixing all broken links
78-
continue-on-error: true
96+
needs: [changes, preview]
97+
if: ${{ needs.changes.outputs.docs == 'true' && needs.preview.outputs.preview-url != '' }}
7998
steps:
8099
- name: "Checkout files"
81100
uses: actions/checkout@v3
@@ -101,7 +120,7 @@ jobs:
101120
lychee --version
102121
103122
- name: Check for broken links
104-
run: yarn docs:broken-links
123+
run: yarn docs:broken-links --base-url "${{ needs.preview.outputs.preview-url }}"
105124

106125
lint:
107126
name: Lint

.github/workflows/preview-fern-docs.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)