Building Your Docs

Pull request previews

PR previews offer a way to preview changes from pull requests (PRs) before merging code to a production branch. This is useful for reviewing documentation changes before publishing them to your live documentation site. Use manually or in GitHub Actions.

Usage

$fern generate --docs --preview

Example

$fern generate --docs --preview
>
>[docs]: Found 0 errors and 1 warnings. Run fern check --warnings to print out the warnings.
>[docs]: Published docs to https://fern-preview-ce3459d6-8a76-4747-963a-33c71ee13959.docs.buildwithfern.com
>┌─
>│ ✓ docs.example.com
>└─

Usage in GitHub Actions

The following is a GitHub Action workflow that generates a preview URL for every pull request.x

.github/workflows/preview-docs.yml
1name: preview-docs
2
3on:
4 pull_request
5
6jobs:
7 run:
8 runs-on: ubuntu-latest
9 permissions: write-all
10 steps:
11 - name: Checkout repository
12 uses: actions/checkout@v4
13
14 - name: Install Fern
15 run: npm install -g fern-api
16
17 - name: Generate preview URL
18 id: generate-docs
19 env:
20 FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
21 run: |
22 OUTPUT=$(fern generate --docs --preview 2>&1) || true
23 echo "$OUTPUT"
24 URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
25 echo "Preview URL: $URL"
26 echo "🌿 Preview your docs: $URL" > preview_url.txt
27
28 - name: Comment URL in PR
29 uses: thollander/actions-comment-pull-request@v2.4.3
30 with:
31 filePath: preview_url.txt

Preview links do not expire. However, the time to live (TTL) is subject to change in the future.