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-a1da0157-93ca-4b1f-b310-8dd34fb891ca.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. Be sure to add the FERN_TOKEN for your organization to the repository.

.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
Allow PR previews to be generated from forks

Fern’s PR previews GitHub Action requires a Fern token to run. Depending on your repository’s permissions, you may need to use the following workflow to allow PR previews from forks to access this token.

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