Skip to content

Commit 6ae4ac2

Browse files
committed
Restructure CI
1 parent 22db318 commit 6ae4ac2

File tree

6 files changed

+490
-313
lines changed

6 files changed

+490
-313
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: 'Deploy cloudflare'
2+
description: 'Deploy GitBook to Cloudflare'
3+
inputs:
4+
apiToken:
5+
description: 'Cloudflare API token'
6+
required: true
7+
accountId:
8+
description: 'Cloudflare account ID'
9+
required: true
10+
environment:
11+
description: 'Environment to deploy to'
12+
required: true
13+
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY:
14+
description: 'Next server actions encryption key'
15+
required: true
16+
GITBOOK_URL:
17+
description: 'GitBook URL'
18+
required: true
19+
GITBOOK_IMAGE_RESIZE_SIGNING_KEY:
20+
description: 'GitBook image resize signing key'
21+
required: true
22+
GITBOOK_IMAGE_RESIZE_URL:
23+
description: 'GitBook image resize URL'
24+
required: true
25+
GITBOOK_ICONS_URL:
26+
description: 'GitBook icons URL'
27+
required: true
28+
GITBOOK_ICONS_TOKEN:
29+
description: 'GitBook icons token'
30+
required: true
31+
GITBOOK_ASSETS_PREFIX:
32+
description: 'GitBook assets prefix'
33+
required: false
34+
outputs:
35+
deployment-url:
36+
description: "Deployment URL"
37+
value: ${{ steps.deploy.outputs.deployment-url }}
38+
runs:
39+
using: 'composite'
40+
steps:
41+
- name: Setup Bun
42+
uses: ./.github/composite/setup-bun
43+
- name: Install dependencies
44+
run: bun install --frozen-lockfile
45+
shell: bash
46+
env:
47+
PUPPETEER_SKIP_DOWNLOAD: 1
48+
- name: Build worker
49+
run: bun run turbo build:v2:cloudflare
50+
env:
51+
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ inputs.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
52+
GITBOOK_URL: ${{ inputs.GITBOOK_URL }}
53+
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
54+
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.GITBOOK_IMAGE_RESIZE_URL }}
55+
GITBOOK_ICONS_URL: ${{ inputs.GITBOOK_ICONS_URL }}
56+
GITBOOK_ICONS_TOKEN: ${{ inputs.GITBOOK_ICONS_TOKEN }}
57+
GITBOOK_ASSETS_PREFIX: ${{ inputs.GITBOOK_ASSETS_PREFIX }}
58+
- id: deploy
59+
name: Deploy to Cloudflare
60+
uses: cloudflare/[email protected]
61+
with:
62+
apiToken: ${{ inputs.apiToken }}
63+
accountId: ${{ inputs.accountId }}
64+
workingDirectory: ./
65+
wranglerVersion: '3.112.0'
66+
environment: ${{ inputs.environment }}
67+
command: ${{ inputs.environment == 'production' && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml

.github/workflows/ci.yaml

Lines changed: 0 additions & 311 deletions
Original file line numberDiff line numberDiff line change
@@ -7,317 +7,6 @@ on:
77
env:
88
NPM_TOKEN_READONLY: ${{ secrets.NPM_TOKEN_READONLY }}
99
jobs:
10-
deploy:
11-
name: Deploy to Cloudflare Pages
12-
runs-on: ubuntu-latest
13-
permissions:
14-
contents: read
15-
deployments: write
16-
issues: write
17-
pull-requests: write
18-
checks: write
19-
statuses: write
20-
outputs:
21-
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
22-
deployment-alias-url: ${{ steps.deploy.outputs.deployment-alias-url }}
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v4
26-
- name: Setup Bun
27-
uses: ./.github/composite/setup-bun
28-
- name: Install dependencies
29-
run: bun install --frozen-lockfile
30-
env:
31-
PUPPETEER_SKIP_DOWNLOAD: 1
32-
- name: Sets env vars for production
33-
run: |
34-
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
35-
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
36-
if: startsWith(github.ref, 'refs/heads/main')
37-
- name: Sets env vars for preview
38-
run: |
39-
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
40-
if: 1 && !startsWith(github.ref, 'refs/heads/main')
41-
- name: Build Next.js with next-on-pages
42-
run: bun run turbo gitbook#build:cloudflare
43-
env:
44-
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
45-
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
46-
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
47-
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
48-
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
49-
SENTRY_RELEASE: ${{ github.sha }}
50-
- id: deploy
51-
name: Deploy to Cloudflare
52-
uses: cloudflare/[email protected]
53-
with:
54-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
55-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
56-
workingDirectory: ./
57-
wranglerVersion: '3.82.0'
58-
command: pages deploy ./packages/gitbook/.vercel/output/static --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME }} --branch=${{ github.ref == 'refs/heads/main' && 'main' || format('pr{0}', github.event.pull_request.number) }}
59-
- name: Outputs
60-
run: |
61-
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
62-
echo "Alias URL: ${{ steps.deploy.outputs.deployment-alias-url }}"
63-
- name: Archive build output
64-
uses: actions/upload-artifact@v4
65-
with:
66-
name: build-output
67-
path: .vercel/
68-
# Until https://github.com/cloudflare/wrangler-action/issues/301 is done
69-
- name: Update Deployment Status to Success
70-
env:
71-
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
72-
run: |
73-
curl -X POST \
74-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
75-
-H "Accept: application/vnd.github.v3+json" \
76-
-d '{"state": "success", "target_url": "${{ steps.deploy.outputs.deployment-url }}", "description": "Deployed Preview URL for commit", "context": "cloudflare/preview"}' \
77-
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}
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-
steps:
91-
- name: Checkout
92-
uses: actions/checkout@v4
93-
- name: Deploy ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
94-
id: deploy
95-
uses: ./.github/composite/deploy-vercel
96-
with:
97-
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
98-
vercel-org: ${{ secrets.VERCEL_ORG_ID }}
99-
vercel-project: ${{ secrets.VERCEL_PROJECT_ID }}
100-
vercel-token: ${{ secrets.VERCEL_TOKEN }}
101-
deploy-v2-vercel-staging:
102-
name: Deploy v2 to Vercel (staging)
103-
runs-on: ubuntu-latest
104-
permissions:
105-
contents: read
106-
deployments: write
107-
issues: write
108-
pull-requests: write
109-
checks: write
110-
statuses: write
111-
if: startsWith(github.ref, 'refs/heads/main')
112-
outputs:
113-
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
114-
steps:
115-
- name: Checkout
116-
uses: actions/checkout@v4
117-
- name: Deploy staging
118-
id: deploy
119-
uses: ./.github/composite/deploy-vercel
120-
with:
121-
environment: staging
122-
vercel-org: ${{ secrets.VERCEL_ORG_ID }}
123-
vercel-project: ${{ secrets.VERCEL_PROJECT_ID }}
124-
vercel-token: ${{ secrets.VERCEL_TOKEN }}
125-
deploy-v2-cloudflare:
126-
name: Deploy v2 to Cloudflare Worker
127-
runs-on: ubuntu-latest
128-
permissions:
129-
contents: read
130-
deployments: write
131-
issues: write
132-
pull-requests: write
133-
checks: write
134-
statuses: write
135-
outputs:
136-
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
137-
steps:
138-
- name: Checkout
139-
uses: actions/checkout@v4
140-
- name: Setup Bun
141-
uses: ./.github/composite/setup-bun
142-
- name: Install dependencies
143-
run: bun install --frozen-lockfile
144-
env:
145-
PUPPETEER_SKIP_DOWNLOAD: 1
146-
- name: Sets env vars for production
147-
run: |
148-
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
149-
echo "GITBOOK_URL=https://open-2c.gitbook.com" >> $GITHUB_ENV
150-
echo "GITBOOK_ASSETS_PREFIX=https://static-2c.gitbook.com" >> $GITHUB_ENV
151-
if: startsWith(github.ref, 'refs/heads/main')
152-
- name: Sets env vars for preview
153-
run: |
154-
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
155-
if: 1 && !startsWith(github.ref, 'refs/heads/main')
156-
- name: Build worker
157-
run: bun run turbo build:v2:cloudflare
158-
env:
159-
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
160-
GITBOOK_URL: https://gitbook-v2.gitbook.workers.dev/
161-
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ secrets.PREVIEW_GITBOOK_IMAGE_RESIZE_SIGNING_KEY }}
162-
GITBOOK_IMAGE_RESIZE_URL: ${{ env.GITBOOK_IMAGE_RESIZE_URL }}
163-
GITBOOK_ICONS_URL: ${{ env.GITBOOK_ICONS_URL }}
164-
GITBOOK_ICONS_TOKEN: ${{ env.GITBOOK_ICONS_TOKEN }}
165-
- id: deploy
166-
name: Deploy to Cloudflare
167-
uses: cloudflare/[email protected]
168-
with:
169-
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
170-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
171-
workingDirectory: ./
172-
wranglerVersion: '3.112.0'
173-
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
174-
command: versions upload --config ./packages/gitbook-v2/wrangler.toml
175-
- name: Outputs
176-
run: |
177-
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
178-
comment-deployments:
179-
runs-on: ubuntu-latest
180-
name: Comment Deployments
181-
if: always() && !startsWith(github.ref, 'refs/heads/main')
182-
needs:
183-
- deploy
184-
- deploy-v2-vercel
185-
- deploy-v2-cloudflare
186-
steps:
187-
- name: Find GitHub Comment
188-
uses: peter-evans/find-comment@v3
189-
id: fc
190-
with:
191-
issue-number: ${{ github.event.pull_request.number }}
192-
comment-author: 'github-actions[bot]'
193-
body-includes: 'Summary of the deployments'
194-
195-
- name: Create or update GitHub comment
196-
uses: peter-evans/create-or-update-comment@v4
197-
with:
198-
comment-id: ${{ steps.fc.outputs.comment-id }}
199-
issue-number: ${{ github.event.pull_request.number }}
200-
body: |
201-
Summary of the deployments:
202-
203-
### Version 1 (production)
204-
205-
| Version | URL | Status |
206-
| --- | --- | --- |
207-
| Latest commit | [${{ needs.deploy.outputs.deployment-url }}](${{ needs.deploy.outputs.deployment-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
208-
| PR | [${{ needs.deploy.outputs.deployment-alias-url }}](${{ needs.deploy.outputs.deployment-alias-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
209-
210-
### Version 2 (experimental)
211-
212-
| Version | URL | Status |
213-
| --- | --- | --- |
214-
| Vercel | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}](${{ needs.deploy-v2-vercel.outputs.deployment-url }}) | ${{ needs.deploy-v2-vercel.result == 'success' && '✅' || '❌' }} |
215-
| Cloudflare | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v2-cloudflare.result == 'success' && '✅' || '❌' }} |
216-
217-
### Test content
218-
219-
| Site | v1 | v2 |
220-
| --- | --- | --- |
221-
| GitBook | [${{ needs.deploy.outputs.deployment-url }}/docs.gitbook.com](${{ needs.deploy.outputs.deployment-url }}/docs.gitbook.com) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/docs.gitbook.com](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/docs.gitbook.com) |
222-
| 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 }}/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open) |
223-
edit-mode: replace
224-
visual-testing:
225-
runs-on: ubuntu-latest
226-
name: Visual Testing
227-
needs: deploy
228-
timeout-minutes: 8
229-
steps:
230-
- name: Checkout
231-
uses: actions/checkout@v4
232-
- name: Setup Bun
233-
uses: ./.github/composite/setup-bun
234-
- name: Install dependencies
235-
run: bun install --frozen-lockfile
236-
- name: Setup Playwright
237-
uses: ./.github/actions/setup-playwright
238-
- name: Run Playwright tests
239-
run: bun e2e
240-
env:
241-
BASE_URL: ${{ needs.deploy.outputs.deployment-url }}
242-
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
243-
visual-testing-v2:
244-
runs-on: ubuntu-latest
245-
name: Visual Testing v2
246-
needs: deploy-v2-vercel
247-
timeout-minutes: 10
248-
steps:
249-
- name: Checkout
250-
uses: actions/checkout@v4
251-
- name: Setup Bun
252-
uses: ./.github/composite/setup-bun
253-
- name: Install dependencies
254-
run: bun install --frozen-lockfile
255-
- name: Setup Playwright
256-
uses: ./.github/actions/setup-playwright
257-
- name: Run Playwright tests
258-
run: bun e2e
259-
env:
260-
BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
261-
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
262-
ARGOS_BUILD_NAME: 'v2'
263-
visual-testing-customers:
264-
runs-on: ubuntu-latest
265-
name: Visual Testing Customers
266-
needs: deploy
267-
timeout-minutes: 6
268-
steps:
269-
- name: Checkout
270-
uses: actions/checkout@v4
271-
- name: Setup Bun
272-
uses: ./.github/composite/setup-bun
273-
- name: Install dependencies
274-
run: bun install --frozen-lockfile
275-
- name: Setup Playwright
276-
uses: ./.github/actions/setup-playwright
277-
- name: Run Playwright tests
278-
run: bun e2e-customers
279-
env:
280-
BASE_URL: ${{ needs.deploy.outputs.deployment-url }}
281-
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
282-
ARGOS_BUILD_NAME: 'customers'
283-
visual-testing-customers-v2:
284-
runs-on: ubuntu-latest
285-
name: Visual Testing Customers v2
286-
needs: deploy-v2-vercel
287-
timeout-minutes: 6
288-
steps:
289-
- name: Checkout
290-
uses: actions/checkout@v4
291-
- name: Setup Bun
292-
uses: ./.github/composite/setup-bun
293-
- name: Install dependencies
294-
run: bun install --frozen-lockfile
295-
- name: Setup Playwright
296-
uses: ./.github/actions/setup-playwright
297-
- name: Run Playwright tests
298-
run: bun e2e-customers
299-
env:
300-
BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
301-
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
302-
ARGOS_BUILD_NAME: 'customers-v2'
303-
pagespeed-testing:
304-
runs-on: ubuntu-latest
305-
name: PageSpeed Testing
306-
needs: deploy
307-
steps:
308-
- name: Checkout
309-
uses: actions/checkout@v4
310-
- name: Setup Bun
311-
uses: ./.github/composite/setup-bun
312-
- name: Install dependencies
313-
run: bun install --frozen-lockfile
314-
env:
315-
PUPPETEER_SKIP_DOWNLOAD: 1
316-
- name: Run pagespeed tests
317-
run: bun ./packages/gitbook/tests/pagespeed-testing.ts $DEPLOYMENT_URL
318-
env:
319-
DEPLOYMENT_URL: ${{needs.deploy.outputs.deployment-url}}
320-
PAGESPEED_API_KEY: ${{ secrets.PAGESPEED_API_KEY }}
32110
format:
32211
runs-on: ubuntu-latest
32312
name: Format

0 commit comments

Comments
 (0)