-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (137 loc) · 5.75 KB
/
Copy pathtest.yml
File metadata and controls
175 lines (137 loc) · 5.75 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Maatify Bootstrap Tests
on:
push:
branches: [ "main", "master" ]
pull_request:
branches: [ "main", "master" ]
jobs:
tests:
runs-on: ubuntu-latest
env:
GH_START_ISO: ${{ github.event.head_commit.timestamp }}
APP_ENV: testing
strategy:
matrix:
php: [ "8.4" ] # ✅ Only 8.4 supported officially
steps:
- name: 🛎️ Checkout repository
uses: actions/checkout@v4
- name: ⚙️ Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: mbstring, intl, bcmath, redis
tools: composer:v2
- name: ♻️ Cache Composer packages
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: 📦 Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Run PHPStan
id: phpstan
run: |
(
set +e
composer analyse > phpstan_output.txt
ANALYSE_EXIT=$?
echo "phpstan_exit=$ANALYSE_EXIT" >> $GITHUB_OUTPUT
ERRORS=$(grep -Eo "Found ([0-9]+) errors" phpstan_output.txt | grep -Eo "[0-9]+")
if [ -z "$ERRORS" ]; then ERRORS=0; fi
echo "phpstan_errors=$ERRORS" >> $GITHUB_OUTPUT
)
echo "PHPStan step completed without failing CI."
- name: 🧪 Run PHPUnit Tests
id: tests
run: |
vendor/bin/phpunit --configuration phpunit.xml | tee phpunit.log
continue-on-error: true
- name: 📄 Validate README & composer.json
run: |
test -f README.md
composer validate --no-check-all
- name: 🧾 Summary Report
if: always()
run: |
echo "### 🧾 Bootstrap Test Summary" >> $GITHUB_STEP_SUMMARY
echo "📦 Environment: $APP_ENV" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
tail -n 20 phpunit.log >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if grep -q "FAILURES!" phpunit.log; then
echo "❌ Some tests failed." >> $GITHUB_STEP_SUMMARY
else
echo "✅ All tests passed successfully." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.phpstan.outputs.phpstan_errors }}" -eq 0 ]; then
echo "🧹 PHPStan: Passed (0 errors)." >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ PHPStan: ${{ steps.phpstan.outputs.phpstan_errors }} errors detected." >> $GITHUB_STEP_SUMMARY
fi
- name: 🐳 Docker Build Check
run: docker build -t maatify/bootstrap:test -f docker/Dockerfile .
- name: 📲 Notify Telegram
if: always()
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_CI_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CI_CHAT_ID }}
run: |
START_TS=$(date -u -d "$GH_START_ISO" +%s)
END_TS=$(date +%s)
START_TIME=$(date -u -d "@$START_TS" +"%H:%M:%S UTC")
END_TIME=$(date -u +"%H:%M:%S UTC")
DURATION=$((END_TS - START_TS))
if [ "$DURATION" -lt 60 ]; then
DURATION_STR="${DURATION}s"
else
DURATION_STR="$(($DURATION / 60))m $(($DURATION % 60))s"
fi
STATUS="✅ Tests passed successfully!"
COLOR="🟢"
HEADER="Maatify CI Report (${GITHUB_REPOSITORY})"
if grep -q "FAILURES!" phpunit.log || [ "${{ job.status }}" != "success" ]; then
STATUS="❌ Some tests failed. Please review the log."
COLOR="🔴"
HEADER="Maatify CI Alert (${GITHUB_REPOSITORY})"
fi
PROJECT="maatify/bootstrap"
BRANCH="$GITHUB_REF_NAME"
ACTOR="$GITHUB_ACTOR"
URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
PHPSTAN_ERRORS="${{ steps.phpstan.outputs.phpstan_errors }}"
if [ "$PHPSTAN_ERRORS" -eq 0 ]; then
PHPSTAN_SUMMARY="🧹 <b>PHPStan:</b> Passed (0 errors)"
else
PHPSTAN_SUMMARY="🧹 <b>PHPStan:</b> ${PHPSTAN_ERRORS} errors detected"
fi
MESSAGE="📢 <b>${HEADER}</b>
${COLOR} ${STATUS}
${PHPSTAN_SUMMARY}
📦 <b>Project:</b> ${PROJECT}
🧱 <b>Branch:</b> ${BRANCH}
👷♂️ <b>Committer:</b> ${ACTOR}
⏱ <b>Start:</b> ${START_TIME}
🕒 <b>End:</b> ${END_TIME}
📈 <b>Duration:</b> ${DURATION_STR}
🔗 <a href='${URL}'>View Run Log</a>"
PAYLOAD=$(jq -n \
--arg chat_id "$TELEGRAM_CHAT_ID" \
--arg text "$MESSAGE" \
--arg parse_mode "HTML" \
'{chat_id: $chat_id, text: $text, parse_mode: $parse_mode}')
RESPONSE=$(curl -s -o /tmp/tg_resp.json -w "%{http_code}" \
-X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
echo "Raw Telegram Response (HTTP $RESPONSE):"
cat /tmp/tg_resp.json
if [ "$RESPONSE" -ne 200 ]; then
echo "⚠️ Telegram notification failed (HTTP $RESPONSE)" >> $GITHUB_STEP_SUMMARY
cat /tmp/tg_resp.json >> $GITHUB_STEP_SUMMARY
else
echo "✅ Telegram notification sent successfully." >> $GITHUB_STEP_SUMMARY
fi