2023-04-21 11:07:37 +00:00
|
|
|
name: Unit Tests
|
2021-03-23 12:31:42 +00:00
|
|
|
|
2023-04-21 11:07:37 +00:00
|
|
|
# Since Unit Tests are required to pass for each PR,
|
|
|
|
# we cannot disable them for documentation-only changes.
|
2021-03-23 12:31:42 +00:00
|
|
|
on:
|
2023-04-21 11:07:37 +00:00
|
|
|
pull_request:
|
|
|
|
push:
|
|
|
|
branches: [trunk]
|
|
|
|
# Allow manually triggering the workflow.
|
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
# Cancels all previous workflow runs for pull requests that have not completed.
|
|
|
|
concurrency:
|
|
|
|
# The concurrency group contains the workflow name and the branch name for pull requests
|
|
|
|
# or the commit hash for any other events.
|
|
|
|
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
|
|
|
|
cancel-in-progress: true
|
2021-03-23 12:31:42 +00:00
|
|
|
|
|
|
|
jobs:
|
2023-04-21 11:07:37 +00:00
|
|
|
JSUnitTests:
|
|
|
|
name: JS Unit Tests
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: ${{ github.repository == 'WooCommerce/WooCommerce-Blocks' || github.event_name == 'pull_request' }}
|
|
|
|
|
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Use desired version of NodeJS
|
2023-11-03 15:06:34 +00:00
|
|
|
uses: actions/setup-node@v4
|
2023-04-21 11:07:37 +00:00
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
cache: npm
|
|
|
|
|
|
|
|
- name: Npm install and build
|
|
|
|
run: |
|
|
|
|
npm ci --no-optional
|
2023-05-05 11:03:36 +00:00
|
|
|
FORCE_REDUCED_MOTION=true npm run build
|
2023-04-21 11:07:37 +00:00
|
|
|
|
|
|
|
- name: blocks.ini setup
|
|
|
|
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = test' > blocks.ini
|
|
|
|
|
|
|
|
- name: Run JavaScript Unit tests
|
|
|
|
run: npm run test
|
|
|
|
|
|
|
|
PHPUnitTests:
|
|
|
|
name: PHP ${{ matrix.php }}
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
timeout-minutes: 20
|
|
|
|
if: ${{ github.repository == 'WooCommerce/WooCommerce-Blocks' || github.event_name == 'pull_request' }}
|
|
|
|
strategy:
|
|
|
|
fail-fast: true
|
|
|
|
matrix:
|
|
|
|
php:
|
|
|
|
- '7.4'
|
|
|
|
- '8.0'
|
|
|
|
- '8.1'
|
|
|
|
- '8.2'
|
|
|
|
|
|
|
|
env:
|
|
|
|
WP_ENV_PHP_VERSION: ${{ matrix.php }}
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
|
|
|
|
- name: Set up Node.js
|
2023-11-03 15:06:34 +00:00
|
|
|
uses: actions/setup-node@v4
|
2023-04-21 11:07:37 +00:00
|
|
|
with:
|
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
cache: npm
|
|
|
|
|
|
|
|
##
|
|
|
|
# This allows Composer dependencies to be installed using a single step.
|
|
|
|
#
|
|
|
|
# Since the tests are currently run within the Docker containers where the PHP version varies,
|
|
|
|
# the same PHP version needs to be configured for the action runner machine so that the correct
|
|
|
|
# dependency versions are installed and cached.
|
|
|
|
##
|
|
|
|
- name: Set up PHP
|
|
|
|
uses: shivammathur/setup-php@v2
|
|
|
|
with:
|
|
|
|
php-version: '${{ matrix.php }}'
|
|
|
|
ini-file: development
|
|
|
|
coverage: none
|
|
|
|
|
|
|
|
# Ensure that Composer installs the correct versions of packages.
|
|
|
|
- name: Override PHP version in composer.json
|
|
|
|
run: |
|
|
|
|
composer config platform.php ${{ matrix.php }}
|
|
|
|
composer update
|
|
|
|
|
|
|
|
- name: Install npm dependencies
|
|
|
|
run: |
|
|
|
|
npm ci
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
- name: Docker debug information
|
|
|
|
run: |
|
|
|
|
docker -v
|
|
|
|
docker-compose -v
|
|
|
|
|
|
|
|
- name: General debug information
|
|
|
|
run: |
|
|
|
|
npm --version
|
|
|
|
node --version
|
|
|
|
curl --version
|
|
|
|
git --version
|
|
|
|
svn --version
|
|
|
|
locale -a
|
|
|
|
|
|
|
|
- name: Start Docker environment
|
|
|
|
run: npm run wp-env start --update
|
|
|
|
|
|
|
|
- name: Log running Docker containers
|
|
|
|
run: docker ps -a
|
|
|
|
|
|
|
|
- name: Docker container debug information
|
|
|
|
run: |
|
2023-06-12 17:00:27 +00:00
|
|
|
npm run wp-env run tests-mysql mysql -- --version
|
2023-09-01 09:07:55 +00:00
|
|
|
npm run wp-env run tests-wordpress php -- --version
|
|
|
|
npm run wp-env run tests-wordpress php -- -m
|
|
|
|
npm run wp-env run tests-wordpress php -- -i
|
|
|
|
npm run wp-env run tests-wordpress locale -- -a
|
2023-04-21 11:07:37 +00:00
|
|
|
|
|
|
|
- name: Run PHPUnit tests
|
|
|
|
run: npm run test:php
|