wordpress-develop/.github/workflows/test-coverage.yml
Jonathan Desrosiers 8bc7e0c0e5 Build/Test Tools: Generate a code coverage report using GitHub Actions.
This introduces a new GitHub Action workflow to generate a code coverage report when running the PHPUnit test suite as both a single and multisite install.

The workflow will run once per week on Sunday at 00:00 UTC.

For now, the reports are not submitted anywhere, but they will be uploaded to the workflow run as ZIP file artifacts where they will persist for 90 days.

Making code coverage reports more readily available will hopefully better highlight areas of Core with poor coverage, and encourage more contributors to help increase test coverage of those areas.

Props ocean90, johnbillion.
Fixes #52034.

git-svn-id: https://develop.svn.wordpress.org/trunk@49834 602fd350-edb4-49c9-b593-d223f7449a82
2020-12-18 00:28:27 +00:00

157 lines
5.2 KiB
YAML

name: Code Coverage Report
on:
# Once weekly On Sundays at 00:00 UTC.
schedule:
- cron: '0 0 * * 0'
env:
LOCAL_DIR: build
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: ${{ true }}
COMPOSER_INSTALL: ${{ false }}
# Controls which NPM script to use for running PHPUnit tests. Options ar `php` and `php-composer`.
PHPUNIT_SCRIPT: php
LOCAL_PHP: '7.4-fpm'
LOCAL_PHP_XDEBUG: true
LOCAL_PHP_MEMCACHED: ${{ false }}
jobs:
# Sets up WordPress for testing or development use.
#
# Performs the following steps:
# - Set environment variables.
# - Checks out the repository.
# - Checks out the WordPress Importer plugin (needed for the Core PHPUnit tests).
# - Logs debug information about the runner container.
# - Installs NodeJS 14.
# - Sets up caching for NPM.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
# - Logs Docker debug information (about the Docker installation within the runner).
# - Starts the WordPress Docker container.
# - Logs debug general information.
# - Logs the running Docker containers.
# - Logs WordPress Docker container debug information.
# - Logs debug information about what's installed within the WordPress Docker containers.
# - Install WordPress within the Docker container.
# - Run the PHPUnit tests.
# - Creates a ZIP file of the code coverage report.
# - Uploads ZIP file as an artifact.
# - Run the PHPUnit tests as a multisite.
# - Creates a ZIP file of the code coverage report.
# - Uploads ZIP file as an artifact.
test-coverage-report:
name: Generate a code coverage report
runs-on: ubuntu-latest
if: ${{ github.repository == 'WordPress/wordpress-develop' }}
steps:
- name: Configure environment variables
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout the WordPress Importer plugin
run: svn checkout -r 2387243 https://plugins.svn.wordpress.org/wordpress-importer/trunk/ tests/phpunit/data/plugins/wordpress-importer
- name: Log debug information
run: |
echo "$GITHUB_REF"
echo "$GITHUB_EVENT_NAME"
npm --version
node --version
curl --version
git --version
svn --version
php --version
php -i
locale -a
- name: Install NodeJS
uses: actions/setup-node@v1
with:
node-version: 14
- name: Cache NodeJS modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Install Dependencies
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build
- name: Docker debug information
run: |
docker -v
docker-compose -v
- name: Start Docker environment
run: |
npm run env:start
- name: General debug information
run: |
npm --version
node --version
curl --version
git --version
svn --version
- name: Log running Docker containers
run: docker ps -a
- name: WordPress Docker container debug information
run: |
docker-compose run --rm mysql mysql --version
docker-compose run --rm php php --version
docker-compose run --rm php php -m
docker-compose run --rm php php -i
docker-compose run --rm php locale -a
- name: Install WordPress
run: npm run env:install
- name: Run tests as a single site
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c phpunit.xml.dist --coverage-html wp-code-coverage-single-${{ github.sha }}
- name: Create ZIP artifact of single site results
uses: thedoctor0/zip-release@0.4.1
with:
filename: wp-code-coverage-single-${{ github.sha }}.zip
path: wp-code-coverage-single-${{ github.sha }}
- name: Upload single site coverage report
uses: actions/upload-artifact@v2
with:
name: wp-code-coverage-single-${{ github.sha }}
path: wp-code-coverage-single-${{ github.sha }}.zip
if-no-files-found: error
- name: Run tests as a multisite install
run: npm run test:${{ env.PHPUNIT_SCRIPT }} -- --verbose -c tests/phpunit/multisite.xml --coverage-html wp-code-coverage-multisite-${{ github.sha }}
- name: Create ZIP artifact of multisite results
uses: thedoctor0/zip-release@0.4.1
with:
filename: wp-code-coverage-multisite-${{ github.sha }}.zip
path: wp-code-coverage-multisite-${{ github.sha }}
- name: Upload multisite coverage report
uses: actions/upload-artifact@v2
with:
name: wp-code-coverage-multisite-${{ github.sha }}
path: wp-code-coverage-multisite-${{ github.sha }}.zip
if-no-files-found: error