Skip to content

Commit 8bc0886

Browse files
committed
ci(adapters): restore full coverage pipeline with explicit stages and reporting
- Add pcov-based PHPUnit coverage execution - Generate Clover XML and HTML coverage reports - Extract and report coverage percentage - Publish coverage badge to badges branch - Include coverage in CI summary and Telegram notifications - Preserve full step-by-step structure and documentation clarity
1 parent 5f9541a commit 8bc0886

2 files changed

Lines changed: 234 additions & 320 deletions

File tree

.github/workflows/ci.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: Run Adapter Tests
2+
3+
on:
4+
push:
5+
branches: [ main, dev ]
6+
pull_request:
7+
branches: [ main, dev ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
15+
env:
16+
GH_START_ISO: ${{ github.event.head_commit.timestamp }}
17+
APP_ENV: testing
18+
19+
# Redis
20+
REDIS_HOST: 127.0.0.1
21+
REDIS_PORT: 6379
22+
REDIS_PASS: ""
23+
REDIS_MAIN_DSN: "redis://127.0.0.1:6379"
24+
REDIS_QUEUE_DSN: "redis://127.0.0.1:6379"
25+
REDIS_SESSIONS_DSN: "redis://127.0.0.1:6379/2"
26+
REDIS_CACHE_DSN: "redis://127.0.0.1:6379/2"
27+
REDIS_ANALYTICS_DSN: "redis://127.0.0.1:6380"
28+
29+
# Mongo
30+
MONGO_HOST: 127.0.0.1
31+
MONGO_PORT: 27017
32+
MONGO_USER: ""
33+
MONGO_PASS: ""
34+
MONGO_DB: maatify
35+
MONGO_AUTH_SOURCE: admin
36+
MONGO_MAIN_DSN: "mongodb://127.0.0.1:27017/maatify"
37+
MONGO_LOGS_DSN: "mongodb://127.0.0.1:27017/logs"
38+
MONGO_ACTIVITY_DSN: "mongodb://127.0.0.1:27017/activity"
39+
40+
# MySQL
41+
MYSQL_HOST: 127.0.0.1
42+
MYSQL_PORT: 3306
43+
MYSQL_USER: root
44+
MYSQL_PASS: root
45+
MYSQL_DB: maatify_dev
46+
MYSQL_DRIVER: dbal
47+
48+
MYSQL_DSN: "mysql:host=127.0.0.1;dbname=maatify_dev;charset=utf8mb4"
49+
MYSQL_MAIN_DSN: "mysql:host=127.0.0.1;dbname=maatify_main;charset=utf8mb4"
50+
MYSQL_MAIN_USER: root
51+
MYSQL_MAIN_PASS: root
52+
MYSQL_DEV_DSN: "mysql:host=127.0.0.1;dbname=maatify_dev;charset=utf8mb4"
53+
MYSQL_BILLING_DSN: "mysql:host=127.0.0.1;dbname=maatify_billing;charset=utf8mb4"
54+
MYSQL_LOGS_DSN: "mysql://root:root@127.0.0.1:3306/maatify_logs"
55+
MYSQL_LOGS_DRIVER: dbal
56+
57+
DB_REGISTRY_PATH: tests/fixtures/database_registry.json
58+
59+
services:
60+
redis:
61+
image: redis:7
62+
ports: [ "6379:6379" ]
63+
64+
mongo:
65+
image: mongo:7
66+
ports: [ "27017:27017" ]
67+
68+
mysql:
69+
image: mysql:8.0
70+
env:
71+
MYSQL_ROOT_PASSWORD: root
72+
MYSQL_DATABASE: maatify_dev
73+
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
74+
ports:
75+
- "3306:3306"
76+
77+
steps:
78+
# ---------------------------------------------
79+
# 1) Checkout
80+
# ---------------------------------------------
81+
- uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 0
84+
85+
# ---------------------------------------------
86+
# 2) PHP Setup (WITH COVERAGE)
87+
# ---------------------------------------------
88+
- uses: shivammathur/setup-php@v2
89+
with:
90+
php-version: "8.4"
91+
coverage: pcov
92+
extensions: mbstring, intl, pdo, pdo_mysql, redis, mongodb
93+
tools: composer
94+
95+
# ---------------------------------------------
96+
# 3) Cache Composer
97+
# ---------------------------------------------
98+
- uses: actions/cache@v4
99+
with:
100+
path: |
101+
~/.composer/cache
102+
~/.cache/composer
103+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
104+
restore-keys: ${{ runner.os }}-composer-
105+
106+
- run: composer config -g github-oauth.github.com "${{ github.token }}"
107+
108+
# ---------------------------------------------
109+
# 4) Install Dependencies
110+
# ---------------------------------------------
111+
- run: composer install --no-interaction --prefer-dist --no-progress
112+
113+
- run: composer dump-autoload --optimize
114+
115+
- run: sudo apt-get update && sudo apt-get install -y jq bc
116+
117+
# ---------------------------------------------
118+
# 5) Debug Services
119+
# ---------------------------------------------
120+
- name: 🔍 Debug Connections
121+
continue-on-error: true
122+
run: |
123+
redis-cli -h $REDIS_HOST ping || true
124+
mysql -h $MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -e "SELECT 1" || true
125+
mongo --host $MONGO_HOST --port $MONGO_PORT --eval "db.runCommand({ ping: 1 })" || true
126+
127+
# ---------------------------------------------
128+
# 6) Wait for MySQL
129+
# ---------------------------------------------
130+
- run: |
131+
for i in {1..30}; do
132+
mysqladmin ping -h 127.0.0.1 --silent && break
133+
sleep 2
134+
done
135+
136+
- run: |
137+
docker exec "${{ job.services.mysql.id }}" \
138+
mysql -uroot -proot -e \
139+
"ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';"
140+
141+
- run: |
142+
mysql -h $MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -e "CREATE DATABASE IF NOT EXISTS maatify_main;"
143+
mysql -h $MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -e "CREATE DATABASE IF NOT EXISTS maatify_logs;"
144+
mysql -h $MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -e "CREATE DATABASE IF NOT EXISTS maatify_dev;"
145+
mysql -h $MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASS -e "CREATE DATABASE IF NOT EXISTS maatify_test;"
146+
147+
# ---------------------------------------------
148+
# 7) PHPStan (non blocking)
149+
# ---------------------------------------------
150+
- name: Run PHPStan
151+
id: phpstan
152+
run: |
153+
set +e
154+
composer analyse > phpstan.log
155+
ERRORS=$(grep -Eo "Found ([0-9]+) errors" phpstan.log | grep -Eo "[0-9]+" || echo 0)
156+
echo "phpstan_errors=$ERRORS" >> $GITHUB_OUTPUT
157+
158+
# ---------------------------------------------
159+
# 8) PHPUnit WITH COVERAGE
160+
# ---------------------------------------------
161+
- name: 🧪 Run PHPUnit
162+
run: |
163+
vendor/bin/phpunit \
164+
--configuration phpunit.xml.dist \
165+
--coverage-clover coverage.xml \
166+
--coverage-html coverage \
167+
| tee phpunit.log
168+
169+
# ---------------------------------------------
170+
# 9) Extract Coverage %
171+
# ---------------------------------------------
172+
- name: Extract Coverage
173+
id: coverage
174+
run: |
175+
COV=$(php -r '
176+
$x=@simplexml_load_file("coverage.xml");
177+
$m=$x->project->metrics;
178+
echo (int)round(((int)$m["coveredstatements"]/(int)$m["statements"])*100);
179+
')
180+
echo "coverage=$COV" >> $GITHUB_OUTPUT
181+
182+
# ---------------------------------------------
183+
# 10) Coverage Badge
184+
# ---------------------------------------------
185+
- run: |
186+
echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${{ steps.coverage.outputs.coverage }}%\",\"color\":\"9C27B0\"}" > coverage-badge.json
187+
188+
- if: github.event_name == 'push'
189+
run: |
190+
git config user.name github-actions
191+
git config user.email actions@github.com
192+
git fetch origin
193+
git checkout badges || git checkout --orphan badges
194+
git reset --hard
195+
cp coverage-badge.json coverage.json
196+
git add coverage.json
197+
git commit -m "Update coverage to ${{ steps.coverage.outputs.coverage }}%" || true
198+
git push origin badges --force
199+
200+
# ---------------------------------------------
201+
# 11) Summary
202+
# ---------------------------------------------
203+
- if: always()
204+
run: |
205+
echo "### 🧾 Adapter Test Summary" >> $GITHUB_STEP_SUMMARY
206+
echo "📊 Coverage: ${{ steps.coverage.outputs.coverage }}%" >> $GITHUB_STEP_SUMMARY
207+
echo "🧹 PHPStan Errors: ${{ steps.phpstan.outputs.phpstan_errors }}" >> $GITHUB_STEP_SUMMARY
208+
tail -n 20 phpunit.log >> $GITHUB_STEP_SUMMARY
209+
210+
# ---------------------------------------------
211+
# 12) Telegram
212+
# ---------------------------------------------
213+
- if: always()
214+
env:
215+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_CI_BOT_TOKEN }}
216+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CI_CHAT_ID }}
217+
run: |
218+
STATUS="✅ Adapter Tests Passed"
219+
COLOR="🟢"
220+
grep -q "FAILURES!" phpunit.log && STATUS="❌ Tests Failed" && COLOR="🔴"
221+
222+
MESSAGE="📢 <b>Maatify CI Report</b>
223+
224+
${COLOR} ${STATUS}
225+
226+
🧹 <b>PHPStan:</b> ${{ steps.phpstan.outputs.phpstan_errors }} errors
227+
📊 <b>Coverage:</b> ${{ steps.coverage.outputs.coverage }}%
228+
229+
🔗 <a href='${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}'>View CI</a>"
230+
231+
curl -s -X POST \
232+
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
233+
-H "Content-Type: application/json" \
234+
-d "$(jq -n --arg chat_id "$TELEGRAM_CHAT_ID" --arg text "$MESSAGE" --arg pm HTML '{chat_id:$chat_id,text:$text,parse_mode:$pm}')"

0 commit comments

Comments
 (0)