forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
289 lines (251 loc) · 11 KB
/
tests.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
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
286
287
288
289
name: Mautic tests and validations
on:
push:
branches:
- '[0-9].*'
pull_request:
merge_group:
schedule:
# Run every day at 10:45 AM UTC to discover potential issues with dependencies like PHP updates etc.
- cron: '45 10 * * *'
permissions:
contents: read # to fetch code (actions/checkout)
jobs:
phpunit:
# We don't want the scheduled jobs to run on forks of Mautic
if: (github.event_name == 'schedule' && (github.repository == 'mautic/mautic' || github.repository == 'mautic/api-library') ) || (github.event_name != 'schedule')
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
db-types: ['mysql', 'mariadb']
name: PHPUnit ${{ matrix.php-versions }} ${{ matrix.db-types }}
services:
database:
image: ${{ matrix.db-types == 'mysql' && 'mysql:5.7' || 'mariadb:10.3' }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: mautictest
ports:
- 3306
options: >-
--shm-size=2gb
--name=${{ matrix.db-types }}
--tmpfs=/var/lib/mysql
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- uses: actions/checkout@v4
# Codecov needs access to previous commits, so we add fetch-depth: 0
with:
fetch-depth: 0
- name: PHPUnit cache
if: ${{matrix.php-versions == '8.1' && matrix.db-types == 'mariadb'}}
uses: actions/cache@v4
with:
path: ./var/cache/phpunit
key: ${{ runner.os }}-phpunit-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-phpunit-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-phpunit-
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
coverage: pcov
ini-values: pcov.enabled=0, pcov.directory=., pcov.exclude="~tests|themes|vendor~"
- name: add MySQL config file
run: |
mysqldump --version
mysqldump --print-defaults
cp .github/ci-files/.my.cnf ~/.my.cnf
mysqldump --print-defaults
- name: Set SYMFONY_ENV to test
run: |
echo "SYMFONY_ENV=test" >> $GITHUB_ENV
echo "MAUTIC_ENV=test" >> $GITHUB_ENV
- name: Install dependencies
# composer install cache - https://github.com/ramsey/composer-install
uses: "ramsey/composer-install@v3"
- name: Run tests - database = ${{ matrix.db-types }}
run: |
rm -rf var/cache
export DB_PORT="${{ job.services.database.ports[3306] }}"
if [[ "${{ matrix.php-versions }}" == "8.1" ]] && [[ "${{ matrix.db-types }}" == "mariadb" ]]; then
php -d zend.assertions=1 -d pcov.enabled=1 bin/phpunit -d memory_limit=2G --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --coverage-clover=coverage.xml --log-junit=junit.xml
else
php -d zend.assertions=1 bin/phpunit -d memory_limit=1G --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist
fi
- name: Upload coverage report
if: ${{ matrix.php-versions == '8.1' && matrix.db-types == 'mariadb' && github.repository == 'mautic/mautic' }}
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Save test results for future steps
if: ${{ matrix.php-versions == '8.1' && matrix.db-types == 'mariadb' && github.repository == 'mautic/mautic' }}
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
./junit.xml
./coverage.xml
- name: Slack Notification if tests fail
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() && github.event_name == 'schedule' }}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: 'The daily GitHub Actions tests in mautic/mautic have failed. Most likely something external has changed, like a PHP version update.'
- name: Store log artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.php-versions }}-${{ matrix.db-types }}
path: ./var/logs/*
e2e-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup DDEV
uses: ddev/github-action-setup-ddev@v1
- name: Set up environment variables for test mode
run: echo -e "APP_ENV=test\nAPP_DEBUG=1" > .env.local
- name: Run E2E tests
run: ddev exec bin/codecept run acceptance
- name: Upload test artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-test-screenshots
path: tests/_output
if-no-files-found: ignore
misc:
# We don't want the scheduled jobs to run on forks of Mautic
if: (github.event_name == 'schedule' && (github.repository == 'mautic/mautic' || github.repository == 'mautic/api-library') ) || (github.event_name != 'schedule')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
commands: ['PHPSTAN', 'CS Fixer', 'Rector', 'Twig Lint', 'scaffolded files mismatch', 'PHPStan baseline changes', 'composer install', 'composer lock check']
php-versions: ['8.1']
name: ${{ matrix.commands }} - ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Rector Cache
if: ${{matrix.commands == 'Rector'}}
uses: actions/cache@v4
with:
path: ./var/cache/rector
key: ${{ runner.os }}-rector-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-rector-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-rector-
- name: PHPStan Cache
if: ${{matrix.commands == 'PHPSTAN'}}
uses: actions/cache@v4
with:
path: ./var/phpstan-cache
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-phpstan-
- name: NPM Cache
uses: actions/cache@v4
with:
path: ./var/cache/js
key: ${{ runner.os }}-js-${{ hashFiles('**/package-lock.json', 'webpack.config.js') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-js-${{ hashFiles('**/package-lock.json', 'webpack.config.js') }}
${{ runner.os }}-js-
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql, pdo_mysql
- name: Install dependencies
# composer install cache - https://github.com/ramsey/composer-install
uses: "ramsey/composer-install@v3"
env:
NPM_CONFIG_CACHE: ./var/cache/js/npm
- name: Run ${{ matrix.commands }}
run: |
if [[ "${{ matrix.commands }}" == "PHPSTAN" ]]; then
export SYMFONY_ENV=dev
export APP_ENV=dev
export APP_DEBUG=1
composer phpstan -- --no-progress
elif [[ "${{ matrix.commands }}" == "Rector" ]]; then
export SYMFONY_ENV=test
bin/console cache:warmup
bin/rector --dry-run --ansi
elif [[ "${{ matrix.commands }}" == "Twig Lint" ]]; then
bin/console lint:twig app plugins
elif [[ "${{ matrix.commands }}" == "CS Fixer" ]]; then
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $file == *.php ]]; then
cs_fix_files="${cs_fix_files} $file"
fi
done
if [[ $cs_fix_files ]]; then
bin/php-cs-fixer fix --config=.php-cs-fixer.php --dry-run --using-cache=no --show-progress=dots --diff $cs_fix_files
fi
elif [[ "${{ matrix.commands }}" == "scaffolded files mismatch" ]]; then
wget -q -O /tmp/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && chmod 755 /tmp/jq
/tmp/jq -r '.extra["mautic-scaffold"]["file-mapping"] | to_entries[] | "diff -q \(.key | sub("\\[(project|web)-root\\]";".")) app/\(.value)"' app/composer.json > diff_commands.sh
/tmp/jq -r '.extra["mautic-scaffold"]["file-mapping"] | to_entries[] | "diff -rui \(.key | sub("\\[(project|web)-root\\]";".")) app/\(.value)"' app/composer.json > diff_commands_verbose.sh
bash diff_commands.sh 2>&1 | tee /tmp/diff_command_output.txt
rm diff_commands.sh
if [[ $(wc -l </tmp/diff_command_output.txt) -ge 1 ]]; then
echo "some scaffolded files were not updated or deleted"
echo "Please apply the same changes in the files mentioned above"
echo "verbose diff:"
bash diff_commands_verbose.sh
exit 1
fi
elif [[ "${{ matrix.commands }}" == "PHPStan baseline changes" ]]; then
if [[ "${{ steps.changed-files.outputs.modified_files }}" == *"phpstan-baseline.neon"* ]]; then
stat=$(git diff --shortstat "origin/${{ github.base_ref }}" ${{ github.sha }} -- phpstan-baseline.neon)
echo $stat
regex="[0-9]+[[:space:]]insertion"
if [[ $stat =~ $regex ]]; then
echo "There are modifications (added or changed lines) to the phpstan-baseline.neon"
echo "Please fix the PHPStan errors instead of altering the baseline file"
exit 1
fi
fi
elif [[ "${{ matrix.commands }}" == "composer install" ]]; then
# create a temp dir and mimic a composer install via mautic/recommended-project
mkdir test_composer
cd test_composer
cp ../.github/ci-files/composer.json ./
composer install
# test if media/css and media/js folder contain the same files as the tarball releases
test -z "$(comm -23 <(ls ../media/js | sort) <(ls docroot/media/js | sort))"
test -z "$(comm -23 <(ls ../media/css | sort) <(ls docroot/media/css | sort))"
# test if console is executable
./bin/console cache:clear
elif [[ "${{ matrix.commands }}" == "composer lock check" ]]; then
composer validate --ansi
else
echo "Invalid command"
exit 1
fi
- name: Slack Notification if tests fail
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() && github.event_name == 'schedule' }}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: 'The daily GitHub Actions tests in mautic/mautic have failed. Most likely something external has changed, like a PHP version update.'