forked from FirebirdSQL/php-firebird
-
-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·285 lines (251 loc) · 10.8 KB
/
Copy pathcode-quality.yml
File metadata and controls
executable file
·285 lines (251 loc) · 10.8 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Code Quality
on:
push:
branches: [main, master, 'feature/**', 'feat/**', 'fix/**', 'release/**']
tags:
- 'v[0-9]*.*'
pull_request:
branches: [main, master]
# Cancel in-progress runs for the same branch
permissions:
contents: read
security-events: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ==========================================================================
# PHP Static Analysis (PHPStan + PHPCS)
# ==========================================================================
php-analysis:
name: PHP Static Analysis
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup PHP
uses: shivammathur/setup-php@728c6c6b8cf02c2e48117716a91ee48313958a19 # v2
with:
php-version: '8.3'
tools: composer:v2
coverage: none
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock', '**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan analyse --error-format=github
- name: Run PHPCS
run: vendor/bin/phpcs --report=checkstyle src/ | cs2pr || vendor/bin/phpcs src/
# ==========================================================================
# Stub Sync Check (php-firebird-stubs / doctrine-firebird-driver protection)
# ==========================================================================
stubs-sync:
name: Stubs Sync Check
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Check stubs are in sync with firebird.c PHP_FE registrations
run: |
chmod +x scripts/check-stubs-sync.sh
bash scripts/check-stubs-sync.sh
- name: Check --CLEAN-- sections for DDL tests
run: |
chmod +x scripts/check-clean-sections.sh
bash scripts/check-clean-sections.sh
# ==========================================================================
# C/C++ Static Analysis (clang-tidy + cppcheck)
# ==========================================================================
c-analysis:
name: C/C++ Static Analysis
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Install analysis tools
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
clang-tidy \
cppcheck \
bear \
php-dev \
libfbclient2 \
firebird-dev || true
- name: Generate compile_commands.json
run: |
# Create a minimal compile_commands.json for static analysis
# This allows analysis without full Firebird installation
cat > compile_commands.json << 'EOF'
[
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c firebird.c -o firebird.o",
"file": "firebird.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_blobs.c -o fbird_blobs.o",
"file": "fbird_blobs.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_events.c -o fbird_events.o",
"file": "fbird_events.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_inspection.c -o fbird_inspection.o",
"file": "fbird_inspection.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_metadata.c -o fbird_metadata.o",
"file": "fbird_metadata.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_query_exec.c -o fbird_query_exec.o",
"file": "fbird_query_exec.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_result.c -o fbird_result.o",
"file": "fbird_result.c"
},
{
"directory": "${{ github.workspace }}",
"command": "gcc -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -c fbird_service.c -o fbird_service.o",
"file": "fbird_service.c"
},
{
"directory": "${{ github.workspace }}",
"command": "g++ -I/usr/include/php/20230831 -I/usr/include/firebird -DHAVE_CONFIG_H -std=c++17 -c firebird_utils.cpp -o firebird_utils.o",
"file": "firebird_utils.cpp"
}
]
EOF
- name: Run cppcheck
run: |
# Define FB_API_VER to satisfy Firebird version check during static analysis
# The extension requires FB 3.0+ (FB_API_VER >= 30), we simulate FB 4.0 headers
CPPCHECK_DEFINES="-DFB_API_VER=40 -DHAVE_CONFIG_H -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"
cppcheck \
$CPPCHECK_DEFINES \
--enable=warning,style,performance,portability \
--suppress=missingIncludeSystem \
--suppress=missingInclude \
--suppress=unknownMacro \
--error-exitcode=0 \
--inline-suppr \
--xml \
--xml-version=2 \
*.c *.cpp 2>&1 | tee cppcheck-report.xml
# Check for errors (exit code 0 = no errors)
cppcheck \
$CPPCHECK_DEFINES \
--enable=warning,performance,portability \
--suppress=missingIncludeSystem \
--suppress=missingInclude \
--suppress=unknownMacro \
--error-exitcode=1 \
--inline-suppr \
*.c *.cpp
- name: Run clang-tidy (informational, non-blocking per-file due to PHP header noise)
run: |
# clang-tidy output is informational; PHP headers generate unavoidable
# warnings. Per-file `|| true` prevents blocking on those. Review logs manually.
for file in *.c *.cpp; do
if [ -f "$file" ]; then
echo "Analyzing $file..."
clang-tidy "$file" \
--checks='-*,bugprone-*,cert-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,performance-*' \
--header-filter='.*\.h$' \
-- -I/usr/include/php/20230831 -I/usr/include/firebird 2>/dev/null || true
fi
done
# ==========================================================================
# Version Stamp Check (stubs @version must match VERSION.txt)
# ==========================================================================
version-stamps:
name: Version Stamps Check
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Check stubs @version tags match VERSION.txt
run: |
chmod +x scripts/check-version-stamps.sh
bash scripts/check-version-stamps.sh
# ==========================================================================
# Secret Detection (Gitleaks CLI - no license required)
# ==========================================================================
secrets-scan:
name: Secret Detection
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Install Gitleaks
run: |
# Download latest gitleaks release using jq for reliable JSON parsing
GITLEAKS_VERSION=$(curl -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest | jq -r '.tag_name')
if [ -z "$GITLEAKS_VERSION" ] || [ "$GITLEAKS_VERSION" = "null" ]; then
echo "Failed to get gitleaks version, using fallback v8.21.2"
GITLEAKS_VERSION="v8.21.2"
fi
echo "Installing gitleaks ${GITLEAKS_VERSION}"
curl -fsSL "https://github.com/gitleaks/gitleaks/releases/download/${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION#v}_linux_x64.tar.gz" -o gitleaks.tar.gz
tar xzf gitleaks.tar.gz
chmod +x gitleaks
sudo mv gitleaks /usr/local/bin/
rm -f gitleaks.tar.gz
- name: Run Gitleaks
run: |
gitleaks detect \
--config=.gitleaks.toml \
--source=. \
--verbose \
--redact
# ==========================================================================
# Quality Summary
# ==========================================================================
quality-summary:
name: Quality Gate
runs-on: ubuntu-24.04
needs: [php-analysis, stubs-sync, c-analysis, version-stamps, secrets-scan]
if: always()
timeout-minutes: 15
steps:
- name: Check job results
run: |
echo "PHP Analysis: ${{ needs.php-analysis.result }}"
echo "Stubs Sync: ${{ needs.stubs-sync.result }}"
echo "C/C++ Analysis: ${{ needs.c-analysis.result }}"
echo "Version Stamps: ${{ needs.version-stamps.result }}"
echo "Secrets Scan: ${{ needs.secrets-scan.result }}"
if [ "${{ needs.php-analysis.result }}" = "failure" ] || \
[ "${{ needs.stubs-sync.result }}" = "failure" ] || \
[ "${{ needs.c-analysis.result }}" = "failure" ] || \
[ "${{ needs.version-stamps.result }}" = "failure" ] || \
[ "${{ needs.secrets-scan.result }}" = "failure" ]; then
echo "❌ Quality gate failed"
exit 1
fi
echo "✅ All quality checks passed"