diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f93303019..925a664b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,16 +2,12 @@ name: tests on: pull_request: - branches: - - main + branches: [main] push: - branches: - - main + branches: [main] schedule: - # Every Saturday - - cron: '0 0 * * 6' + - cron: "0 0 * * 6" # Every Saturday -# Workflow-level concurrency control - cancels previous runs when new commits arrive concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -19,186 +15,112 @@ concurrency: env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} - jobs: - resolve-playwright-version: - name: Resolve Playwright version - runs-on: ubuntu-latest - outputs: - version: ${{ steps.out.outputs.version }} - steps: - - uses: actions/checkout@v5 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - name: Use Node.js 22 - uses: actions/setup-node@v6 - with: - node-version: 22 - cache: pnpm - - # Install dependencies to ensure node_modules/@playwright/test exists - - name: Install dependencies - env: - # do not download browsers here - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" - run: pnpm install --frozen-lockfile - - - name: Read @playwright/test version - id: out - run: | - VER=$(node -e "console.log(require(require.resolve('@playwright/test/package.json')).version)") - echo "version=$VER" >> "$GITHUB_OUTPUT" test: - timeout-minutes: 5 runs-on: ubuntu-latest - strategy: matrix: node-version: [lts/*, latest] - # See: https://github.com/fuma-nama/fumadocs/issues/2456 fail-fast: false steps: - - id: checkout - name: Checkout - uses: actions/checkout@v5 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v6 + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v5 with: node-version: ${{ matrix.node-version }} - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - - - name: Run test - run: pnpm turbo run test + cache: pnpm + - run: pnpm install + - run: pnpm turbo run test test-typesafety: - timeout-minutes: 5 runs-on: ubuntu-latest steps: - - id: checkout - name: Checkout - uses: actions/checkout@v5 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - name: Use Node.js 22 - uses: actions/setup-node@v6 + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v5 with: node-version: 22 - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - - - name: Run typecheck - run: pnpm run typecheck + cache: pnpm + - run: pnpm install + - run: pnpm run typecheck test-build: - timeout-minutes: 5 runs-on: ubuntu-latest - strategy: matrix: node-version: [lts/*, latest] steps: - - id: checkout - name: Checkout - uses: actions/checkout@v5 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v6 + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v5 with: node-version: ${{ matrix.node-version }} - cache: "pnpm" - - - name: Install Bun - uses: oven-sh/setup-bun@v2 + cache: pnpm + - uses: oven-sh/setup-bun@v2 with: bun-version: 1.2.21 + - run: pnpm install + - run: pnpm run build + resolve-playwright-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.out.outputs.version }} + steps: + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v6 + with: + node-version: 22 + cache: pnpm - name: Install dependencies - run: pnpm install - - - name: Run build - run: pnpm run build + env: + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" + run: pnpm install --frozen-lockfile + - name: Read @playwright/test version + id: out + run: | + VER=$(node -e "console.log(require(require.resolve('@playwright/test/package.json')).version)") + echo "version=$VER" >> "$GITHUB_OUTPUT" test-e2e: - name: Test E2E needs: resolve-playwright-version - timeout-minutes: 12 runs-on: ubuntu-latest - - env: - PLAYWRIGHT_TIMEOUT: 300000 - PLAYWRIGHT_HEADLESS: true - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" - + timeout-minutes: 12 container: image: mcr.microsoft.com/playwright:v${{ needs.resolve-playwright-version.outputs.version }}-noble options: --user 1001 - steps: - uses: actions/checkout@v5 with: fetch-depth: 2 - - # Set Turbo base/head for PRs, see: https://turborepo.com/docs/reference/run#--affected - name: Set Turbo base/head for PRs if: ${{ github.event_name == 'pull_request' }} run: | echo "TURBO_SCM_BASE=${{ github.event.pull_request.base.sha || github.event.before }}" >> $GITHUB_ENV echo "TURBO_SCM_HEAD=${{ github.sha }}" >> $GITHUB_ENV - - - name: Install pnpm - uses: pnpm/action-setup@v4 - - - name: Use Node.js - uses: actions/setup-node@v6 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v6 with: node-version: lts/* - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - + cache: pnpm + - run: pnpm install - name: Run E2E (PR) if: ${{ github.event_name == 'pull_request' }} - run: pnpm run test:e2e --affected - env: - TURBO_LOG: info - DEBUG: pw:api - - # Pushes to main - run everything + run: pnpm run test:e2e --affected -v - name: Run E2E (main) if: ${{ github.event_name != 'pull_request' }} - run: pnpm run test:e2e - env: - DEBUG: pw:api - + run: pnpm run test:e2e -v - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: - name: test-results - path: | - **/test-results/** + name: test-results-e2e + path: "**/test-results/**" retention-days: 30 test-windows: if: github.event_name == 'schedule' || contains(join(github.event.pull_request.labels.*.name, ','), 'windows') - timeout-minutes: 15 runs-on: windows-latest strategy: matrix: @@ -216,47 +138,29 @@ jobs: uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - - - name: Cache Playwright browsers - uses: actions/cache@v4 + cache: pnpm + - run: pnpm install + - uses: actions/cache@v4 with: path: ~/.cache/ms-playwright - key: windows-latest-pw-${{ hashFiles('pnpm-lock.yaml') }} + key: windows-latest-pw-${{ hashFiles('pnpm-lock.yaml') }}-${{ matrix.node-version }} restore-keys: | + windows-latest-pw-${{ hashFiles('pnpm-lock.yaml') }}- windows-latest-pw- - - - name: Install Playwright Browsers + - name: Install Playwright browsers run: pnpm exec playwright install --with-deps - - - name: Build - run: pnpm build - - - name: Run test - run: pnpm turbo run test - - - name: Test e2e - run: pnpm run test:e2e - env: - CI: true - PLAYWRIGHT_TIMEOUT: 300000 - DEBUG: pw:api - PLAYWRIGHT_HEADLESS: true - + - run: pnpm build + - run: pnpm turbo run test + - run: pnpm run test:e2e - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: - name: test-results - path: | - **/test-results/** + name: test-results-windows-${{ matrix.node-version }} + path: "**/test-results/**" retention-days: 30 test-macos: if: github.event_name == 'schedule' || contains(join(github.event.pull_request.labels.*.name, ','), 'macos') - timeout-minutes: 15 runs-on: macos-latest strategy: matrix: @@ -274,40 +178,23 @@ jobs: uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - - - name: Cache Playwright browsers - uses: actions/cache@v4 + cache: pnpm + - run: pnpm install + - uses: actions/cache@v4 with: path: ~/.cache/ms-playwright - key: macos-latest-pw-${{ hashFiles('pnpm-lock.yaml') }} + key: macos-latest-pw-${{ hashFiles('pnpm-lock.yaml') }}-${{ matrix.node-version }} restore-keys: | + macos-latest-pw-${{ hashFiles('pnpm-lock.yaml') }}- macos-latest-pw- - - - name: Install Playwright Browsers + - name: Install Playwright browsers run: pnpm exec playwright install --with-deps - - - name: Build - run: pnpm build - - - name: Run test - run: pnpm turbo run test - - - name: Test e2e - run: pnpm run test:e2e - env: - CI: true - PLAYWRIGHT_TIMEOUT: 300000 - DEBUG: pw:api - PLAYWRIGHT_HEADLESS: true - + - run: pnpm build + - run: pnpm turbo run test + - run: pnpm run test:e2e - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: - name: test-results - path: | - **/test-results/** - retention-days: 30 \ No newline at end of file + name: test-results-macos-${{ matrix.node-version }} + path: "**/test-results/**" + retention-days: 30 diff --git a/tooling/playwright-www/playwright.config.ts b/tooling/playwright-www/playwright.config.ts index 45ad12436..ec063c494 100644 --- a/tooling/playwright-www/playwright.config.ts +++ b/tooling/playwright-www/playwright.config.ts @@ -1,108 +1,37 @@ import { defineConfig, devices } from "@playwright/test"; -/** - * @see https://playwright.dev/docs/test-configuration - */ +const isCi = Boolean(process.env.CI); + export default defineConfig({ testDir: "./tests", - /* Run tests in files in parallel */ fullyParallel: true, - /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* Limit test failures to prevent runaway failures */ - maxFailures: 5, - /* Timeout for each test in milliseconds */ - timeout: process.env.CI ? 300000 : 60000, // 5 minutes on CI, 1 minute locally - /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + forbidOnly: isCi, + retries: isCi ? 2 : 0, + workers: isCi ? 1 : undefined, reporter: "html", - /* Output directory for test artifacts */ - outputDir: "./tests/test-results", - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { - /* Base URL to use in actions like `await page.goto('/')`. */ baseURL: "http://localhost:3000", - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: "on-first-retry", - - /* Global timeout configuration */ - actionTimeout: 15000, - navigationTimeout: 30000, }, - /* Configure projects for major browsers */ projects: [ { name: "chromium", use: { ...devices["Desktop Chrome"] }, }, - { name: "firefox", - use: { - ...devices["Desktop Firefox"], - // Firefox-specific timeout configuration - actionTimeout: 15000, - navigationTimeout: 30000, - }, + use: { ...devices["Desktop Firefox"] }, + }, + { + name: "webkit", + use: { ...devices["Desktop Safari"] }, }, - - // WebKit is disabled on WSL2/Linux due to stability issues - // Uncomment the following block if running on macOS or native Linux - // { - // name: "webkit", - // use: { - // ...devices["Desktop Safari"], - // // WebKit-specific timeout configuration - // actionTimeout: 90000, // Increased timeout for WebKit - // navigationTimeout: 90000, - // // WebKit-specific launch options for WSL2/Linux - // launchOptions: { - // args: [ - // '--no-sandbox', - // '--disable-setuid-sandbox', - // '--disable-dev-shm-usage', - // '--disable-gpu', - // '--disable-web-security', - // '--disable-features=VizDisplayCompositor' - // ], - // }, - // }, - // // WebKit-specific: Run with reduced parallelism for stability - // fullyParallel: false, - // workers: 1, - // }, - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { ...devices['Pixel 5'] }, - // }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, ], - /* Run your local dev server before starting the tests */ webServer: { command: "pnpm --filter=www run dev", url: "http://localhost:3000", - reuseExistingServer: !process.env.CI, - timeout: 120_000, + reuseExistingServer: !isCi, }, });