Skip to content

Commit

Permalink
build(.github) setup end-to-end testing w/ Playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Aug 23, 2024
1 parent 02b8363 commit f1039e1
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 982 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/changelogger.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/link-project.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/lint.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .github/workflows/phpcs.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
name: 'Codeception Tests'
name: 'End-to-End Tests - Seating'
on:
pull_request:
paths:
- 'tests/**.php'
- 'tests/**.ts'
- 'src/**.php'
- '*.php'
- 'src/resources/**.js'
- 'composer.json'
- 'composer.lock'
- 'codeception.dist.yml'
- '.github/workflows/tests-php.yml'
- '.github/workflows/tests-end-to-end-seating.yml'
jobs:
test:
strategy:
fail-fast: false
matrix:
suite:
# - acceptance
- functional
- integration
- restv1
- views_integration
- commerce_integration
- wpunit
- slr_integration
- seating
runs-on: ubuntu-latest
steps:
# ------------------------------------------------------------------------------
Expand All @@ -35,25 +27,10 @@ jobs:
token: ${{ secrets.GH_BOT_TOKEN }}
submodules: recursive
# ------------------------------------------------------------------------------
# Check if any PHP files have changed
# ------------------------------------------------------------------------------
- name: Check changed files
id: skip
run: |
num_php_files=$(git diff ${{ github.event.pull_request.base.sha }} HEAD --name-only | grep -P "\.php" | wc -l)
if [[ -z "$num_php_files" ]]; then
echo "::set-output name=value::1"
elif [[ "$num_php_files" == "0" || "$num_php_files" == "" ]]; then
echo "::set-output name=value::1"
else
echo "::set-output name=value::0"
fi
# ------------------------------------------------------------------------------
# Checkout slic
# ------------------------------------------------------------------------------
- name: Checkout slic
uses: actions/checkout@v2
if: steps.skip.outputs.value != 1
with:
repository: stellarwp/slic
ref: main
Expand All @@ -64,12 +41,10 @@ jobs:
# ------------------------------------------------------------------------------
- name: Get Composer Cache Directory
id: get-composer-cache-dir
if: steps.skip.outputs.value != 1
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)-${{ secrets.COMPOSER_CACHE_KEY }}"
- uses: actions/cache@v2
id: composer-cache
if: steps.skip.outputs.value != 1
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ secrets.COMPOSER_CACHE_KEY }}-${{ hashFiles('**/composer.lock') }}
Expand All @@ -79,24 +54,19 @@ jobs:
# Initialize slic
# ------------------------------------------------------------------------------
- name: Set up slic env vars
if: steps.skip.outputs.value != 1
run: |
echo "SLIC_BIN=${GITHUB_WORKSPACE}/slic/slic" >> $GITHUB_ENV
echo "SLIC_WP_DIR=${GITHUB_WORKSPACE}/slic/_wordpress" >> $GITHUB_ENV
echo "SLIC_WORDPRESS_DOCKERFILE=Dockerfile.base" >> $GITHUB_ENV
- name: Set run context for slic
if: steps.skip.outputs.value != 1
run: echo "SLIC=1" >> $GITHUB_ENV && echo "CI=1" >> $GITHUB_ENV
- name: Start ssh-agent
if: steps.skip.outputs.value != 1
run: |
mkdir -p "${HOME}/.ssh";
ssh-agent -a /tmp/ssh_agent.sock;
- name: Export SSH_AUTH_SOCK env var
if: steps.skip.outputs.value != 1
run: echo "SSH_AUTH_SOCK=/tmp/ssh_agent.sock" >> $GITHUB_ENV
- name: Set up slic for CI
if: steps.skip.outputs.value != 1
run: |
cd ${GITHUB_WORKSPACE}/..
${SLIC_BIN} here
Expand All @@ -112,14 +82,12 @@ jobs:
# Start the Chrome container
# ------------------------------------------------------------------------------
- name: Start the Chrome container
if: steps.skip.outputs.value != 1 && matrix.suite == 'acceptance'
run: ${SLIC_BIN} up chrome
# ------------------------------------------------------------------------------
# Fetch branches for dependent repos
# ------------------------------------------------------------------------------
- name: Fetch head branch from TEC
uses: octokit/[email protected]
if: steps.skip.outputs.value != 1
id: fetch-tec-head-branch
with:
route: GET /repos/{owner}/{repo}/branches/${{ github.head_ref }}
Expand All @@ -131,7 +99,7 @@ jobs:
- name: Fetch base branch from TEC
uses: octokit/[email protected]
id: fetch-tec-base-branch
if: steps.skip.outputs.value != 1 && steps.fetch-tec-head-branch.outcome != 'success'
if: steps.fetch-tec-head-branch.outcome != 'success'
with:
route: GET /repos/{owner}/{repo}/branches/${{ github.base_ref }}
owner: the-events-calendar
Expand All @@ -143,78 +111,64 @@ jobs:
# Set TEC branch
# ------------------------------------------------------------------------------
- name: Set TEC with head branch
if: steps.skip.outputs.value != 1 && steps.fetch-tec-head-branch.outcome == 'success'
if: steps.fetch-tec-head-branch.outcome == 'success'
run: echo "TEC_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
- name: Set TEC with base branch
if: steps.skip.outputs.value != 1 && steps.fetch-tec-head-branch.outcome != 'success' && steps.fetch-tec-base-branch.outcome == 'success'
if: steps.fetch-tec-head-branch.outcome != 'success' && steps.fetch-tec-base-branch.outcome == 'success'
run: echo "TEC_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV
- name: Set TEC with master branch
if: steps.skip.outputs.value != 1 && steps.fetch-tec-head-branch.outcome != 'success' && steps.fetch-tec-base-branch.outcome != 'success'
if: steps.fetch-tec-head-branch.outcome != 'success' && steps.fetch-tec-base-branch.outcome != 'success'
run: echo "TEC_BRANCH=master" >> $GITHUB_ENV
# ------------------------------------------------------------------------------
# Clone and init TEC
# ------------------------------------------------------------------------------
- name: Clone TEC
uses: actions/checkout@v2
if: steps.skip.outputs.value != 1
with:
fetch-depth: 1
repository: the-events-calendar/the-events-calendar
ref: ${{ env.TEC_BRANCH }}
token: ${{ secrets.GH_BOT_TOKEN }}
path: the-events-calendar
submodules: recursive
- name: Init TEC
if: steps.skip.outputs.value != 1
- name: Init TEC (including npm)
run: |
mv ${GITHUB_WORKSPACE}/the-events-calendar ${GITHUB_WORKSPACE}/../the-events-calendar
docker network prune -f
${SLIC_BIN} use the-events-calendar
${SLIC_BIN} composer install --no-dev
- name: Set up TEC Common
if: steps.skip.outputs.value != 1
${SLIC_BIN} npm install
${SLIC_BIN} npm run build
- name: Set up TEC Common (including npm)
run: |
docker network prune -f
${SLIC_BIN} use the-events-calendar/common
${SLIC_BIN} composer install --no-dev
${SLIC_BIN} npm install
${SLIC_BIN} npm run build
# ------------------------------------------------------------------------------
# Set up ET Common
# ------------------------------------------------------------------------------
- name: Set up ET Common
if: steps.skip.outputs.value != 1
- name: Set up ET Common (including npm)
run: |
docker network prune -f
${SLIC_BIN} use event-tickets/common
${SLIC_BIN} composer install --no-dev
# ------------------------------------------------------------------------------
# Set up ET Common (npm install and build)
# ------------------------------------------------------------------------------
- name: Set up ET Common (npm)
if: steps.skip.outputs.value != 1 && matrix.suite == 'acceptance'
run: |
${SLIC_BIN} npm install
${SLIC_BIN} npm run build
# ------------------------------------------------------------------------------
# Set up ET
# Set up ET (including npm)
# ------------------------------------------------------------------------------
- name: Set up ET
if: steps.skip.outputs.value != 1
run: |
${SLIC_BIN} use event-tickets
${SLIC_BIN} composer install
# ------------------------------------------------------------------------------
# Set up ET (npm install and build)
# ------------------------------------------------------------------------------
- name: Set up ET (npm)
if: steps.skip.outputs.value != 1 && matrix.suite == 'acceptance'
run: |
${SLIC_BIN} npm install
${SLIC_BIN} npm run build
# ------------------------------------------------------------------------------
# Init WordPress container
# ------------------------------------------------------------------------------
- name: Init the WordPress container
if: steps.skip.outputs.value != 1
run: |
${SLIC_BIN} up wordpress
${SLIC_BIN} wp core version
Expand All @@ -226,18 +180,60 @@ jobs:
- name: Install and activate TwentyTwenty
run: ${SLIC_BIN} wp theme install twentytwenty --activate
# ------------------------------------------------------------------------------
# Run tests
# Install Playwright dependencies (chromium)
# ------------------------------------------------------------------------------
- name: Install Playwright dependencies
run: ${SLIC_BIN} playwright install chromium
env:
CI: 'true'
# ------------------------------------------------------------------------------
# Clone, init and spin up the Seating service
# ------------------------------------------------------------------------------
- name: Set the env var for the Seating service directory
run: echo "SEATING_SERVICE_DIR=$(realpath {GITHUB_WORKSPACE}/../event-tickets-seating-service)" >> $GITHUB_ENV
- name: Clone the Seating service
uses: actions/checkout@v2
with:
fetch-depth: 1
repository: the-events-calendar/event-tickets-seating-service
ref: routes-local-development
path: ${{ SEATING_SERVICE_DIR }}
submodules: recursive
token: ${{ secrets.GH_BOT_TOKEN }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: ${{ SEATING_SERVICE_DIR }}/.nvmrc
- name: Init the Seating service
working-directory: ${{ SEATING_SERVICE_DIR }}
run: |
npm ci
npm run build
- name: Install pm2
run: |
npm install -g pm2
pm2 -V
pm2 list
- name: Start the Seating service using pm2
working-directory: ${{ SEATING_SERVICE_DIR }}
run: |
pm2 start npm --name "seating-ci" -- run local:up
pm2 list
# ------------------------------------------------------------------------------
# Run Playwright tests
# ------------------------------------------------------------------------------
- name: Run suite tests
if: steps.skip.outputs.value != 1
run: ${SLIC_BIN} run ${{ matrix.suite }} --ext DotReporter
run: |
${SLIC_BIN} playwright test tests/end-to-end/${{ matrix.suite }}
env:
CI: 'true'
# ------------------------------------------------------------------------------
# Upload artifacts (On failure)
# Upload artifacts (On failure) -- @todo find the location of the artifacts in Playwright
# ------------------------------------------------------------------------------
- name: Upload artifacts
uses: actions/upload-artifact@v2
if: steps.skip.outputs.value != 1 && failure()
- name: Upload artifacts on failure
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: output ${{ matrix.suite }}
path: tests/_output/
name: playwright-${{ matrix.suite }}-report
path: tests/_output/playwright/
retention-days: 7
Loading

0 comments on commit f1039e1

Please sign in to comment.