Add code coverage information #31
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PHPUnit Coverage | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
php-coverage: | |
name: "PHP Coverage Analysis" | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
env: | |
WP_ENV_PHP_VERSION: '8.2' | |
WP_ENV_CORE: 'https://wordpress.org/wordpress-latest.zip' | |
steps: | |
- uses: styfle/[email protected] | |
- uses: actions/checkout@v3 | |
- name: Setup Node.js (.nvmrc) | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
cache: npm | |
- name: Setup PHP with Xdebug | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.2' | |
coverage: xdebug | |
- name: Install dependencies | |
run: | | |
sudo apt-get update && sudo apt-get install -y libxml2-utils | |
composer update | |
npm ci | |
- name: Install WordPress with Xdebug enabled | |
run: npm run wp-env start -- --xdebug=coverage | |
- name: Run PHPUnit with Coverage | |
id: phpunit | |
run: | | |
# Run tests and capture coverage output | |
coverage_output=$(npm run test-php-coverage -- --coverage-text) | |
# Extract only the coverage report section and format it | |
filtered_output=$(echo "$coverage_output" | sed -n '/^Code Coverage Report:/,$p' | sed '1 s/^/## /' | sed '/^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/d' | sed '/^Summary:/s/^/### /') | |
echo "$filtered_output" | tee coverage-summary.txt | |
echo "coverage_summary<<EOF" >> $GITHUB_ENV | |
echo "$filtered_output" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Find Comment | |
uses: peter-evans/find-comment@v2 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: Code Coverage Report | |
- name: Create or Update Comment | |
uses: peter-evans/create-or-update-comment@v3 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: ${{ env.coverage_summary }} | |
edit-mode: replace |