1- name : Codecoverage-Main
1+ name : Unit tests + Code coverage report
22
33# Runs PHPUnit unit and Codeception wp-browser wpunit tests, merges the code coverage, commits the html report to
44# GitHub Pages, generates a README badge with the coverage percentage.
77 push :
88 branches :
99 - main
10+ pull_request :
11+ types : [ opened, reopened, ready_for_review, synchronize ]
12+ branches :
13+ - main
14+ workflow_dispatch :
1015
1116jobs :
1217
13- codecoverage-main :
18+ unit-tests :
1419 runs-on : ubuntu-latest
1520
1621 services :
1722 mysql :
18- image : mysql:8.0
23+ image : mysql:5.7
1924 env :
2025 MYSQL_ROOT_PASSWORD : password
2126 MYSQL_DATABASE : tests-wordpress
@@ -25,31 +30,36 @@ jobs:
2530
2631 strategy :
2732 matrix :
28- php : [ '7.4 ' ]
33+ php : [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3 ' ]
2934
3035 steps :
3136 - name : Checkout
3237 uses : actions/checkout@v3
33-
34- - name : Check does gh-pages branch need to be created
35- run : |
36- if [[ $(git branch -l gh-pages) == "" ]]; then
37- gh_pages_branch_needed=true
38- else
39- gh_pages_branch_needed=false
40- fi
41- echo "GH_PAGES_BRANCH_NEEDED=$gh_pages_branch_needed" >> $GITHUB_ENV;
42- mkdir gh-pages
43-
44- - name : Maybe create gh-pages branch
45- if : ${{ env.GH_PAGES_BRANCH_NEEDED }}
46- uses : peaceiris/actions-gh-pages@v4
4738 with :
48- github_token : ${{ secrets.GITHUB_TOKEN }}
49- publish_dir : ./gh-pages
50- force_orphan : true
51- allow_empty_commit : true
52- commit_message : " 🤖 Creating gh-pages branch"
39+ fetch-depth : 0 # attempting to get all branch names.
40+
41+ # - name: Check does gh-pages branch need to be created
42+ # run: |
43+ # git branch -l;
44+ # if [[ $(git branch -l gh-pages) == "" ]]; then
45+ # gh_pages_branch_needed=true;
46+ # echo "gh-pages branch is needed";
47+ # else
48+ # gh_pages_branch_needed=false
49+ # echo "gh-pages branch already exists";
50+ # fi
51+ # echo "GH_PAGES_BRANCH_NEEDED=$gh_pages_branch_needed" >> $GITHUB_ENV;
52+ # mkdir gh-pages
53+ #
54+ # - name: Maybe create gh-pages branch
55+ # if: ${{ env.GH_PAGES_BRANCH_NEEDED }}
56+ # uses: peaceiris/actions-gh-pages@v4
57+ # with:
58+ # github_token: ${{ secrets.GITHUB_TOKEN }}
59+ # publish_dir: ./gh-pages
60+ # force_orphan: true
61+ # allow_empty_commit: true
62+ # commit_message: "🤖 Creating gh-pages branch"
5363
5464 - name : Checkout GitHub Pages branch for code coverage report
5565 uses : actions/checkout@v3
@@ -83,10 +93,10 @@ jobs:
8393 mkdir gh-pages/phpunit || true;
8494
8595 - name : Run unit tests
86- run : XDEBUG_MODE=coverage vendor/bin/phpunit --bootstrap tests/phpunit/bootstrap.php --coverage-php tests/_output/unit.cov || true;
96+ run : XDEBUG_MODE=coverage vendor/bin/phpunit --bootstrap tests/phpunit/bootstrap.php --coverage-php tests/_output/unit.cov
8797
8898 - name : Run wpunit tests
89- run : XDEBUG_MODE=coverage vendor/bin/codecept run wpunit --coverage tests/_output/wpunit.cov --debug || true;
99+ run : XDEBUG_MODE=coverage vendor/bin/codecept run wpunit --coverage tests/_output/wpunit.cov --debug
90100
91101 - name : Merge code coverage
92102 run : vendor/bin/phpcov merge --clover gh-pages/phpunit/clover.xml --php gh-pages/phpunit/phpunit.cov --html gh-pages/phpunit/html/ tests/_output/;
@@ -102,6 +112,7 @@ jobs:
102112 run : php-coverage-badger gh-pages/phpunit/clover.xml gh-pages/phpunit/coverage.svg
103113
104114 - name : Commit code coverage to gh-pages
115+ if : ${{ github.ref == 'refs/heads/main' && matrix.php == '7.3' }} # only commit on main, on the PHP version we're using in production.
105116 uses : stefanzweifel/git-auto-commit-action@v5
106117 with :
107118 repository : gh-pages
0 commit comments