Skip to content

Update self-hosted changelog: v0.115.11 #6638

Update self-hosted changelog: v0.115.11

Update self-hosted changelog: v0.115.11 #6638

Workflow file for this run

name: Preview Docs
on:
pull_request:
types: [opened, synchronize, ready_for_review]
branches:
- main
jobs:
run:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
pull-requests: write # Only for commenting
contents: read # For checking out code
steps:
- name: Check for FERN_TOKEN
id: check-token
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
run: |
if [ -z "$FERN_TOKEN" ]; then
echo "FERN_TOKEN is not available (e.g. Dependabot PRs). Skipping preview."
echo "has_token=false" >> $GITHUB_OUTPUT
else
echo "has_token=true" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
if: steps.check-token.outputs.has_token == 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0 # Fetch full history for git diff
persist-credentials: false
- name: Checkout PR
if: steps.check-token.outputs.has_token == 'true'
run: |
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }}
git checkout pr-${{ github.event.pull_request.number }}
- name: Setup Fern CLI
if: steps.check-token.outputs.has_token == 'true'
uses: fern-api/setup-fern-cli@d07601425e9c9ede8745d71ca75c4c462d98755d # v1
- name: Generate preview URL
if: steps.check-token.outputs.has_token == 'true'
id: generate-docs
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
HEAD_REF: ${{ github.head_ref }}
run: |
OUTPUT=$(fern generate --docs --preview --id "$HEAD_REF" --instance fern-api.docs.buildwithfern.com/learn 2>&1) || true
echo "$OUTPUT"
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
echo "preview_url=$URL" >> $GITHUB_OUTPUT
echo "Preview URL: $URL"
- name: Get page links for changed MDX files
if: steps.check-token.outputs.has_token == 'true'
id: page-links
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
STEPS_GENERATE_DOCS_OUTPUTS_PREVIEW_URL: ${{ steps.generate-docs.outputs.preview_url }}
run: |
PREVIEW_URL="${STEPS_GENERATE_DOCS_OUTPUTS_PREVIEW_URL}"
CHANGED_FILES=$(git diff --name-only origin/main...HEAD -- '*.mdx' 2>/dev/null || echo "")
if [ -z "$CHANGED_FILES" ] || [ -z "$PREVIEW_URL" ]; then
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
fi
BASE_URL=$(echo "$PREVIEW_URL" | grep -oP 'https?://[^/]+')
FILES_PARAM=$(echo "$CHANGED_FILES" | tr '\n' ',' | sed 's/,$//')
RESPONSE=$(curl -sf -H "FERN_TOKEN: $FERN_TOKEN" "${PREVIEW_URL}/api/fern-docs/get-slug-for-file?files=${FILES_PARAM}" 2>/dev/null) || {
echo "page_links=" >> $GITHUB_OUTPUT; exit 0
}
PAGE_LINKS=$(echo "$RESPONSE" | jq -r --arg url "$BASE_URL" \
'.mappings[] | select(.slug != null) | "- [\(.slug)](\($url)/\(.slug))"')
if [ -n "$PAGE_LINKS" ]; then
{ echo "page_links<<EOF"; echo "$PAGE_LINKS"; echo "EOF"; } >> $GITHUB_OUTPUT
else
echo "page_links=" >> $GITHUB_OUTPUT
fi
- name: Create comment content
if: steps.check-token.outputs.has_token == 'true'
run: |
echo ":herb: **Preview your docs:** <${STEPS_GENERATE_DOCS_OUTPUTS_PREVIEW_URL}>" > comment.md
if [ -n "${STEPS_PAGE_LINKS_OUTPUTS_PAGE_LINKS}" ]; then
echo "" >> comment.md
echo "Here are the markdown pages you've updated:" >> comment.md
echo "${STEPS_PAGE_LINKS_OUTPUTS_PAGE_LINKS}" >> comment.md
fi
env:
STEPS_GENERATE_DOCS_OUTPUTS_PREVIEW_URL: ${{ steps.generate-docs.outputs.preview_url }}
STEPS_PAGE_LINKS_OUTPUTS_PAGE_LINKS: ${{ steps.page-links.outputs.page_links }}
- name: Post PR comment
if: steps.check-token.outputs.has_token == 'true'
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
with:
file-path: comment.md
comment-tag: preview-docs
mode: upsert