2021-03-23 12:31:42 +00:00
|
|
|
name: Unit tests
|
|
|
|
|
|
|
|
on:
|
2021-08-17 12:25:11 +00:00
|
|
|
push:
|
|
|
|
branches: [trunk]
|
|
|
|
pull_request:
|
2021-03-23 12:31:42 +00:00
|
|
|
|
|
|
|
jobs:
|
2021-08-17 12:25:11 +00:00
|
|
|
Setup:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
name: Setup
|
|
|
|
steps:
|
2022-03-23 07:41:43 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Cache node_modules
|
|
|
|
id: cache-node-modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
env:
|
|
|
|
cache-name: cache-node-modules
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
|
|
|
|
2022-03-23 07:41:43 +00:00
|
|
|
- name: Setup node version and npm cache
|
|
|
|
uses: actions/setup-node@v3
|
2021-08-17 12:25:11 +00:00
|
|
|
with:
|
2022-03-23 07:41:43 +00:00
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
cache: 'npm'
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Install Node Dependencies
|
|
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
|
|
run: npm ci --no-optional
|
|
|
|
|
|
|
|
- name: Build Assets
|
|
|
|
run: FORCE_REDUCED_MOTION=true npm run build:e2e-test
|
|
|
|
|
|
|
|
- name: Store Build Assets
|
|
|
|
uses: actions/upload-artifact@v3
|
|
|
|
with:
|
|
|
|
name: build-assets
|
|
|
|
path: build/
|
2021-08-17 12:25:11 +00:00
|
|
|
|
|
|
|
- name: Get Composer Cache Directory
|
|
|
|
id: composer-cache
|
2022-11-09 15:28:08 +00:00
|
|
|
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
2021-08-17 12:25:11 +00:00
|
|
|
- uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
path: ${{ steps.composer-cache.outputs.dir }}
|
|
|
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-composer-
|
|
|
|
|
|
|
|
- name: Set up PHP
|
|
|
|
uses: shivammathur/setup-php@v2
|
|
|
|
with:
|
2022-11-09 15:28:08 +00:00
|
|
|
php-version: "8.0" # This is not the PHP version used to run the tests, that is set by wp-env
|
2021-08-17 12:25:11 +00:00
|
|
|
coverage: none
|
|
|
|
tools: composer
|
|
|
|
|
|
|
|
- name: Composer install
|
2022-05-24 11:42:54 +00:00
|
|
|
run: composer install
|
2021-08-17 12:25:11 +00:00
|
|
|
|
|
|
|
PHPUnitTests:
|
2022-11-09 15:28:08 +00:00
|
|
|
name: PHP ${{ matrix.php }}
|
2022-03-23 07:41:43 +00:00
|
|
|
needs: Setup
|
2021-08-17 12:25:11 +00:00
|
|
|
runs-on: ubuntu-latest
|
2022-11-09 15:28:08 +00:00
|
|
|
strategy:
|
|
|
|
fail-fast: false
|
|
|
|
matrix:
|
|
|
|
php: [ '7.4', '8.0' ]
|
2021-08-17 12:25:11 +00:00
|
|
|
|
2022-03-23 07:41:43 +00:00
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Cache node_modules
|
|
|
|
id: cache-node-modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
env:
|
|
|
|
cache-name: cache-node-modules
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
|
|
|
|
2022-03-23 07:41:43 +00:00
|
|
|
- name: Setup node version and npm cache
|
|
|
|
uses: actions/setup-node@v3
|
2021-08-17 12:25:11 +00:00
|
|
|
with:
|
2022-03-23 07:41:43 +00:00
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
cache: 'npm'
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Download Build Assets
|
|
|
|
uses: actions/download-artifact@v3
|
|
|
|
with:
|
|
|
|
name: build-assets
|
|
|
|
|
2021-08-17 12:25:11 +00:00
|
|
|
- name: blocks.ini setup
|
2022-11-09 15:28:08 +00:00
|
|
|
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = test' > blocks.ini
|
2022-05-24 11:42:54 +00:00
|
|
|
|
2022-07-06 07:51:39 +00:00
|
|
|
- name: Get Composer cache directory
|
|
|
|
id: composer-cache
|
2022-11-09 15:28:08 +00:00
|
|
|
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
2022-07-06 07:51:39 +00:00
|
|
|
|
|
|
|
- name: Set up Composer caching
|
|
|
|
uses: actions/cache@v2
|
|
|
|
env:
|
|
|
|
cache-name: cache-composer-dependencies
|
|
|
|
with:
|
|
|
|
path: ${{ steps.composer-cache.outputs.dir }}
|
|
|
|
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-composer-
|
|
|
|
|
|
|
|
- name: Install PHP deps
|
|
|
|
run: composer install
|
|
|
|
|
2022-11-09 15:28:08 +00:00
|
|
|
- name: Setup Permissions
|
2021-08-20 13:58:32 +00:00
|
|
|
run: |
|
2022-11-09 15:28:08 +00:00
|
|
|
mkdir -p ./wp-content/uploads/wc-logs
|
|
|
|
echo 'deny from all' > ./wp-content/uploads/wc-logs/.htaccess
|
|
|
|
chmod -R 777 ./
|
2022-05-24 11:42:54 +00:00
|
|
|
|
2021-08-20 13:58:32 +00:00
|
|
|
- name: Run PHPUnit tests
|
2022-11-09 15:28:08 +00:00
|
|
|
run: |
|
|
|
|
JSON='{"phpVersion": "${{ matrix.php }}"}'
|
|
|
|
echo $JSON > .wp-env.override.json
|
|
|
|
npm run wp-env start --update
|
|
|
|
npm run test:php
|
2022-05-24 11:42:54 +00:00
|
|
|
|
2021-08-20 13:58:32 +00:00
|
|
|
- name: Run PHPUnit tests (WooCommerce Development Version)
|
2021-08-17 12:25:11 +00:00
|
|
|
run: |
|
2022-11-09 15:28:08 +00:00
|
|
|
JSON='{"plugins": [".","https://downloads.wordpress.org/plugin/woocommerce.zip"], "phpVersion": "${{ matrix.php }}"}'
|
2021-08-20 13:58:32 +00:00
|
|
|
echo $JSON > .wp-env.override.json
|
2022-11-09 15:28:08 +00:00
|
|
|
npm run wp-env stop
|
|
|
|
rm -rf /home/runner/wp-env/*
|
|
|
|
npm run wp-env start --update
|
2021-08-20 13:58:32 +00:00
|
|
|
npm run test:php
|
2021-08-17 12:25:11 +00:00
|
|
|
|
|
|
|
JSUnitTests:
|
|
|
|
name: JS Unit Tests
|
|
|
|
needs: Setup
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-03-23 07:41:43 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Cache node_modules
|
|
|
|
id: cache-node-modules
|
|
|
|
uses: actions/cache@v3
|
|
|
|
env:
|
|
|
|
cache-name: cache-node-modules
|
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
|
|
|
|
2022-03-23 07:41:43 +00:00
|
|
|
- name: Setup node version and npm cache
|
|
|
|
uses: actions/setup-node@v3
|
2021-08-17 12:25:11 +00:00
|
|
|
with:
|
2022-03-23 07:41:43 +00:00
|
|
|
node-version-file: '.nvmrc'
|
|
|
|
cache: 'npm'
|
2022-05-24 11:42:54 +00:00
|
|
|
|
|
|
|
- name: Download Build Assets
|
|
|
|
uses: actions/download-artifact@v3
|
|
|
|
with:
|
|
|
|
name: build-assets
|
2021-08-17 12:25:11 +00:00
|
|
|
|
|
|
|
- name: blocks.ini setup
|
2022-11-09 15:28:08 +00:00
|
|
|
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = test' > blocks.ini
|
2021-08-17 12:25:11 +00:00
|
|
|
|
|
|
|
- name: Run JavaScript Unit tests
|
2022-05-24 11:42:54 +00:00
|
|
|
run: npm run test
|