Skip to content

Using NEXT_PUBLIC_VERCEL_ENV to determine whether to reroute chat/suggest endpoints #2438

Using NEXT_PUBLIC_VERCEL_ENV to determine whether to reroute chat/suggest endpoints

Using NEXT_PUBLIC_VERCEL_ENV to determine whether to reroute chat/suggest endpoints #2438

name: Preview @fern-docs/bundle
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.head.ref || github.ref_name || github.ref }}
cancel-in-progress: true
jobs:
ignore:
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.ignore.outputs.continue }}
check_changes: ${{ steps.check_changes.outputs.continue }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # used for turbo-ignore
- name: Check for changes in playwright or github actions
id: check_changes
run: |
if git diff --name-only HEAD~1 -- playwright/ .github/workflows/; then
echo "continue=1" >> $GITHUB_OUTPUT
fi
- name: Ignore unchanged files
id: ignore
if: steps.check_changes.outputs.continue != 1
uses: ./.github/actions/turbo-ignore
with:
token: ${{ secrets.VERCEL_TOKEN }}
project: "app.buildwithfern.com"
package: "@fern-docs/bundle"
environment: "preview"
branch: ${{ github.event.pull_request.head.ref || github.ref_name || github.ref }}
deploy:
needs: ignore
if: needs.ignore.outputs.continue == 1 || needs.ignore.outputs.check_changes == 1
runs-on: ubuntu-latest
environment:
name: Preview - app.buildwithfern.com
url: ${{ steps.deploy.outputs.deployment_url }}
outputs:
deployment_url: ${{ steps.deploy.outputs.deployment_url }}
permissions: write-all # required for the pr-preview comment
steps:
# set the ref to a specific branch so that the deployment is scoped to that branch (instead of a headless ref)
- uses: actions/checkout@v4
with:
fetch-depth: 2 # used for turbo-ignore
ref: ${{ github.event.pull_request.head.ref || github.ref_name || github.ref }}
- uses: ./.github/actions/install
- name: Build & Deploy to Vercel
id: deploy
run: |
pnpm vercel-scripts deploy app.buildwithfern.com --token=${{ secrets.VERCEL_TOKEN }}
if [ -f deployment-url.txt ]; then
pnpm vercel-scripts preview.txt $(cat deployment-url.txt) --token=${{ secrets.VERCEL_TOKEN }}
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
fi
- name: Comment PR Preview
uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request' && steps.deploy.outputs.deployment_url
with:
filePath: preview.txt
comment_tag: pr_preview
analyze:
needs: ignore
if: needs.ignore.outputs.continue == 1 || needs.ignore.outputs.check_changes == 1
runs-on: ubuntu-latest
permissions: write-all # required for the pr-preview comment
steps:
# set the ref to a specific branch so that the deployment is scoped to that branch (instead of a headless ref)
- uses: actions/checkout@v4
with:
fetch-depth: 2 # used for turbo-ignore
ref: ${{ github.event.pull_request.head.ref || github.ref_name || github.ref }}
- uses: ./.github/actions/install
- name: Build
id: deploy
run: pnpm vercel-scripts deploy app.buildwithfern.com --token=${{ secrets.VERCEL_TOKEN }} --skip-deploy=true
env:
ANALYZE: 1
- name: Analyze bundle
run: pnpm --package=nextjs-bundle-analysis dlx report
- name: Upload analysis
uses: actions/upload-artifact@v4
with:
name: bundle
path: packages/fern-docs/bundle/.next/analyze/__bundle_analysis.json
- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v6
if: success() && github.event.number
with:
workflow: deploy-docs-bundle-preview.yml
branch: ${{ github.event.pull_request.base.ref }}
path: packages/fern-docs/bundle/.next/analyze/base
# https://infrequently.org/2021/03/the-performance-inequality-gap/
- name: Compare with base branch bundle
if: success() && github.event.number
run: ls -laR packages/fern-docs/bundle/.next/analyze/base && pnpm --package=nextjs-bundle-analysis dlx compare
- name: Comment PR Bundle Analysis
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
filePath: packages/fern-docs/bundle/.next/analyze/__bundle_analysis_comment.txt
comment_tag: bundle_analysis
deploy-dev:
needs: ignore
if: needs.ignore.outputs.continue == 1 || needs.ignore.outputs.check_changes == 1
runs-on: ubuntu-latest
environment:
name: Preview - app-dev.buildwithfern.com
url: ${{ steps.deploy.outputs.deployment_url }}
outputs:
deployment_url: ${{ steps.deploy.outputs.deployment_url }}
steps:
# set the ref to a specific branch so that the deployment is scoped to that branch (instead of a headless ref)
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref_name || github.ref }}
- uses: ./.github/actions/install
- name: Build & Deploy to Vercel
id: deploy
run: |
pnpm vercel-scripts deploy app-dev.buildwithfern.com --token=${{ secrets.VERCEL_TOKEN }}
echo "deployment_url=$(cat deployment-url.txt)" >> $GITHUB_OUTPUT
ete:
needs:
- ignore
- deploy # only runs on fern-prod
if: always() && (needs.deploy.result == 'success' || needs.deploy.result == 'skipped')
uses: ./.github/workflows/playwright.yml
permissions: write-all
with:
deployment_url: ${{ needs.deploy.outputs.deployment_url || '' }}
secrets:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}