feat: create workflow for generating previews and publishing docs using fern #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate Fern Docs Preview | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
preview: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Checkout aa-sdk | |
uses: actions/checkout@v4 | |
- name: Setup Docs | |
uses: ./.github/actions/setup-docs | |
with: | |
docs-github-token: ${{ secrets.DOCS_GITHUB_TOKEN }} | |
- name: Generate preview URL | |
id: generate-docs | |
env: | |
FERN_TOKEN: ${{ secrets.FERN_TOKEN }} | |
run: | | |
cd docs-site | |
OUTPUT=$(fern generate --docs --preview 2>&1) || true | |
echo "$OUTPUT" | |
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()') | |
echo "preview_url=$URL" >> $GITHUB_OUTPUT | |
- name: Comment Preview URL in PR | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '## 🌿 Documentation Preview\n\n| Name | Preview | Updated (UTC) |\n| :--- | :------ | :------ |\n| **Alchemy Docs** | [🔗 Visit Preview](${{ steps.generate-docs.outputs.preview_url }}) | ' + new Date().toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true }) + ' |\n\n>' | |
}); |