Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created April 29, 2022 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/94018d7ce205a095c3fc4ad02f09040e to your computer and use it in GitHub Desktop.
Save wpscholar/94018d7ce205a095c3fc4ad02f09040e to your computer and use it in GitHub Desktop.
Sample GitHub Action workflow for running Cypress tests with @wordpress/env
name: Cypress Tests
on:
push:
branches:
- master
pull_request:
types: [opened, edited, synchronize, reopened, ready_for_review]
pull_request_review:
types: [submitted, edited]
jobs:
test:
name: Run Cypress Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer
- name: Setup workflow context
id: workflow
working-directory: ${{ runner.temp }}
env:
REPO: ${{ github.repository }}
run: |
mkdir dist
echo ::set-output name=DIST::${PWD}/dist
echo ::set-output name=PACKAGE::${REPO##*/}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer vendor directory
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- name: PHP version
run: php --version
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install PHP Dependencies
run: composer install --no-progress --no-dev --optimize-autoloader --prefer-dist
- name: NPM Install
run: npm install
- name: Build JavaScript
run: npm run build
- name: Create Distribution Copy
run: rsync -r --exclude-from=.distignore . ${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}
- name: List Distribution Files
working-directory: ${{ steps.workflow.outputs.DIST }}
run: find .
- name: Configure WordPress
run: echo '{"config":{"WP_DEBUG_DISPLAY":false},"plugins":["${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}"]}' > .wp-env.override.json
- name: Install WordPress
run: npx wp-env start
- name: Run Cypress Tests
run: npx cypress run
- name: Store screenshots of test failures
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: screenshots
path: ./cypress/screenshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment