mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
3d1eb53708
Co-authored-by: Valentino Hudhra <v.hudhra@gmail.com> Co-authored-by: Valentino Hudhra <2587839+valentin0h@users.noreply.github.com>
367 lines
16 KiB
YAML
367 lines
16 KiB
YAML
name: CI
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
env:
|
|
NPM_TOKEN_READONLY: ${{ secrets.NPM_TOKEN_READONLY }}
|
|
jobs:
|
|
deploy:
|
|
name: Deploy to Cloudflare Pages
|
|
runs-on: ubuntu-latest
|
|
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
|
|
run: |
|
|
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
|
|
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
|
|
if: startsWith(github.ref, 'refs/heads/main')
|
|
- name: Sets env vars for preview
|
|
run: |
|
|
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
|
|
if: 1 && !startsWith(github.ref, 'refs/heads/main')
|
|
- name: Build Next.js with next-on-pages
|
|
run: bun run turbo build:cloudflare
|
|
env:
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
|
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
|
|
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
|
SENTRY_RELEASE: ${{ github.sha }}
|
|
- id: deploy
|
|
name: Deploy to Cloudflare
|
|
uses: cloudflare/wrangler-action@v3.11.0
|
|
with:
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '3.82.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 }}"
|
|
- name: Archive build output
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: build-output
|
|
path: .vercel/
|
|
# Until https://github.com/cloudflare/wrangler-action/issues/301 is done
|
|
- name: Update Deployment Status to Success
|
|
env:
|
|
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
|
|
run: |
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
-d '{"state": "success", "target_url": "${{ steps.deploy.outputs.deployment-url }}", "description": "Deployed Preview URL for commit", "context": "cloudflare/preview"}' \
|
|
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}
|
|
deploy-v2-vercel:
|
|
name: Deploy v2 to Vercel
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
deployments: write
|
|
issues: write
|
|
pull-requests: write
|
|
checks: write
|
|
statuses: write
|
|
outputs:
|
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
|
env:
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
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
|
|
run: |
|
|
echo "VERCEL_ENVIRONMENT=production" >> $GITHUB_ENV
|
|
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
|
|
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
|
|
if: startsWith(github.ref, 'refs/heads/main')
|
|
- name: Sets env vars for preview
|
|
run: |
|
|
echo "VERCEL_ENVIRONMENT=preview" >> $GITHUB_ENV
|
|
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
|
|
if: 1 && !startsWith(github.ref, 'refs/heads/main')
|
|
- name: Pull Vercel Environment Information
|
|
run: bun run vercel pull --yes --environment=$VERCEL_ENVIRONMENT --token=${{ secrets.VERCEL_TOKEN }}
|
|
- name: Build Project Artifacts
|
|
run: bun run vercel build --token=${{ secrets.VERCEL_TOKEN }}
|
|
env:
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
|
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
|
|
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
|
SENTRY_RELEASE: ${{ github.sha }}
|
|
- name: Deploy Project Artifacts to Vercel
|
|
id: deploy
|
|
run: |
|
|
DEPLOYMENT_URL=$(bun run vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
|
|
echo "deployment-url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT"
|
|
- name: Outputs
|
|
run: |
|
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
|
deploy-v2-cloudflare:
|
|
name: Deploy v2 to Cloudflare Worker
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
deployments: write
|
|
issues: write
|
|
pull-requests: write
|
|
checks: write
|
|
statuses: write
|
|
outputs:
|
|
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
|
env:
|
|
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
|
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
|
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
|
|
run: |
|
|
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
|
|
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
|
|
if: startsWith(github.ref, 'refs/heads/main')
|
|
- name: Sets env vars for preview
|
|
run: |
|
|
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
|
|
if: 1 && !startsWith(github.ref, 'refs/heads/main')
|
|
- name: Build worker
|
|
run: bun run turbo build:v2:cloudflare
|
|
env:
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
|
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
|
|
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
|
SENTRY_RELEASE: ${{ github.sha }}
|
|
- id: deploy
|
|
name: Deploy to Cloudflare
|
|
uses: cloudflare/wrangler-action@v3.11.0
|
|
with:
|
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
workingDirectory: ./
|
|
wranglerVersion: '3.82.0'
|
|
command: versions upload --config ./packages/gitbook-v2/wrangler.toml
|
|
- name: Outputs
|
|
run: |
|
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
|
comment-deployments:
|
|
runs-on: ubuntu-latest
|
|
name: Comment Deployments
|
|
if: always() && !startsWith(github.ref, 'refs/heads/main')
|
|
needs:
|
|
- deploy
|
|
- 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 (production)
|
|
|
|
| Version | URL | Status |
|
|
| --- | --- | --- |
|
|
| Latest commit | [${{ needs.deploy.outputs.deployment-url }}](${{ needs.deploy.outputs.deployment-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
|
|
| PR | [${{ needs.deploy.outputs.deployment-alias-url }}](${{ needs.deploy.outputs.deployment-alias-url }}) | ${{ needs.deploy.result == 'success' && '✅' || '❌' }} |
|
|
|
|
### Version 2 (experimental)
|
|
|
|
| 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 | v2 |
|
|
| --- | --- | --- |
|
|
| 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) |
|
|
| 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) |
|
|
edit-mode: replace
|
|
visual-testing:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing
|
|
needs: deploy
|
|
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.outputs.deployment-url}}
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
- uses: actions/upload-artifact@v4
|
|
if: ${{ !cancelled() }}
|
|
with:
|
|
name: playwright-test-results
|
|
path: packages/gitbook/test-results/
|
|
retention-days: 3
|
|
visual-testing-customers:
|
|
runs-on: ubuntu-latest
|
|
name: Visual Testing Customers
|
|
needs: deploy
|
|
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.outputs.deployment-url}}
|
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
|
ARGOS_BUILD_NAME: 'customers'
|
|
- uses: actions/upload-artifact@v4
|
|
if: ${{ !cancelled() }}
|
|
with:
|
|
name: playwright-test-results-customers
|
|
path: packages/gitbook/test-results/
|
|
retention-days: 3
|
|
pagespeed-testing:
|
|
runs-on: ubuntu-latest
|
|
name: PageSpeed Testing
|
|
needs: deploy
|
|
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 $DEPLOYMENT_URL
|
|
env:
|
|
DEPLOYMENT_URL: ${{needs.deploy.outputs.deployment-url}}
|
|
PAGESPEED_API_KEY: ${{ secrets.PAGESPEED_API_KEY }}
|
|
format:
|
|
runs-on: ubuntu-latest
|
|
name: Format
|
|
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
|
|
- run: bun format:check
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
name: Lint
|
|
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
|
|
- run: bun lint --no-cache
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
name: Test
|
|
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
|
|
- run: bun unit
|
|
build-oss:
|
|
# CI to check that the repository builds correctly on a machine without the credentials
|
|
runs-on: ubuntu-latest
|
|
name: Build (Open Source)
|
|
env:
|
|
NPM_TOKEN_READONLY: ''
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
- name: Setup Bun
|
|
uses: ./.github/composite/setup-bun
|
|
- name: Install dependencies
|
|
run: bun install
|
|
env:
|
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
|
- run: bun run build
|
|
typecheck:
|
|
runs-on: ubuntu-latest
|
|
name: Typecheck
|
|
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
|
|
- run: bun typecheck
|