Skip to content

Add Reo.dev tracking script #1466

Add Reo.dev tracking script

Add Reo.dev tracking script #1466

Workflow file for this run

name: preview-docs
on: pull_request
# One preview build per PR at a time. Stop existing runs when newer pushes retrigger the workflow.
concurrency:
group: preview-docs-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
preview:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
- name: Install dependencies
run: yarn install
- name: Build and generate preview
id: generate-docs
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
# Stable, per-PR preview id. Includes repo because Fern scopes preview IDs by org - prevents collisions if another repo later copies this workflow.
PREVIEW_ID: ${{ github.event.repository.name }}-${{ github.event.pull_request.number }}
run: |
set -eo pipefail
yarn build:specs 2>&1 | tee /tmp/build.log
yarn fern generate --docs --preview --id "$PREVIEW_ID" --force 2>&1 | tee -a /tmp/build.log
# Because the script runs under set -e with pipefail, it would abort if grep finds no match and exits non-zero, so || true absorbs that and lets the empty-URL check below handle it.
URL=$(grep -oP 'Published docs to \Khttps://[^\s]+' /tmp/build.log | head -1 || true)
if [ -z "$URL" ]; then
echo "::error::Could not extract preview URL from build output"
exit 1
fi
echo "preview_url=$URL" >> "$GITHUB_OUTPUT"
- name: Post preview comment
uses: actions/github-script@v9
env:
PREVIEW_URL: ${{ steps.generate-docs.outputs.preview_url }}
with:
script: |
const previewUrl = process.env.PREVIEW_URL;
const MARKER = '<!-- preview-docs-bot -->';
let body = MARKER + '\n';
body += `## 🌿 Preview\n\n`;
body += `${previewUrl}`;
body += `\n\n---\n[View workflow run](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(MARKER));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}