From 585e1f2ff576dfd38c30afde016c6da409c6014e Mon Sep 17 00:00:00 2001 From: Ammar Ansari Date: Mon, 30 Dec 2024 17:44:06 +0500 Subject: [PATCH] get the playwright version inside the action --- .github/actions/playwright/action.yml | 39 +++++++++++++++++-- .github/workflows/browser-js-production.yml | 9 +---- .github/workflows/browser-js-staging.yml | 9 +---- .../realtime-api-production-euswcom.yml | 9 +---- .github/workflows/realtime-api-production.yml | 9 +---- .github/workflows/realtime-api-staging.yml | 9 +---- .github/workflows/v2-webrtc-calling.yml | 2 +- 7 files changed, 42 insertions(+), 44 deletions(-) diff --git a/.github/actions/playwright/action.yml b/.github/actions/playwright/action.yml index 4939bbfbf..0eaa6876e 100644 --- a/.github/actions/playwright/action.yml +++ b/.github/actions/playwright/action.yml @@ -3,20 +3,53 @@ description: Install playwright and required browsers inputs: PLAYWRIGHT_VERSION: - required: true - description: Playwright version to use + description: If provided, the action will use this version directly + required: false + PACKAGE_JSON_PATH: + description: Path to package.json where '@playwright/test' is defined + required: false + default: './internal/e2e-js/package.json' runs: using: composite steps: + - name: Validate input + shell: bash + run: | + # Ensure at least one of PLAYWRIGHT_VERSION or PACKAGE_JSON_PATH is passed + if [ -z "${{ inputs.PLAYWRIGHT_VERSION }}" ] && [ -z "${{ inputs.PACKAGE_JSON_PATH }}" ]; then + echo "Error: You must provide either PLAYWRIGHT_VERSION or PACKAGE_JSON_PATH." + exit 1 + fi + + - name: Get Playwright version + id: playwright-version + shell: bash + run: | + # If a version is explicitly provided, use that + if [ -n "${{ inputs.PLAYWRIGHT_VERSION }}" ]; then + DETECTED_VERSION="${{ inputs.PLAYWRIGHT_VERSION }}" + echo "Using explicit Playwright version: $DETECTED_VERSION" + else + # Otherwise, read it from package.json + echo "Reading Playwright version from ${{ inputs.PACKAGE_JSON_PATH }}" + DETECTED_VERSION=$(jq -r '.devDependencies["@playwright/test"]' "${{ inputs.PACKAGE_JSON_PATH }}") + DETECTED_VERSION=${DETECTED_VERSION#^} # Remove ^ + echo "Detected Playwright version: $DETECTED_VERSION" + fi + + echo "PLAYWRIGHT_VERSION=$DETECTED_VERSION" >> $GITHUB_ENV + - name: Cache playwright binaries uses: actions/cache@v4 id: playwright-cache with: path: | ~/.cache/ms-playwright - key: ${{ runner.os }}-playwright-${{ inputs.PLAYWRIGHT_VERSION }} + key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }} + - if: steps.playwright-cache.outputs.cache-hit != 'true' name: Install Playwright shell: bash run: npx playwright install --with-deps chromium + diff --git a/.github/workflows/browser-js-production.yml b/.github/workflows/browser-js-production.yml index f80e440ed..2c46180c6 100644 --- a/.github/workflows/browser-js-production.yml +++ b/.github/workflows/browser-js-production.yml @@ -41,17 +41,10 @@ jobs: uses: ./.github/actions/build with: NODE_VERSION: ${{ matrix.node-version }} - - name: Get Playwright version - id: playwright-version - run: | - PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' ./internal/e2e-js/package.json) - PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION#^} - echo "Playwright version: $PLAYWRIGHT_VERSION" - echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT - name: Install Playwright uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.playwright_version }} + PACKAGE_JSON_PATH: ./internal/e2e-js/package.json - name: Test run: npm run -w=@sw-internal/e2e-js dev -- --project ${{ matrix.project }} env: diff --git a/.github/workflows/browser-js-staging.yml b/.github/workflows/browser-js-staging.yml index aed875e15..faebbab4d 100644 --- a/.github/workflows/browser-js-staging.yml +++ b/.github/workflows/browser-js-staging.yml @@ -40,17 +40,10 @@ jobs: uses: ./.github/actions/build with: NODE_VERSION: ${{ matrix.node-version }} - - name: Get Playwright version - id: playwright-version - run: | - PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' ./internal/e2e-js/package.json) - PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION#^} - echo "Playwright version: $PLAYWRIGHT_VERSION" - echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT - name: Install Playwright uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.playwright_version }} + PACKAGE_JSON_PATH: ./internal/e2e-js/package.json - name: Test run: npm run -w=@sw-internal/e2e-js dev -- --project ${{ matrix.project }} env: diff --git a/.github/workflows/realtime-api-production-euswcom.yml b/.github/workflows/realtime-api-production-euswcom.yml index 75cb05655..047a5abd1 100644 --- a/.github/workflows/realtime-api-production-euswcom.yml +++ b/.github/workflows/realtime-api-production-euswcom.yml @@ -27,17 +27,10 @@ jobs: uses: ./.github/actions/build with: NODE_VERSION: ${{ matrix.node-version }} - - name: Get Playwright version - id: playwright-version - run: | - PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' ./internal/e2e-realtime-api/package.json) - PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION#^} - echo "Playwright version: $PLAYWRIGHT_VERSION" - echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT - name: Install Playwright uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.playwright_version }} + PACKAGE_JSON_PATH: ./internal/e2e-realtime-api/package.json - name: Test id: run-tests run: npm run -w=@sw-internal/e2e-realtime-api dev diff --git a/.github/workflows/realtime-api-production.yml b/.github/workflows/realtime-api-production.yml index d08695f64..b7312fc81 100644 --- a/.github/workflows/realtime-api-production.yml +++ b/.github/workflows/realtime-api-production.yml @@ -29,18 +29,11 @@ jobs: uses: ./.github/actions/build with: NODE_VERSION: ${{ matrix.node-version }} - - name: Get Playwright version - id: playwright-version - run: | - PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' ./internal/e2e-realtime-api/package.json) - PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION#^} - echo "Playwright version: $PLAYWRIGHT_VERSION" - echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT - name: Install Playwright if: matrix.test_command == 'dev:playwright' uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.playwright_version }} + PACKAGE_JSON_PATH: ./internal/e2e-realtime-api/package.json - name: Test run: 'npm run -w=@sw-internal/e2e-realtime-api ${{ matrix.test_command }}' env: diff --git a/.github/workflows/realtime-api-staging.yml b/.github/workflows/realtime-api-staging.yml index 25e5a5678..72aecd718 100644 --- a/.github/workflows/realtime-api-staging.yml +++ b/.github/workflows/realtime-api-staging.yml @@ -29,18 +29,11 @@ jobs: uses: ./.github/actions/build with: NODE_VERSION: ${{ matrix.node-version }} - - name: Get Playwright version - id: playwright-version - run: | - PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' ./internal/e2e-realtime-api/package.json) - PLAYWRIGHT_VERSION=${PLAYWRIGHT_VERSION#^} - echo "Playwright version: $PLAYWRIGHT_VERSION" - echo "playwright_version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT - name: Install Playwright if: matrix.test_command == 'dev:playwright' uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: ${{ steps.playwright-version.outputs.playwright_version }} + PACKAGE_JSON_PATH: ./internal/e2e-realtime-api/package.json - name: Test run: 'npm run -w=@sw-internal/e2e-realtime-api ${{ matrix.test_command }}' env: diff --git a/.github/workflows/v2-webrtc-calling.yml b/.github/workflows/v2-webrtc-calling.yml index 804517a4f..5b7b402c3 100644 --- a/.github/workflows/v2-webrtc-calling.yml +++ b/.github/workflows/v2-webrtc-calling.yml @@ -76,7 +76,7 @@ jobs: - name: Install Playwright uses: ./.github/actions/playwright with: - PLAYWRIGHT_VERSION: '1.49.1' # TODO: Read from deps ? + PACKAGE_JSON_PATH: ./internal/e2e-js/package.json - name: Run test for ${{ matrix.region.name }} id: run-tests run: npm run -w=@sw-internal/e2e-js dev -- v2WebrtcFromRest.spec.ts webrtcCalling.spec.ts