-
Notifications
You must be signed in to change notification settings - Fork 4
120 lines (99 loc) · 3.93 KB
/
unit-tests-and-coverage-report.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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:
codecoverage-main:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
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
- name: Check does gh-pages branch need to be created
run: |
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/[email protected]
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 || true;
- name: Run wpunit tests
run: XDEBUG_MODE=coverage vendor/bin/codecept run wpunit --coverage tests/_output/wpunit.cov --debug || true;
- 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-version == '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 }}"