feat: create workflow for generating previews and publishing docs using fern #3
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: Download Alchemy Docs Repo | |
run: | | |
rm -rf docs-site && \ | |
curl -L -f -H "Authorization: token ${{ secrets.DOCS_GITHUB_TOKEN }}" \ | |
-o docs.tar.gz https://api.github.com/repos/alchemyplatform/docs/tarball/main && \ | |
tar xzf docs.tar.gz && \ | |
mv alchemyplatform-docs-* docs-site && \ | |
rm docs.tar.gz | |
- name: Copy docs to docs-site/account-kit and cd into docs-site | |
run: | | |
mkdir -p docs-site/account-kit | |
cp -r docs/* docs-site/account-kit/ | |
- name: Insert Account Kit docs.yml into docs-site/fern/docs.yml | |
run: | | |
cd docs-site | |
account-kit/scripts/insert-docs.sh | |
- name: Install Fern CLI | |
run: npm install -g fern-api | |
- 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 }).replace(',', '') + ' |\n\n>' | |
}); |