diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml new file mode 100644 index 0000000000..d191fff3f3 --- /dev/null +++ b/.github/workflows/test-coverage.yml @@ -0,0 +1,156 @@ +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