From fe8938eedbe3df9dd835811e94e5ba68fd5bfd3f Mon Sep 17 00:00:00 2001 From: MaryWylde Date: Mon, 27 Apr 2026 16:45:27 +0400 Subject: [PATCH] chore: update playwright yml --- .github/workflows/playwright-scheduled.yml | 63 +++++++++++----------- playwright.config.ts | 15 +++++- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/.github/workflows/playwright-scheduled.yml b/.github/workflows/playwright-scheduled.yml index 20085f3..f128cee 100644 --- a/.github/workflows/playwright-scheduled.yml +++ b/.github/workflows/playwright-scheduled.yml @@ -3,6 +3,13 @@ name: Playwright scheduled # Runs the Playwright suite weekly and on manual dispatch. # Does NOT gate pull requests — pull-request-check.yml is unrelated. # See QA_PLAN.md §5 for the full specification. +# +# Mirrors the cypress-manual.yml pattern: the workflow builds *this branch's +# source* with the chosen environment's `.env.` file, starts a local +# `next start` server, and runs Playwright against `http://localhost:3005`. +# This decouples the test from whatever is currently deployed at staging / +# prod URLs — newly added selectors, fixtures, and components are exercised +# against real Strapi data without waiting for a deploy. on: schedule: @@ -10,14 +17,14 @@ on: - cron: '0 6 * * 1' workflow_dispatch: inputs: - environment: - description: 'Target environment' + target_env: + description: 'Which env file to build with (controls Strapi backend, OAuth IDs, etc.)' type: choice required: true default: staging options: - staging - - production + - prod scope: description: 'Which tier to run (ignored if spec_path is provided)' type: choice @@ -49,22 +56,16 @@ permissions: jobs: playwright: - name: Playwright (${{ github.event.inputs.environment || 'staging' }} / ${{ github.event.inputs.scope || 'all' }} / ${{ github.event.inputs.browser || 'chromium' }}) + name: Playwright (${{ github.event.inputs.target_env || 'staging' }} / ${{ github.event.inputs.scope || 'all' }} / ${{ github.event.inputs.browser || 'chromium' }}) runs-on: ubuntu-latest timeout-minutes: 45 env: CI: 'true' - # scheduled run. Leave unset → the job will fail fast with a clear - # message instead of silently hitting localhost. - # - # Suggested setup: - # If the environment needs auth headers or cookies to reach the app, - # add those as repo secrets and wire them through `env:` here. - PLAYWRIGHT_STAGING_URL: ${{ secrets.PLAYWRIGHT_STAGING_URL }} - PLAYWRIGHT_PRODUCTION_URL: ${{ secrets.PLAYWRIGHT_PRODUCTION_URL }} - # Disable the webServer block in playwright.config.ts — in CI we run - # against a deployed URL, never against a freshly-spawned `yarn dev`. - PLAYWRIGHT_NO_SERVER: '1' + NODE_ENV: production + APP_ENV: ${{ github.event.inputs.target_env || 'staging' }} + # The webServer block in playwright.config.ts reads APP_ENV and runs + # `next start` against the freshly-built `.next/`. baseURL stays at + # the default localhost:3005. steps: - name: Checkout uses: actions/checkout@v4 @@ -78,23 +79,19 @@ jobs: - name: Install dependencies run: yarn install --frozen-lockfile + - name: Decode prod env file + if: env.APP_ENV == 'prod' + run: echo "${{ secrets.ENV_PRODUCTION }}" | base64 -d > .env.prod + + - name: Decode staging env file + if: env.APP_ENV == 'staging' + run: echo "${{ secrets.ENV_STAGING }}" | base64 -d > .env.staging + - name: Install Playwright browsers run: yarn playwright install --with-deps ${{ github.event.inputs.browser == 'all' && 'chromium firefox webkit' || github.event.inputs.browser || 'chromium' }} - - name: Resolve base URL - id: resolve - run: | - ENV_INPUT="${{ github.event.inputs.environment || 'staging' }}" - if [ "$ENV_INPUT" = "production" ]; then - URL="$PLAYWRIGHT_PRODUCTION_URL" - else - URL="$PLAYWRIGHT_STAGING_URL" - fi - if [ -z "$URL" ]; then - echo "::error ::Base URL for environment '$ENV_INPUT' is not configured. Set the PLAYWRIGHT_${ENV_INPUT^^}_URL repository secret." - exit 1 - fi - echo "base_url=$URL" >> "$GITHUB_OUTPUT" + - name: Build app + run: yarn cross-env NODE_ENV=production APP_ENV=${{ env.APP_ENV }} next build - name: Resolve scope path id: scope @@ -123,10 +120,10 @@ jobs: fi - name: Run Playwright - env: - PLAYWRIGHT_BASE_URL: ${{ steps.resolve.outputs.base_url }} - run: | - yarn playwright test ${{ steps.scope.outputs.path }} ${{ steps.projects.outputs.args }} + # webServer block in playwright.config.ts spawns `next start` itself + # (because APP_ENV is set), waits for http://localhost:3005, runs + # the suite, and tears the server down at the end. + run: yarn playwright test ${{ steps.scope.outputs.path }} ${{ steps.projects.outputs.args }} - name: Upload HTML report if: failure() diff --git a/playwright.config.ts b/playwright.config.ts index 549ef14..ad129bf 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -39,13 +39,24 @@ export default defineConfig({ use: { ...devices['Desktop Safari'] }, }, ], + // Server selection: + // - PLAYWRIGHT_NO_SERVER=1 → don't manage one (e.g. workflow already + // started it, or running against a deployed URL). + // - APP_ENV=staging|prod → pre-built production server (`next start`). + // The CI workflow runs `next build` first, then this block boots + // `next start` against the chosen env file. See + // .github/workflows/playwright-scheduled.yml. + // - else → local `yarn dev`. webServer: process.env.PLAYWRIGHT_NO_SERVER ? undefined : { - command: 'yarn dev', + command: + process.env.APP_ENV === 'staging' || process.env.APP_ENV === 'prod' + ? `cross-env NODE_ENV=production APP_ENV=${process.env.APP_ENV} next start -p 3005` + : 'yarn dev', url: baseURL, reuseExistingServer: !isCI, - timeout: 120_000, + timeout: 180_000, stdout: 'ignore', stderr: 'pipe', },