-
Notifications
You must be signed in to change notification settings - Fork 286
235 lines (207 loc) · 7.84 KB
/
test.yml
File metadata and controls
235 lines (207 loc) · 7.84 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
name: PHPUnit Tests
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
env:
DB_NAME: facturascripts_test
DB_USER: root
DB_PASS: root
DB_HOST: 127.0.0.1
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.0', '8.1', '8.2', '8.3', '8.4']
database:
- type: mysql
version: '8.0'
port: 3306
- type: mariadb
version: '11.0'
port: 3306
- type: postgresql
version: '13'
port: 5432
fail-fast: false
name: PHP ${{ matrix.php-version }} - ${{ matrix.database.type }} ${{ matrix.database.version }}
services:
mysql:
image: ${{ matrix.database.type == 'mysql' && format('mysql:{0}', matrix.database.version) || '' }}
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: facturascripts_test
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
mariadb:
image: ${{ matrix.database.type == 'mariadb' && format('mariadb:{0}', matrix.database.version) || '' }}
env:
MARIADB_ROOT_PASSWORD: root
MARIADB_DATABASE: facturascripts_test
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: false
ports:
- 3306:3306
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=3
postgres:
image: ${{ matrix.database.type == 'postgresql' && format('postgres:{0}', matrix.database.version) || '' }}
env:
POSTGRES_PASSWORD: root
POSTGRES_DB: facturascripts_test
POSTGRES_USER: root
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U root -d facturascripts_test"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: bcmath, curl, gd, iconv, mysqli, pdo_mysql, pdo_pgsql, pgsql, soap, zip, fileinfo, openssl, simplexml, mbstring, intl
coverage: xdebug
tools: composer:v2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- 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@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader
- name: Verify database connection
run: |
if [ "${{ matrix.database.type }}" = "mysql" ] || [ "${{ matrix.database.type }}" = "mariadb" ]; then
echo "Testing ${{ matrix.database.type }} ${{ matrix.database.version }} connection..."
mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SHOW DATABASES;"
mysql --host=${{ env.DB_HOST }} --user=${{ env.DB_USER }} --password=${{ env.DB_PASS }} -e "SELECT VERSION();"
else
echo "Testing PostgreSQL ${{ matrix.database.version }} connection..."
PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "\l"
PGPASSWORD=${{ env.DB_PASS }} psql -h ${{ env.DB_HOST }} -U ${{ env.DB_USER }} -d ${{ env.DB_NAME }} -c "SELECT version();"
fi
- name: Create application config
run: |
if [ "${{ matrix.database.type }}" = "mysql" ] || [ "${{ matrix.database.type }}" = "mariadb" ]; then
cat > config.php << 'EOF'
<?php
define('FS_COOKIES_EXPIRE', 31536000);
define('FS_ROUTE', '');
define('FS_DB_TYPE', 'mysql');
define('FS_DB_HOST', '${{ env.DB_HOST }}');
define('FS_DB_PORT', 3306);
define('FS_DB_NAME', '${{ env.DB_NAME }}');
define('FS_DB_USER', '${{ env.DB_USER }}');
define('FS_DB_PASS', '${{ env.DB_PASS }}');
define('FS_DB_FOREIGN_KEYS', true);
define('FS_DB_TYPE_CHECK', true);
define('FS_MYSQL_CHARSET', 'utf8mb4');
define('FS_MYSQL_COLLATE', 'utf8mb4_unicode_520_ci');
define('FS_LANG', 'es_ES');
define('FS_TIMEZONE', 'Europe/Madrid');
define('FS_HIDDEN_PLUGINS', '');
define('FS_DEBUG', true);
define('FS_DISABLE_ADD_PLUGINS', false);
define('FS_DISABLE_RM_PLUGINS', false);
EOF
else
cat > config.php << 'EOF'
<?php
define('FS_COOKIES_EXPIRE', 31536000);
define('FS_ROUTE', '');
define('FS_DB_TYPE', 'postgresql');
define('FS_DB_HOST', '${{ env.DB_HOST }}');
define('FS_DB_PORT', 5432);
define('FS_DB_NAME', '${{ env.DB_NAME }}');
define('FS_DB_USER', '${{ env.DB_USER }}');
define('FS_DB_PASS', '${{ env.DB_PASS }}');
define('FS_DB_FOREIGN_KEYS', true);
define('FS_DB_TYPE_CHECK', true);
define('FS_LANG', 'es_ES');
define('FS_TIMEZONE', 'Europe/Madrid');
define('FS_HIDDEN_PLUGINS', '');
define('FS_DEBUG', true);
define('FS_DISABLE_ADD_PLUGINS', false);
define('FS_DISABLE_RM_PLUGINS', false);
EOF
fi
- name: Run PHPUnit tests
run: |
if [ -f phpunit.xml ] || [ -f phpunit.xml.dist ]; then
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
else
echo "No PHPUnit configuration found. Running with default settings..."
vendor/bin/phpunit --bootstrap vendor/autoload.php tests/
fi
- name: Upload coverage reports
if: matrix.php-version == '8.3' && matrix.database.type == 'mysql' && matrix.database.version == '8.1'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
security-audit:
runs-on: ubuntu-latest
name: Security Audit
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2
- name: Install dependencies
run: composer install --prefer-dist --no-dev --optimize-autoloader
- name: Run security audit
run: composer audit
code-quality:
runs-on: ubuntu-latest
name: Code Quality
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2, phpcs, phpstan
- name: Install dependencies
run: composer install --prefer-dist --no-progress --optimize-autoloader
- name: Run PHP CodeSniffer
run: |
if [ -f phpcs.xml ] || [ -f phpcs.xml.dist ]; then
phpcs
else
echo "No PHPCS configuration found, skipping..."
fi
continue-on-error: true
- name: Run PHPStan
run: |
if [ -f phpstan.neon ] || [ -f phpstan.neon.dist ]; then
phpstan analyse
else
echo "No PHPStan configuration found, skipping..."
fi
continue-on-error: true