diff --git a/.github/actions/install-playwright/action.yml b/.github/actions/install-playwright/action.yml index 6c8ea05d3c91..30815292dea2 100644 --- a/.github/actions/install-playwright/action.yml +++ b/.github/actions/install-playwright/action.yml @@ -5,33 +5,25 @@ inputs: description: 'What browsers to install.' default: 'chromium webkit firefox' cwd: - description: 'The working directory to run Playwright in.' - default: '.' - installed-version: description: - 'A Playwright version that an earlier run of this action already installed. Skips the install if it matches.' - default: '' - -outputs: - version: - description: 'The resolved Playwright version, empty if Playwright is not installed or the install was skipped.' - value: ${{ steps.playwright-version.outputs.version }} + 'The directory whose package.json declares the `@playwright/test` version to install. Nothing is installed if it + does not depend on `@playwright/test`.' + required: true runs: using: 'composite' steps: - # Resolve the app's @playwright/test version. Some apps (e.g. the node bundler apps) assert via a - # plain node script and don't depend on Playwright — emit an empty version instead of failing, so - # the steps below skip the (wasted) browser install rather than erroring on the missing package. + # Read from package.json rather than node_modules, so this can run before dependencies are installed. - name: Get Playwright version id: playwright-version run: | - version=$(node -e "let v = ''; try { v = require('@playwright/test/package.json').version; } catch {} process.stdout.write(String(v));") - if [ "$version" = "$INSTALLED_VERSION" ]; then version=''; fi + version=$(node -e " + const { dependencies, devDependencies } = require('./package.json'); + const range = devDependencies?.['@playwright/test'] ?? dependencies?.['@playwright/test'] ?? ''; + process.stdout.write(range.replace(/^[~^=]/, '')); + ") echo "version=$version" >> "$GITHUB_OUTPUT" shell: bash - env: - INSTALLED_VERSION: ${{ inputs.installed-version }} working-directory: ${{ inputs.cwd }} - name: Restore cached playwright binaries @@ -46,18 +38,19 @@ runs: # We always install all browsers, if uncached - name: Install Playwright dependencies (uncached) - run: npx playwright install chromium webkit firefox --with-deps + env: + PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.version }} + run: npx -y "playwright@$PLAYWRIGHT_VERSION" install chromium webkit firefox --with-deps if: steps.playwright-version.outputs.version != '' && steps.playwright-cache.outputs.cache-hit != 'true' shell: bash - working-directory: ${{ inputs.cwd }} - name: Install Playwright system dependencies only (cached) env: PLAYWRIGHT_BROWSERS: ${{ inputs.browsers || 'chromium webkit firefox' }} - run: npx playwright install-deps "$PLAYWRIGHT_BROWSERS" + PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.version }} + run: npx -y "playwright@$PLAYWRIGHT_VERSION" install-deps "$PLAYWRIGHT_BROWSERS" if: steps.playwright-version.outputs.version != '' && steps.playwright-cache.outputs.cache-hit == 'true' shell: bash - working-directory: ${{ inputs.cwd }} # Only store cache on develop branch - name: Store cached playwright binaries diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 702a6ddbc2cb..cb05f34f6df2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -684,6 +684,7 @@ jobs: uses: ./.github/actions/install-playwright with: browsers: ${{ matrix.project }} + cwd: dev-packages/browser-integration-tests - name: Run Playwright tests env: @@ -746,6 +747,7 @@ jobs: uses: ./.github/actions/install-playwright with: browsers: chromium + cwd: dev-packages/browser-integration-tests - name: Run Playwright Loader tests env: @@ -1101,8 +1103,7 @@ jobs: name: build-layer-output path: ${{ env.BUILD_LAYER_PATH }} - # Installs the root workspace's Playwright version while the app builds. Most apps use the same version. - # The app's own version is only known after its build, so it gets installed then if it differs. + # Installs Playwright while the app builds. # Started after the artifact downloads: starting next to them made `download-artifact` fail to read the event file. - name: Install Playwright id: install-playwright @@ -1110,6 +1111,7 @@ jobs: uses: ./.github/actions/install-playwright with: browsers: chromium + cwd: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }} - name: Prepare e2e tests run: yarn test:prepare @@ -1138,13 +1140,6 @@ jobs: - wait: [install-playwright] - - name: Install Playwright for the app's version - uses: ./.github/actions/install-playwright - with: - browsers: chromium - cwd: ${{ runner.temp }}/test-application - installed-version: ${{ steps.install-playwright.outputs.version }} - - name: Run E2E test working-directory: ${{ runner.temp }}/test-application timeout-minutes: 10 @@ -1248,8 +1243,7 @@ jobs: name: build-tarball-output path: ${{ env.TARBALL_ARTIFACT_DOWNLOAD_PATH }} - # Installs the root workspace's Playwright version while the app builds. Most apps use the same version. - # The app's own version is only known after its build, so it gets installed then if it differs. + # Installs Playwright while the app builds. # Started after the artifact downloads: starting next to them made `download-artifact` fail to read the event file. - name: Install Playwright id: install-playwright @@ -1257,6 +1251,7 @@ jobs: uses: ./.github/actions/install-playwright with: browsers: chromium + cwd: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }} - name: Prepare E2E tests run: yarn test:prepare @@ -1283,13 +1278,6 @@ jobs: - wait: [install-playwright] - - name: Install Playwright for the app's version - uses: ./.github/actions/install-playwright - with: - browsers: chromium - cwd: ${{ runner.temp }}/test-application - installed-version: ${{ steps.install-playwright.outputs.version }} - - name: Run E2E test working-directory: ${{ runner.temp }}/test-application timeout-minutes: 10 diff --git a/.github/workflows/flaky-test-detector.yml b/.github/workflows/flaky-test-detector.yml index ae4fbc9ad692..b4c7e6e40c5f 100644 --- a/.github/workflows/flaky-test-detector.yml +++ b/.github/workflows/flaky-test-detector.yml @@ -42,6 +42,7 @@ jobs: uses: ./.github/actions/install-playwright with: browsers: 'chromium' + cwd: dev-packages/browser-integration-tests - name: Determine changed tests uses: dorny/paths-filter@v4.0.3