Skip to content

Add playwright initial setup and tests #1

Add playwright initial setup and tests

Add playwright initial setup and tests #1

Workflow file for this run

name: Clear Playwright Cache
on:
schedule:
- cron: '0 0 */7 * *' # runs weekly
jobs:
clear-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
restore-keys: |
${{ runner.os }}-playwright-
name: run e2e tests for vue

Check failure on line 18 in .github/workflows/playwright.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/playwright.yml

Invalid workflow file

You have an error in your yaml syntax on line 18
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
get-changed-files:
runs-on: ubuntu-latest
outputs:
changed-files: ${{ steps.changed_files.outputs.changed-files }}
steps:
- name: Get Changed Files
id: changed_files
uses: actions/github-script@v6
with:
script: |
const { context } = require('@actions/github');
const fs = require('fs');
const changedFiles = fs.readFileSync(context.payload.pull_request.patch_url, 'utf-8')
.match(/^\+(?:\s*\w+\/)*(\S+\.ts)$/gm)
.map(line => line.replace('+', '').trim());
core.setOutput('changed-files', JSON.stringify(changedFiles));
check-dependencies:
runs-on: ubuntu-latest
needs: get-changed-files
outputs:
should-install-fresh-deps: ${{ steps.check_deps.outputs.should-install }}
steps:
- name: Check if package files changed
id: check_deps
run: |
changed_files=(${CHANGED_FILES})
if [[ " ${changed_files[*]} " =~ "package.json" || " ${changed_files[*]} " =~ "package-lock.json" ]]; then
echo "::set-output name=should-install::true"
else
echo "::set-output name=should-install::false"
fi
install-and-cache-node-deps:
runs-on: ubuntu-latest
needs: check-dependencies
if: steps.check_deps.outputs.should-install == 'true'
steps:
- name: Install dependencies (Vue app)
working-directory: vue-app
run: npm ci
- name: Cache Node Dependencies
uses: actions/cache@v3
with:
path: vue-app/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
build-and-start-vue:
runs-on: ubuntu-latest
needs: check-dependencies
if: steps.check_deps.outputs.should-install == 'false'
steps:
- name: Use cached Node dependencies
uses: actions/cache@v3
with:
path: vue-app/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Start Vue app
run: npm run dev & # Runs in background
- name: Make sure Vue server is up and running
run: |
until $(curl --output /dev/null --silent --head --fail http://localhost:3000); do
printf '.'
sleep 3
done
echo "Vue server is up and running!"
playwright-setup:
runs-on: ubuntu-latest
steps:
- name: Cache Playwright Dependencies
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright (if not cached)
if: steps.cache.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
call-test-selection-api:
runs-on: ubuntu-latest
needs: [get-changed-files]
steps:
- name: Call the Test Selection API
id: test_selection
run: |
changed_files=${{ steps.changed_files.outputs.changed-files }}
tests=$(curl -X POST 'https://tests-selection.azurewebsites.net/api' \
-H 'Content-Type: application/json' \
-d "$changed_files")
echo "selected-tests::$tests"
run-playwright-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
timeout-minutes: 10
needs: [call-test-selection-api, get-changed-files, playwright-setup, build-and-start-vue]
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Run Playwright Tests
run: |
tests=${{ steps.test_selection.outputs.selected-tests }}
npx playwright test $tests --max-failures=2 --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}