forked from Nullcorps/woocommerce-gateway-bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 2
143 lines (115 loc) · 5.54 KB
/
codecoverage.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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/setup-php@v2
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_DB_HOST=\"127.0.0.1\"/TEST_SITE_DB_HOST=\"127.0.0.1:${{ 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: Read secrets (upload local `.env.secret` file using `gh secret set -f .env.secret`)
uses: Firenza/secrets-to-env@v1.2.0
with:
secrets: ${{ toJSON(secrets) }}
- 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 -rf *
cd ../../..
- 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 tests/_output;
- name: Edit phpcov html output to work with gh-pages
run: |
cd tests/_output/html
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
git checkout -- tests/contract.suite.yml
- name: Commit code coverage to gh-pages
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: tests/_output/html
branch: gh-pages
commit_message: "🤖 Commit 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 code coverage badge"
file_pattern: .github/coverage.svg