Skip to content

Update codecoverage.yml #61

Update codecoverage.yml

Update codecoverage.yml #61

Workflow file for this run

name: Codecoverage
# Runs codeception unit and wpunit tests, merges the code coverage, commits the html report to
# GitHub Pages, generates a README badge with the coverage percentage.
# Requires a gh-pages branch already created.
on:
push:
branches:
- master
jobs:
codecoverage:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
matrix:
php: [ '7.4' ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout GitHub Pages branch for code coverage report
uses: actions/checkout@v3
with:
ref: gh-pages
path: tests/_output/html
- name: Install PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer
extensions: zip
- name: Update environment config for GitHub Actions
env:
PLUGIN_SLUG: ${{ github.event.repository.name }}
run: |
find . -depth \( -name '.env.testing' \) -exec sed -i "s/TEST_SITE_PORT=\"*\"/TEST_SITE_PORT=\"${{ job.services.mysql.ports['3306'] }}\"/g" {} +
find . -depth \( -name '.env.testing' -o -name '*.cest' \) -exec sed -i "s/localhost:8080\/${{ env.PLUGIN_SLUG }}/localhost:8080/g" {} +
find . -depth \( -name 'dump.sql' \) -exec sed -i "s/localhost:8080\/${{ env.PLUGIN_SLUG }}/localhost:8080/g" {} +
find tests -depth \( -name '*.yml' \) -exec sed -i "s/%TEST_DB_HOST%/127.0.0.1:${{ job.services.mysql.ports['3306'] }}/g" {} +
- name: Read .env.testing
uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: .env.testing
- name: Configure MySQL
run: |
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE USER '"$TEST_DB_USER"'@'%' IDENTIFIED WITH mysql_native_password BY '"$TEST_DB_PASSWORD"';";
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_SITE_DB_NAME"; USE "$TEST_SITE_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_SITE_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
mysql -h 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u root -ppassword -e "CREATE DATABASE "$TEST_DB_NAME"; USE "$TEST_DB_NAME"; GRANT ALL PRIVILEGES ON "$TEST_DB_NAME".* TO '"$TEST_DB_USER"'@'%';";
- name: Run composer install
continue-on-error: true
run: composer install
- name: Create wpconfig ... the composer.json creation didn't work
run: |
export $(grep -v '^#' .env.testing | xargs);
sudo vendor/bin/wp config create --dbname=$TEST_SITE_DB_NAME --dbuser=$TEST_SITE_DB_USER --dbpass=$TEST_SITE_DB_PASSWORD --dbhost=127.0.0.1:${{ job.services.mysql.ports['3306'] }} --allow-root --extra-php="define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true );"
tail -n 1000 wordpress/wp-config.php
- name: Run composer post-install-cmd
continue-on-error: true
run: composer run-script post-install-cmd
- name: Check database
run: vendor/bin/wp db check --debug
- name: Allow writing to wp-content
run: sudo chmod -R a+w wp-content
- name: Clear previous code coverage
run: |
cd tests/_output/html
rm $( grep -Ril 'php-code-coverage' )
for dir in "js" "templates" "icons" "css" "src"; do rm -rf $dir; done;
cd ../../..
rm -rf tests/_output/html/phpunit
mkdir tests/_output/html/phpunit
- name: Run unit tests
run: XDEBUG_MODE=coverage vendor/bin/codecept run unit --coverage unit.cov --debug || true;
- name: Run wpunit tests
run: XDEBUG_MODE=coverage vendor/bin/codecept run wpunit --coverage wpunit.cov --debug || true;
- name: Merge code coverage
run: vendor/bin/phpcov merge --clover tests/_output/clover.xml --html tests/_output/html/phpunit tests/_output;
- name: Edit phpcov html output to work with gh-pages
run: |
cd tests/_output/html/phpunit
mv _css css; find . -depth -name '*.html' -exec sed -i "s/_css\//css\//" {} +
mv _icons icons; find . -depth -name '*.html' -exec sed -i "s/_icons\//icons\//" {} +
mv _js js; find . -depth -name '*.html' -exec sed -i "s/_js\//js\//" {} +
git add *
cd ../../../..
- name: Discard environment changes before committing other changes
run: |
git checkout -- .env.testing
git checkout -- tests/_data/dump.sql
git checkout -- tests/integration.suite.yml
git checkout -- tests/wpunit.suite.yml
- name: Commit code coverage to gh-pages
uses: stefanzweifel/[email protected]
with:
repository: tests/_output/html
branch: gh-pages
commit_message: "🤖 Commit PHPUnit code coverage to gh-pages"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Update README badge
run: vendor/bin/php-coverage-badger tests/_output/clover.xml .github/coverage.svg PHPUnit
- name: Commit code coverage badge
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "🤖 Commit PHPUnit code coverage badge"
file_pattern: .github/coverage.svg