woocommerce/plugins/woocommerce-blocks/.github/workflows/unit-tests.yml

147 lines
5.2 KiB
YAML

name: Unit Tests
# Since Unit Tests are required to pass for each PR,
# we cannot disable them for documentation-only changes.
on:
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
jobs:
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
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Npm install and build
run: |
npm ci --no-optional
FORCE_REDUCED_MOTION=true npm run build
- 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
uses: actions/setup-node@v3
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
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
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
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: |
composer config platform.php ${{ matrix.php }}
composer update
- name: Install npm dependencies
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: |
npm ci
npm run build
- name: Docker debug information
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: |
docker -v
docker-compose -v
- name: General debug information
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: |
npm --version
node --version
curl --version
git --version
svn --version
locale -a
- name: Start Docker environment
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: npm run wp-env start --update
- name: Log running Docker containers
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: docker ps -a
- name: Docker container debug information
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: |
npm run wp-env run tests-mysql mysql -- --version
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"
- name: Run PHPUnit tests
# 8.1 and 8.2 are temporarily disabled as docker-images for those cause the errors when pipeline is running
if: ${{ matrix.php == '7.4' || matrix.php == '8.0' }}
run: npm run test:php