Skip to content

Commit cfccc44

Browse files
authored
Setup package and deployment for v2 (#2791)
1 parent 45b30c9 commit cfccc44

File tree

24 files changed

+2927
-314
lines changed

24 files changed

+2927
-314
lines changed

.changeset/angry-dots-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook-v2': minor
3+
---
4+
5+
Setup structure and deployment for new version

.github/workflows/ci.yaml

Lines changed: 149 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
checks: write
1919
statuses: write
2020
outputs:
21-
deployment_url: ${{ steps.deploy.outputs.deployment-url }}
21+
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
22+
deployment-alias-url: ${{ steps.deploy.outputs.deployment-alias-url }}
2223
steps:
2324
- name: Checkout
2425
uses: actions/checkout@v4
@@ -38,7 +39,7 @@ jobs:
3839
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
3940
if: 1 && !startsWith(github.ref, 'refs/heads/main')
4041
- name: Build Next.js with next-on-pages
41-
run: bun run build:cloudflare
42+
run: bun run turbo build:cloudflare
4243
env:
4344
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
4445
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
@@ -74,26 +75,163 @@ jobs:
7475
-H "Accept: application/vnd.github.v3+json" \
7576
-d '{"state": "success", "target_url": "${{ steps.deploy.outputs.deployment-url }}", "description": "Deployed Preview URL for commit", "context": "cloudflare/preview"}' \
7677
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}
77-
78+
deploy-v2-vercel:
79+
name: Deploy v2 to Vercel
80+
runs-on: ubuntu-latest
81+
permissions:
82+
contents: read
83+
deployments: write
84+
issues: write
85+
pull-requests: write
86+
checks: write
87+
statuses: write
88+
outputs:
89+
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
90+
env:
91+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
92+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
93+
steps:
94+
- name: Checkout
95+
uses: actions/checkout@v4
96+
- name: Setup Bun
97+
uses: ./.github/composite/setup-bun
98+
- name: Install dependencies
99+
run: bun install --frozen-lockfile
100+
env:
101+
PUPPETEER_SKIP_DOWNLOAD: 1
102+
- name: Sets env vars for production
103+
run: |
104+
echo "VERCEL_ENVIRONMENT=production" >> $GITHUB_ENV
105+
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
106+
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
107+
if: startsWith(github.ref, 'refs/heads/main')
108+
- name: Sets env vars for preview
109+
run: |
110+
echo "VERCEL_ENVIRONMENT=preview" >> $GITHUB_ENV
111+
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
112+
if: 1 && !startsWith(github.ref, 'refs/heads/main')
113+
- name: Pull Vercel Environment Information
114+
run: bun run vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }}
115+
- name: Build Project Artifacts
116+
run: bun run vercel build --token=${{ secrets.VERCEL_TOKEN }}
117+
env:
118+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
119+
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
120+
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
121+
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
122+
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
123+
SENTRY_RELEASE: ${{ github.sha }}
124+
- name: Deploy Project Artifacts to Vercel
125+
id: deploy
126+
run: |
127+
DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
128+
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
129+
- name: Outputs
130+
run: |
131+
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
132+
deploy-v2-cloudflare:
133+
name: Deploy v2 to Cloudflare Worker
134+
runs-on: ubuntu-latest
135+
permissions:
136+
contents: read
137+
deployments: write
138+
issues: write
139+
pull-requests: write
140+
checks: write
141+
statuses: write
142+
outputs:
143+
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
144+
env:
145+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
146+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
147+
steps:
148+
- name: Checkout
149+
uses: actions/checkout@v4
150+
- name: Setup Bun
151+
uses: ./.github/composite/setup-bun
152+
- name: Install dependencies
153+
run: bun install --frozen-lockfile
154+
env:
155+
PUPPETEER_SKIP_DOWNLOAD: 1
156+
- name: Sets env vars for production
157+
run: |
158+
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
159+
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
160+
if: startsWith(github.ref, 'refs/heads/main')
161+
- name: Sets env vars for preview
162+
run: |
163+
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
164+
if: 1 && !startsWith(github.ref, 'refs/heads/main')
165+
- name: Build worker
166+
run: bun run turbo build:v2:cloudflare
167+
env:
168+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
169+
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
170+
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
171+
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
172+
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
173+
SENTRY_RELEASE: ${{ github.sha }}
174+
- id: deploy
175+
name: Deploy to Cloudflare
176+
uses: cloudflare/[email protected]
177+
with:
178+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
179+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
180+
workingDirectory: ./
181+
wranglerVersion: '3.82.0'
182+
command: versions upload --config ./packages/gitbook-v2/wrangler.toml
183+
- name: Outputs
184+
run: |
185+
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
186+
comment-deployments:
187+
runs-on: ubuntu-latest
188+
name: Comment Deployments
189+
if: always() && !startsWith(github.ref, 'refs/heads/main')
190+
needs:
191+
- deploy
192+
- deploy-v2-vercel
193+
- deploy-v2-cloudflare
194+
steps:
195+
- name: Checkout
196+
uses: actions/checkout@v4
197+
- name: Setup Bun
198+
uses: ./.github/composite/setup-bun
78199
- name: Find GitHub Comment
79200
uses: peter-evans/find-comment@v3
80201
id: fc
81-
if: 1 && !startsWith(github.ref, 'refs/heads/main')
82202
with:
83203
issue-number: ${{ github.event.pull_request.number }}
84204
comment-author: 'github-actions[bot]'
85-
body-includes: GitBook Preview
205+
body-includes: 'Summary of the deployments'
86206

87207
- name: Create or update GitHub comment
88208
uses: peter-evans/create-or-update-comment@v4
89-
if: 1 && !startsWith(github.ref, 'refs/heads/main')
90209
with:
91210
comment-id: ${{ steps.fc.outputs.comment-id }}
92211
issue-number: ${{ github.event.pull_request.number }}
93212
body: |
94-
**GitBook Preview**
95-
Latest commit: [${{ steps.deploy.outputs.deployment-url }}](${{ steps.deploy.outputs.deployment-url }})
96-
PR: [${{ steps.deploy.outputs.deployment-alias-url }}](${{ steps.deploy.outputs.deployment-alias-url }})
213+
Summary of the deployments:
214+
215+
### Version 1 (production)
216+
217+
| Version | URL | Status |
218+
| --- | --- | --- |
219+
| Latest commit | [${{ needs.deploy.outputs.deployment-url }}](${{ needs.deploy.outputs.deployment-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
220+
| PR | [${{ needs.deploy.outputs.deployment-alias-url }}](${{ needs.deploy.outputs.deployment-alias-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
221+
222+
### Version 2 (experimental)
223+
224+
| Version | URL | Status |
225+
| --- | --- | --- |
226+
| Vercel | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}](${{ needs.deploy-v2-vercel.outputs.deployment-url }}) | ${{ needs.deploy-v2-vercel.result == 'success' && '✅' || '❌' }} |
227+
| Cloudflare | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v2-cloudflare.result == 'success' && '✅' || '❌' }} |
228+
229+
### Test content
230+
231+
| Site | v1 | v2 |
232+
| --- | --- | --- |
233+
| GitBook | [${{ needs.deploy.outputs.deployment-url }}/docs.gitbook.com](${{ needs.deploy.outputs.deployment-url }}/docs.gitbook.com) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/static/url/docs.gitbook.com](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/static/url/docs.gitbook.com) |
234+
| E2E | [${{ needs.deploy.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/static/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/static/url/gitbook.gitbook.io/test-gitbook-open) |
97235
edit-mode: replace
98236
visual-testing:
99237
runs-on: ubuntu-latest
@@ -111,7 +249,7 @@ jobs:
111249
- name: Run Playwright tests
112250
run: bun e2e
113251
env:
114-
BASE_URL: ${{needs.deploy.outputs.deployment_url}}
252+
BASE_URL: ${{needs.deploy.outputs.deployment-url}}
115253
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
116254
- uses: actions/upload-artifact@v4
117255
if: ${{ !cancelled() }}
@@ -135,7 +273,7 @@ jobs:
135273
- name: Run pagespeed tests
136274
run: bun ./packages/gitbook/tests/pagespeed-testing.ts $DEPLOYMENT_URL
137275
env:
138-
DEPLOYMENT_URL: ${{needs.deploy.outputs.deployment_url}}
276+
DEPLOYMENT_URL: ${{needs.deploy.outputs.deployment-url}}
139277
PAGESPEED_API_KEY: ${{ secrets.PAGESPEED_API_KEY }}
140278
format:
141279
runs-on: ubuntu-latest

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.next
22
.vercel
3+
.open-next
34

45
# Generated
56
packages/emoji-codepoints/index.ts

0 commit comments

Comments
 (0)