Skip to content

V3.0.2

V3.0.2 #126

Workflow file for this run

name: Playwright tests
on:
pull_request:
branches: [ staging, main, master ]
types:
- opened
- synchronize
paths:
- '.github/workflows/playwright.yml'
- 'src/**'
- 'tests/playwright/**'
- 'package.json'
schedule:
- cron: '0 6 1,16 * *'
workflow_dispatch:
jobs:
# First job: setup and build extension artifacts
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Publish extension to dist folder
run: |
npm ci
npm i grunt -g
grunt playwright
- name: Install test dependencies
run: npm ci
working-directory: tests/playwright
- name: Install Playwright browser (chromium)
run: npx playwright install --with-deps chromium
working-directory: tests/playwright
# Upload the built extension
- name: Upload extension artifacts
uses: actions/upload-artifact@v4
with:
name: extension-dist
path: dist/
retention-days: 1
# Upload node_modules from the test directory (includes Playwright browsers)
- name: Upload test dependencies
uses: actions/upload-artifact@v4
with:
name: test-node-modules
path: |
tests/playwright/node_modules/
tests/playwright/package.json
tests/playwright/package-lock.json
retention-days: 1
# Upload the Playwright cache (browsers and dependencies)
- name: Upload Playwright cache
uses: actions/upload-artifact@v4
with:
name: playwright-cache
path: ~/.cache/ms-playwright/
retention-days: 1
# Second job: discover all the *.spec.ts files and output a JSON matrix.
discover-tests:
needs: setup
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.discover.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Discover tests
id: discover
run: |
# Find all *.spec.ts files and strip out the directory so that later
tests=$(find tests/playwright/site.integrations.tests -name '*.spec.ts')
# Create JSON format for matrix
matrix="{\"tests\":["
for test in $tests; do
# Extract the test name by manipulating the project path (e.g., remove RestEasier.CoreApi/Tests/ and .csproj)
test_name=$(basename "$test" .spec.ts)
test_file=$(basename "$test")
# Append to matrix
matrix="$matrix{\"name\":\"$test_name\",\"file\":\"$test_file\"},"
done
# Remove the last comma and close the JSON
matrix="${matrix::-1}]}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
# Third job: run tests in parallel using shared artifacts
test:
name: ${{ matrix.tests.name }}
needs: [setup, discover-tests]
timeout-minutes: 10
strategy:
matrix: ${{ fromJson(needs.discover-tests.outputs.matrix) }}
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Download the pre-built extension
- name: Download extension artifacts
uses: actions/download-artifact@v4
with:
name: extension-dist
path: dist/
# Download test dependencies
- name: Download test dependencies
uses: actions/download-artifact@v4
with:
name: test-node-modules
path: tests/playwright/
# Download Playwright cache
- name: Download Playwright cache
uses: actions/download-artifact@v4
with:
name: playwright-cache
path: ~/.cache/ms-playwright/
# Restore node_modules and ensure Playwright is available
- name: Restore test environment
run: |
cd tests/playwright
# Ensure .bin directory exists and has proper permissions
if [ -d "node_modules/.bin" ]; then
find node_modules/.bin -type f -exec chmod +x {} \;
fi
# Restore execute bits on all Chromium binaries (artifact download strips perms)
find ~/.cache/ms-playwright -path '*/chrome-linux/*' -type f -exec chmod +x {} \; 2>/dev/null || true
# Reinstall playwright if .bin/playwright is missing
if [ ! -f "node_modules/.bin/playwright" ]; then
echo "Playwright binary not found, reinstalling..."
npm install playwright
fi
# Verify playwright is available
./node_modules/.bin/playwright --version || npx playwright --version
- name: Run Playwright test for ${{ matrix.tests.name }}
run: ./node_modules/.bin/playwright test ${{ matrix.tests.file }}
working-directory: tests/playwright
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ matrix.tests.name }}
path: tests/playwright/playwright-report/
retention-days: 10
# If the test step fails, create an issue using the same method as before, if running on the main or master branch.
- name: Create issue if test fails
if: failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
uses: dacbd/create-issue-action@main
with:
token: ${{ github.token }}
title: |
Playwright test failed: ${{ matrix.tests.name }}
assignees: ${{ github.repository_owner }}
labels: bug, failed-tests
body: |
## Failure Report:
> [!IMPORTANT]
> Details on failed run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
- **Test File:** `${{ matrix.tests.file }}`
- **Author:** trossr32
- **Branch:** `${{ github.ref }}`
- **Commit:** ${{ github.sha }}
- **Workflow:** `${{ github.workflow_ref }}`