mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
299 lines
14 KiB
YAML
299 lines
14 KiB
YAML
name: Preview
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
env:
|
|
NPM_TOKEN_READONLY: ${{ secrets.NPM_TOKEN_READONLY }}
|
|
jobs:
|
|
deploy-v1-cloudflare:
|
|
name: Deploy v1 to Cloudflare Pages
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: ${{ github.ref == 'refs/heads/main' && '1c-production' || '1c-preview' }}
|
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
|
permissions:
|
|
contents: read
|
|
deployments: write
|
|
issues: write
|
|
pull-requests: write
|
|
checks: write
|
|
statuses: write
|
|
outputs:
|
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
|
deployment-alias-url: ${{ steps.deploy.outputs.deployment-alias-url }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
env:
|
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
|
- name: Sets env vars for production
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
|
|
- name: Build Next.js with next-on-pages
|
|
run: bun run turbo gitbook#build:cloudflare
|
|
env:
|
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
|
GITBOOK_RUNTIME: cloudflare
|
|
- id: deploy
|
|
name: Deploy to Cloudflare
|
|
uses: cloudflare/wrangler-action@v3.14.0
|
|
with:
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '3.112.0'
|
|
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) }}
|
|
- name: Outputs
|
|
run: |
|
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
|
echo "Alias URL: ${{ steps.deploy.outputs.deployment-alias-url }}"
|
|
deploy-v2-vercel:
|
|
name: Deploy v2 to Vercel (preview)
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: 2v-preview
|
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
|
outputs:
|
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Deploy to Vercel
|
|
id: deploy
|
|
uses: ./.github/composite/deploy-vercel
|
|
with:
|
|
environment: preview
|
|
vercelOrg: ${{ secrets.VERCEL_ORG_ID }}
|
|
vercelProject: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
vercelToken: ${{ secrets.VERCEL_TOKEN }}
|
|
opItem: op://gitbook-open/2v-preview
|
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
|
deploy-v2-cloudflare:
|
|
name: Deploy v2 to Cloudflare Worker (preview)
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: 2c-preview
|
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
|
outputs:
|
|
deployment-url: ${{ steps.deploy.outputs.deployment-url || steps.extract-worker-id.outputs.worker-url }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Deploy to Cloudflare
|
|
id: deploy
|
|
uses: ./.github/composite/deploy-cloudflare
|
|
with:
|
|
environment: preview
|
|
deploy: ${{ github.ref == 'refs/heads/main' }}
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
opItem: op://gitbook-open/2c-preview
|
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
|
commitTag: ${{ github.ref == 'refs/heads/main' && 'main' || format('pr{0}', github.event.pull_request.number) }}
|
|
commitMessage: ${{ github.sha }}
|
|
- name: Extract Worker ID
|
|
id: extract-worker-id
|
|
if: ${{ !steps.deploy.outputs.deployment-url }}
|
|
run: |
|
|
if [[ "${{ steps.deploy.outputs.command-output }}" =~ Worker\ Version\ ID:\ ([0-9a-f]{8})-([0-9a-f-]+) ]]; then
|
|
WORKER_ID_FIRST_PART="${BASH_REMATCH[1]}"
|
|
echo "worker-url=https://${WORKER_ID_FIRST_PART}-gitbook-open-v2-preview.gitbook.workers.dev/" >> $GITHUB_OUTPUT
|
|
fi
|
|
- name: Outputs
|
|
run: |
|
|
echo "URL: ${{ steps.deploy.outputs.deployment-url || steps.extract-worker-id.outputs.worker-url }}"
|
|
comment-deployments:
|
|
runs-on: ubuntu-latest
|
|
name: Comment Deployments (preview)
|
|
if: always() && !startsWith(github.ref, 'refs/heads/main')
|
|
needs:
|
|
- deploy-v1-cloudflare
|
|
- deploy-v2-vercel
|
|
- deploy-v2-cloudflare
|
|
steps:
|
|
- name: Find GitHub Comment
|
|
uses: peter-evans/find-comment@v3
|
|
id: fc
|
|
with:
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
comment-author: 'github-actions[bot]'
|
|
body-includes: 'Summary of the deployments'
|
|
|
|
- name: Create or update GitHub comment
|
|
uses: peter-evans/create-or-update-comment@v4
|
|
with:
|
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
body: |
|
|
Summary of the deployments:
|
|
|
|
### Version 1
|
|
|
|
| Version | URL | Status |
|
|
| --- | --- | --- |
|
|
| Latest commit | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
|
| PR | [${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
|
|
|
### Version 2
|
|
|
|
| Version | URL | Status |
|
|
| --- | --- | --- |
|
|
| Vercel | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}](${{ needs.deploy-v2-vercel.outputs.deployment-url }}) | ${{ needs.deploy-v2-vercel.result == 'success' && '✅' || '❌' }} |
|
|
| Cloudflare | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v2-cloudflare.result == 'success' && '✅' || '❌' }} |
|
|
|
|
### Test content
|
|
|
|
| Site | `v1` | `2v` | `2c` |
|
|
| --- | --- | --- | --- |
|
|
| GitBook | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.com/docs](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.com/docs) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.com/docs](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.com/docs) | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.com/docs](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.com/docs) |
|
|
| E2E | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v1-cloudflare.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) | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open) |
|
|
edit-mode: replace
|
|
visual-testing-v1:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing v1
|
|
needs: deploy-v1-cloudflare
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
visual-testing-v2-vercel:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing v2
|
|
needs: deploy-v2-vercel
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}
|
|
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'v2-vercel'
|
|
visual-testing-v2-cloudflare:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing v2 (Cloudflare)
|
|
needs: deploy-v2-cloudflare
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}
|
|
SITE_BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'v2-cloudflare'
|
|
visual-testing-customers-v1:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing Customers v1
|
|
needs: deploy-v1-cloudflare
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e-customers
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'customers-v1'
|
|
visual-testing-customers-v2:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing Customers v2
|
|
needs: deploy-v2-vercel
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e-customers
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}
|
|
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'customers-v2'
|
|
visual-testing-customers-v2-cloudflare:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing Customers v2 (Cloudflare)
|
|
needs: deploy-v2-cloudflare
|
|
timeout-minutes: 10
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
- name: Setup Playwright
|
|
uses: ./.github/actions/setup-playwright
|
|
- name: Run Playwright tests
|
|
run: bun e2e-customers
|
|
env:
|
|
BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}
|
|
SITE_BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'customers-v2'
|
|
pagespeed-testing-v1:
|
|
runs-on: ubuntu-latest
|
|
name: PageSpeed Testing v1
|
|
needs: deploy-v1-cloudflare
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install --frozen-lockfile
|
|
env:
|
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
|
- name: Run pagespeed tests
|
|
run: bun ./packages/gitbook/tests/pagespeed-testing.ts
|
|
env:
|
|
BASE_URL: ${{needs.deploy-v1-cloudflare.outputs.deployment-url}}
|
|
PAGESPEED_API_KEY: ${{ secrets.PAGESPEED_API_KEY }}
|