bolt.diy/.github/workflows/ci.yaml
2025-03-14 09:09:24 -07:00

249 lines
7.6 KiB
YAML

name: CI
on:
push:
branches:
- main
pull_request:
deployment_status:
# Cancel in-progress runs when a new commit is pushed
concurrency:
# For pull requests, use the PR number as the concurrency group
# For other events (push, deployment_status), use the branch/ref
# This ensures PR builds are cancelled when new commits are pushed
# And deployment status events don't interfere with push events for the same branch
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.deployment.environment || github.ref }}
cancel-in-progress: true
# Define Node.js version in one place
env:
NODE_VERSION: "22.x"
PNPM_VERSION: 8
jobs:
typecheck:
name: Type Check
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
# Use PNPM store cache to improve performance
- name: PNPM store cache
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Use node_modules cache to improve performance between runs
- name: Cache node_modules
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-modules-
# Install dependencies with fallback for lockfile mismatch
- name: Install dependencies
run: |
# Try frozen install first
pnpm install --frozen-lockfile || \
# If frozen install fails, update lockfile and try again
(echo "Frozen install failed, updating lockfile..." && pnpm install)
- name: Run type check
run: pnpm run typecheck
lint:
name: Lint
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
# Use PNPM store cache to improve performance
- name: PNPM store cache
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Use node_modules cache to improve performance between runs
- name: Cache node_modules
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-modules-
# Install dependencies with fallback for lockfile mismatch
- name: Install dependencies
run: |
# Try frozen install first
pnpm install --frozen-lockfile || \
# If frozen install fails, update lockfile and try again
(echo "Frozen install failed, updating lockfile..." && pnpm install)
- name: Run ESLint
run: pnpm run lint
test:
name: Unit Tests
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
timeout-minutes: 15
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
# Use PNPM store cache to improve performance
- name: PNPM store cache
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Use node_modules cache to improve performance between runs
- name: Cache node_modules
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-modules-
# Install dependencies with fallback for lockfile mismatch
- name: Install dependencies
run: |
# Try frozen install first
pnpm install --frozen-lockfile || \
# If frozen install fails, update lockfile and try again
(echo "Frozen install failed, updating lockfile..." && pnpm install)
- name: Run tests
run: pnpm run test
playwright:
name: Playwright Tests
runs-on: ubuntu-latest
timeout-minutes: 30
if: ${{ (github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success') }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
# Use PNPM store cache to improve performance
- name: PNPM store cache
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Use node_modules cache to improve performance between runs
- name: Cache node_modules
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-modules-
# Install dependencies with fallback for lockfile mismatch
- name: Install dependencies
run: |
# Try frozen install first
pnpm install --frozen-lockfile || \
# If frozen install fails, update lockfile and try again
(echo "Frozen install failed, updating lockfile..." && pnpm install)
# Cache Playwright browsers to speed up workflow
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright browsers
run: pnpm playwright install chromium
- name: Get Vercel Preview URL
run: |
echo "PLAYWRIGHT_TEST_BASE_URL=${{ github.event.deployment_status.target_url }}" >> $GITHUB_ENV
echo "Testing against Vercel Preview URL: ${{ github.event.deployment_status.target_url }}"
- name: Run Playwright tests against Vercel preview
if: ${{ github.event_name == 'deployment_status' }}
run: pnpm run test:e2e
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 30