-
Notifications
You must be signed in to change notification settings - Fork 4
160 lines (141 loc) · 5.83 KB
/
deploy-docs-bundle-preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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 }}