forked from akeneo/pim-community-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
366 lines (314 loc) · 17.7 KB
/
Jenkinsfile
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!groovy
def editions = ["ce"]
def storages = ["orm", "odm"]
def phpVersion = "5.6"
def mysqlVersion = "5.5"
def esVersion = "none"
def features = "features"
def launchUnitTests = "yes"
def launchIntegrationTests = "yes"
def launchBehatTests = "yes"
stage("Checkout") {
milestone 1
if (env.BRANCH_NAME =~ /^PR-/) {
userInput = input(message: 'Launch tests?', parameters: [
choice(choices: 'yes\nno', description: 'Run unit tests and code style checks', name: 'launchUnitTests'),
choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'),
choice(choices: 'yes\nno', description: 'Run behat tests', name: 'launchBehatTests'),
string(defaultValue: 'odm,orm', description: 'Storage used for the behat tests (comma separated values)', name: 'storages'),
string(defaultValue: 'ee,ce', description: 'PIM edition the behat tests should run on (comma separated values)', name: 'editions'),
string(defaultValue: 'features,vendor/akeneo/pim-community-dev/features', description: 'Behat scenarios to build', name: 'features'),
choice(choices: '5.6\n7.0\n7.1', description: 'PHP version to run behat with', name: 'phpVersion'),
choice(choices: '5.5\n5.7', description: 'Mysql version to run behat with', name: 'mysqlVersion'),
choice(choices: 'none\n1.7\n5', description: 'ElasticSearch version to run behat with', name: 'esVersion')
])
storages = userInput['storages'].tokenize(',')
editions = userInput['editions'].tokenize(',')
features = userInput['features']
phpVersion = userInput['phpVersion']
mysqlVersion = userInput['mysqlVersion']
esVersion = userInput['esVersion']
launchUnitTests = userInput['launchUnitTests']
launchIntegrationTests = userInput['launchIntegrationTests']
launchBehatTests = userInput['launchBehatTests']
}
milestone 2
node {
deleteDir()
checkout scm
stash "pim_community_dev"
if (editions.contains('ee') && 'yes' == launchBehatTests) {
checkout([$class: 'GitSCM',
branches: [[name: 'master']],
userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/akeneo/pim-enterprise-dev.git']]
])
stash "pim_enterprise_dev"
}
}
checkouts = [:];
checkouts['community'] = {
node('docker') {
deleteDir()
docker.image("carcel/php:5.6").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
sh "composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "app/console oro:requirejs:generate-config"
sh "app/console assets:install"
stash "pim_community_dev_full"
}
deleteDir()
}
}
if (editions.contains('ee') && 'yes' == launchBehatTests) {
checkouts['enterprise'] = {
node('docker') {
deleteDir()
docker.image("carcel/php:5.6").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_enterprise_dev"
sh "php -d memory_limit=-1 /usr/local/bin/composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "app/console oro:requirejs:generate-config"
sh "app/console assets:install"
stash "pim_enterprise_dev_full"
}
deleteDir()
}
}
}
parallel checkouts
}
if (launchUnitTests.equals("yes")) {
stage("Unit tests and Code style") {
def tasks = [:]
tasks["phpunit-5.6"] = {runPhpUnitTest("5.6")}
tasks["phpunit-7.0"] = {runPhpUnitTest("7.0")}
tasks["phpunit-7.1"] = {runPhpUnitTest("7.1")}
tasks["phpspec-5.6"] = {runPhpSpecTest("5.6")}
tasks["phpspec-7.0"] = {runPhpSpecTest("7.0")}
tasks["phpspec-7.1"] = {runPhpSpecTest("7.1")}
tasks["php-cs-fixer"] = {runPhpCsFixerTest()}
tasks["php-coupling-detector"] = {runPhpCouplingDetectorTest()}
tasks["grunt"] = {runGruntTest()}
parallel tasks
}
}
if (launchIntegrationTests.equals("yes")) {
stage("Integration tests") {
def tasks = [:]
tasks["phpunit-5.6-orm-api-base"] = {runIntegrationTest("5.6", "orm", "PIM_Api_Base_Integration_Test")}
tasks["phpunit-5.6-orm-api-controllers"] = {runIntegrationTest("5.6", "orm", "PIM_Api_Bundle_Controllers_Integration_Test")}
tasks["phpunit-5.6-orm-api-controllers-catalog"] = {runIntegrationTest("5.6", "orm", "PIM_Api_Bundle_Controllers_Catalog_Integration_Test")}
tasks["phpunit-5.6-orm-api-controller-product"] = {runIntegrationTest("5.6", "orm", "PIM_Api_Bundle_Controller_Product_Integration_Test")}
tasks["phpunit-5.6-orm-catalog"] = {runIntegrationTest("5.6", "orm", "PIM_Catalog_Integration_Test")}
tasks["phpunit-5.6-orm-completeness"] = {runIntegrationTest("5.6", "orm", "PIM_Catalog_Completeness_Integration_Test")}
tasks["phpunit-5.6-orm-pqb"] = {runIntegrationTest("5.6", "orm", "PIM_Catalog_PQB_Integration_Test")}
tasks["phpunit-7.0-orm-api-base"] = {runIntegrationTest("7.0", "orm", "PIM_Api_Base_Integration_Test")}
tasks["phpunit-7.0-orm-api-controllers"] = {runIntegrationTest("7.0", "orm", "PIM_Api_Bundle_Controllers_Integration_Test")}
tasks["phpunit-7.0-orm-api-controllers-catalog"] = {runIntegrationTest("7.0", "orm", "PIM_Api_Bundle_Controllers_Catalog_Integration_Test")}
tasks["phpunit-7.0-orm-api-controller-product"] = {runIntegrationTest("7.0", "orm", "PIM_Api_Bundle_Controller_Product_Integration_Test")}
tasks["phpunit-7.0-orm-catalog"] = {runIntegrationTest("7.0", "orm", "PIM_Catalog_Integration_Test")}
tasks["phpunit-7.0-orm-completeness"] = {runIntegrationTest("7.0", "orm", "PIM_Catalog_Completeness_Integration_Test")}
tasks["phpunit-7.0-orm-pqb"] = {runIntegrationTest("7.0", "orm", "PIM_Catalog_PQB_Integration_Test")}
tasks["phpunit-7.1-orm-api-base"] = {runIntegrationTest("7.1", "orm", "PIM_Api_Base_Integration_Test")}
tasks["phpunit-7.1-orm-api-controllers"] = {runIntegrationTest("7.1", "orm", "PIM_Api_Bundle_Controllers_Integration_Test")}
tasks["phpunit-7.1-orm-api-controllers-catalog"] = {runIntegrationTest("7.1", "orm", "PIM_Api_Bundle_Controllers_Catalog_Integration_Test")}
tasks["phpunit-7.1-orm-api-controller-product"] = {runIntegrationTest("7.1", "orm", "PIM_Api_Bundle_Controller_Product_Integration_Test")}
tasks["phpunit-7.1-orm-catalog"] = {runIntegrationTest("7.1", "orm", "PIM_Catalog_Integration_Test")}
// tasks["phpunit-7.1-orm-completeness"] = {runIntegrationTest("7.1", "orm", "PIM_Catalog_Completeness_Integration_Test")}
tasks["phpunit-7.1-orm-pqb"] = {runIntegrationTest("7.1", "orm", "PIM_Catalog_PQB_Integration_Test")}
// Temporarily deactivate integration tests with MongoDB because of stability issues
// tasks["phpunit-5.6-odm"] = {runIntegrationTest("5.6", "odm")}
// tasks["phpunit-7.0-odm"] = {runIntegrationTest("7.0", "odm")}
// tasks["phpunit-7.1-odm"] = {runIntegrationTest("7.1", "odm")}
parallel tasks
}
}
if (launchBehatTests.equals("yes")) {
stage("Functional tests") {
def tasks = [:]
if (editions.contains('ee') && storages.contains('odm')) {tasks["behat-ee-odm"] = {runBehatTest("ee", "odm", features, phpVersion, mysqlVersion, esVersion)}}
if (editions.contains('ee') && storages.contains('orm')) {tasks["behat-ee-orm"] = {runBehatTest("ee", "orm", features, phpVersion, mysqlVersion, esVersion)}}
if (editions.contains('ce') && storages.contains('odm')) {tasks["behat-ce-odm"] = {runBehatTest("ce", "odm", features, phpVersion, mysqlVersion, esVersion)}}
if (editions.contains('ce') && storages.contains('orm')) {tasks["behat-ce-orm"] = {runBehatTest("ce", "orm", features, phpVersion, mysqlVersion, esVersion)}}
parallel tasks
}
}
def runGruntTest() {
node('docker') {
deleteDir()
try {
docker.image('digitallyseamless/nodejs-bower-grunt').inside("") {
unstash "pim_community_dev_full"
sh "npm install"
sh "grunt"
}
} finally {
sh "docker stop \$(docker ps -a -q) || true"
sh "docker rm \$(docker ps -a -q) || true"
sh "docker volume rm \$(docker volume ls -q) || true"
deleteDir()
}
}
}
def runPhpUnitTest(phpVersion) {
node('docker') {
deleteDir()
try {
docker.image("carcel/php:${phpVersion}").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
if (phpVersion != "5.6") {
sh "composer require --no-update --ignore-platform-reqs alcaeus/mongo-php-adapter"
}
sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "mkdir -p app/build/logs/"
sh "./bin/phpunit -c app/phpunit.xml.dist --testsuite PIM_Unit_Test --log-junit app/build/logs/phpunit.xml"
}
} finally {
sh "docker stop \$(docker ps -a -q) || true"
sh "docker rm \$(docker ps -a -q) || true"
sh "docker volume rm \$(docker volume ls -q) || true"
sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${phpVersion}] /\" app/build/logs/*.xml"
junit "app/build/logs/*.xml"
deleteDir()
}
}
}
def runIntegrationTest(phpVersion, storage, testSuiteName) {
node('docker') {
deleteDir()
try {
docker.image("mongo:2.4").withRun("--name mongodb", "--smallfiles") {
docker.image("mysql:5.5").withRun("--name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim", "--sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION") {
docker.image("carcel/php:${phpVersion}").inside("--link mysql:mysql --link mongodb:mongodb -v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
if (phpVersion != "5.6") {
sh "composer require --no-update --ignore-platform-reqs alcaeus/mongo-php-adapter"
}
sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "cp app/config/parameters_test.yml.dist app/config/parameters_test.yml"
sh "sed -i 's/database_host: localhost/database_host: mysql/' app/config/parameters_test.yml"
// Activate MongoDB if needed
if ('odm' == storage) {
sh "sed -i \"s@// new Doctrine@new Doctrine@g\" app/AppKernel.php"
sh "sed -i \"s@# mongodb_database: .*@mongodb_database: akeneo_pim@g\" app/config/pim_parameters.yml"
sh "sed -i \"s@# mongodb_server: .*@mongodb_server: 'mongodb://mongodb:27017'@g\" app/config/pim_parameters.yml"
sh "printf \" pim_catalog_product_storage_driver: doctrine/mongodb-odm\n\" >> app/config/parameters_test.yml"
}
sh "./app/console --env=test pim:install --force"
sh "mkdir -p app/build/logs/"
sh "./bin/phpunit -c app/phpunit.xml.dist --testsuite ${testSuiteName} --log-junit app/build/logs/phpunit_integration.xml"
}
}
}
} finally {
sh "docker stop \$(docker ps -a -q) || true"
sh "docker rm \$(docker ps -a -q) || true"
sh "docker volume rm \$(docker volume ls -q) || true"
sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${phpVersion}-${storage}-${testSuiteName}] /\" app/build/logs/*.xml"
junit "app/build/logs/*.xml"
deleteDir()
}
}
}
def runPhpSpecTest(phpVersion) {
node('docker') {
deleteDir()
try {
docker.image("carcel/php:${phpVersion}").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
if (phpVersion != "5.6") {
sh "composer require --no-update --ignore-platform-reqs alcaeus/mongo-php-adapter"
}
sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "mkdir -p app/build/logs/"
sh "./bin/phpspec run --no-interaction --format=junit > app/build/logs/phpspec.xml"
}
} finally {
sh "docker stop \$(docker ps -a -q) || true"
sh "docker rm \$(docker ps -a -q) || true"
sh "docker volume rm \$(docker volume ls -q) || true"
sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${phpVersion}] /\" app/build/logs/*.xml"
junit "app/build/logs/*.xml"
deleteDir()
}
}
}
def runPhpCsFixerTest() {
node('docker') {
deleteDir()
try {
docker.image("carcel/php:7.1").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
sh "composer remove --dev --no-update doctrine/mongodb-odm-bundle;"
sh "composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "mkdir -p app/build/logs/"
sh "./bin/php-cs-fixer fix --diff --dry-run --format=junit --config=.php_cs.php > app/build/logs/phpcs.xml"
}
} finally {
sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-cs-fixer] /\" app/build/logs/*.xml"
junit "app/build/logs/*.xml"
deleteDir()
}
}
}
def runBehatTest(edition, storage, features, phpVersion, mysqlVersion, esVersion) {
node() {
dir("behat-${edition}-${storage}") {
deleteDir()
if ('ce' == edition) {
unstash "pim_community_dev_full"
tags = "~skip&&~skip-pef&&~skip-nav&&~doc&&~unstable&&~unstable-app&&~deprecated&&~@unstable-app"
} else {
unstash "pim_enterprise_dev_full"
dir('vendor/akeneo/pim-community-dev') {
deleteDir()
unstash "pim_community_dev"
}
tags = "~skip&&~skip-pef&&~skip-nav&&~doc&&~unstable&&~unstable-app&&~deprecated&&~@unstable-app&&~ce"
}
// Configure the PIM
sh "cp behat.ci.yml behat.yml"
sh "cp app/config/parameters.yml.dist app/config/parameters_test.yml"
sh "sed -i \"s#database_host: .*#database_host: mysql#g\" app/config/parameters_test.yml"
if ('ce' == edition) {
sh "printf \" installer_data: 'PimInstallerBundle:minimal'\n\" >> app/config/parameters_test.yml"
} else {
sh "printf \" installer_data: 'PimEnterpriseInstallerBundle:minimal'\n\" >> app/config/parameters_test.yml"
}
// Activate MongoDB if needed
if ('odm' == storage) {
sh "sed -i \"s@// new Doctrine@new Doctrine@g\" app/AppKernel.php"
sh "sed -i \"s@# mongodb_database: .*@mongodb_database: akeneo_pim@g\" app/config/pim_parameters.yml"
sh "sed -i \"s@# mongodb_server: .*@mongodb_server: 'mongodb://mongodb:27017'@g\" app/config/pim_parameters.yml"
sh "printf \" pim_catalog_product_storage_driver: doctrine/mongodb-odm\n\" >> app/config/parameters_test.yml"
}
sh "mkdir -p app/build/logs/behat app/build/logs/consumer app/build/screenshots"
sh "cp behat.ci.yml behat.yml"
try {
sh "php /var/lib/distributed-ci/dci-master/bin/build ${env.WORKSPACE}/behat-${edition}-${storage} ${env.BUILD_NUMBER} ${storage} ${features} ${env.JOB_NAME} 5 ${phpVersion} ${mysqlVersion} \"${tags}\" \"behat-${edition}-${storage}\" -e ${esVersion} --exit_on_failure"
} finally {
sh "sed -i \"s/ name=\\\"/ name=\\\"[${edition}-${storage}] /\" app/build/logs/behat/*.xml"
junit 'app/build/logs/behat/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: 'app/build/screenshots/*.png'
deleteDir()
}
}
}
}
def runPhpCouplingDetectorTest() {
node('docker') {
deleteDir()
try {
docker.image("carcel/php:7.1").inside("-v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") {
unstash "pim_community_dev"
sh "composer remove --dev --no-update doctrine/mongodb-odm-bundle;"
sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist"
sh "./bin/php-coupling-detector detect --config-file=.php_cd.php src"
}
} finally {
sh "docker stop \$(docker ps -a -q) || true"
sh "docker rm \$(docker ps -a -q) || true"
sh "docker volume rm \$(docker volume ls -q) || true"
deleteDir()
}
}
}