Merge pull request #116 from newfold-labs/fix/PRESS10-60 #36
This file contains 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: Unit tests + Code coverage report | |
# Runs PHPUnit unit and Codeception wp-browser wpunit tests, merges the code coverage, commits the html report to | |
# GitHub Pages, generates a README badge with the coverage percentage. | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [ opened, reopened, ready_for_review, synchronize ] | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
unit-tests: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_ROOT_PASSWORD: password | |
MYSQL_DATABASE: tests-wordpress | |
ports: | |
- 62088:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
strategy: | |
matrix: | |
php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # attempting to get all branch names. | |
# - name: Check does gh-pages branch need to be created | |
# run: | | |
# git branch -l; | |
# if [[ $(git branch -l gh-pages) == "" ]]; then | |
# gh_pages_branch_needed=true; | |
# echo "gh-pages branch is needed"; | |
# else | |
# gh_pages_branch_needed=false | |
# echo "gh-pages branch already exists"; | |
# fi | |
# echo "GH_PAGES_BRANCH_NEEDED=$gh_pages_branch_needed" >> $GITHUB_ENV; | |
# mkdir gh-pages | |
# | |
# - name: Maybe create gh-pages branch | |
# if: ${{ env.GH_PAGES_BRANCH_NEEDED }} | |
# uses: peaceiris/actions-gh-pages@v4 | |
# with: | |
# github_token: ${{ secrets.GITHUB_TOKEN }} | |
# publish_dir: ./gh-pages | |
# force_orphan: true | |
# allow_empty_commit: true | |
# commit_message: "🤖 Creating gh-pages branch" | |
- name: Checkout GitHub Pages branch for code coverage report | |
uses: actions/checkout@v3 | |
with: | |
ref: gh-pages | |
path: gh-pages | |
- name: Install PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php }} | |
coverage: xdebug | |
tools: composer, jaschilz/php-coverage-badger | |
extensions: zip | |
- name: Read .env.testing | |
uses: c-py/action-dotenv-to-setenv@v2 | |
with: | |
env-file: .env.testing | |
- name: Run composer install | |
continue-on-error: true | |
run: composer install -v | |
- name: Allow writing to wp-content | |
run: sudo chmod -R a+w wp-content | |
- name: Clear previous code coverage | |
run: | | |
rm -rf gh-pages/phpunit || true; | |
mkdir gh-pages/phpunit || true; | |
- name: Run unit tests | |
run: XDEBUG_MODE=coverage vendor/bin/phpunit --bootstrap tests/phpunit/bootstrap.php --coverage-php tests/_output/unit.cov --debug | |
- name: Run wpunit tests | |
run: XDEBUG_MODE=coverage vendor/bin/codecept run wpunit --coverage tests/_output/wpunit.cov --debug | |
- name: Merge code coverage | |
run: vendor/bin/phpcov merge --clover gh-pages/phpunit/clover.xml --php gh-pages/phpunit/phpunit.cov --html gh-pages/phpunit/html/ tests/_output/; | |
# See: https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/ | |
- name: Add `.nojekyll` file so code coverage report successfully deploys to gh-pages | |
working-directory: gh-pages/phpunit | |
run: | | |
touch .nojekyll | |
git add -- .nojekyll * | |
- name: Update README badge | |
run: php-coverage-badger gh-pages/phpunit/clover.xml gh-pages/phpunit/coverage.svg | |
- name: Commit code coverage to gh-pages | |
if: ${{ (github.ref == 'refs/heads/main') && (matrix.php == '7.3') }} # only commit on main, on the PHP version we're using in production. | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
repository: gh-pages | |
branch: gh-pages | |
commit_message: "🤖 Save code coverage report to gh-pages" # TODO: include the percentage change in the message. | |
commit_options: "" | |
env: | |
GITHUB_TOKEN: "${{ github.token }}" |