|
1 | 1 | #!groovy |
2 | 2 |
|
3 | | -import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateAction |
4 | | - |
5 | | -def phpVersion = "7.1" |
6 | | -def mysqlVersion = "5.7" |
7 | | -def launchUnitTests = "yes" |
8 | | -def launchIntegrationTests = "yes" |
9 | | -def launchBehatTests = "yes" |
10 | | - |
11 | | -class Globals { |
12 | | - static pimVersion = "2.0" |
13 | | - static extensionBranch = "dev-master" |
| 3 | +milestone 1 |
| 4 | +if (env.BRANCH_NAME =~ /^PR-/) { |
| 5 | + input 'Launch tests?' |
14 | 6 | } |
15 | | - |
16 | | -stage("Checkout") { |
17 | | - milestone 1 |
18 | | - if (env.BRANCH_NAME =~ /^PR-/) { |
19 | | - userInput = input(message: 'Launch tests?', parameters: [ |
20 | | - choice(choices: 'yes\nno', description: 'Run unit tests', name: 'launchUnitTests'), |
21 | | - choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'), |
22 | | - ]) |
23 | | - |
24 | | - launchUnitTests = userInput['launchUnitTests'] |
25 | | - launchIntegrationTests = userInput['launchIntegrationTests'] |
26 | | - } |
27 | | - milestone 2 |
28 | | - |
29 | | - podPHP(phpVersion, { |
30 | | - |
31 | | - checkout scm |
32 | | - stash "excel_init" |
33 | | - |
34 | | - checkout([$class: 'GitSCM', |
35 | | - branches: [[name: "${Globals.pimVersion}"]], |
36 | | - userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/akeneo/pim-community-standard.git']] |
37 | | - ]) |
38 | | - stash "pim_community" |
39 | | - |
40 | | - checkout([$class: 'GitSCM', |
41 | | - branches: [[name: "${Globals.pimVersion}"]], |
| 7 | +milestone 2 |
| 8 | + |
| 9 | +stage("Tests") { |
| 10 | + withCredentials([string(credentialsId: 'composer-token', variable: 'token')]) { |
| 11 | + podTemplate(label: 'excel-init-ee', containers: [ |
| 12 | + containerTemplate( |
| 13 | + name: "elasticsearch", |
| 14 | + image: "elasticsearch:5.5", |
| 15 | + resourceRequestCpu: '100m', |
| 16 | + resourceRequestMemory: '200Mi', |
| 17 | + envVars: [ |
| 18 | + envVar(key: "ES_JAVA_OPTS", value: "-Xms512m -Xmx512m"), |
| 19 | + envVar(key: "FORCE", value: "true"), |
| 20 | + ] |
| 21 | + ), |
| 22 | + containerTemplate( |
| 23 | + name: "mysql", |
| 24 | + image: "mysql:5.7", |
| 25 | + resourceRequestCpu: '100m', |
| 26 | + resourceRequestMemory: '200Mi', |
| 27 | + envVars: [ |
| 28 | + envVar(key: "MYSQL_ROOT_PASSWORD", value: "root"), |
| 29 | + envVar(key: "MYSQL_USER", value: "akeneo_pim"), |
| 30 | + envVar(key: "MYSQL_PASSWORD", value: "akeneo_pim"), |
| 31 | + envVar(key: "MYSQL_DATABASE", value: "akeneo_pim"), |
| 32 | + ], volumes: [ |
| 33 | + emptyDirVolume(memory: true, mountPath: "/var/lib/mysql"), |
| 34 | + emptyDirVolume(memory: true, mountPath: "/tmp") |
| 35 | + ] |
| 36 | + ), |
| 37 | + containerTemplate( |
| 38 | + name: "php", |
| 39 | + ttyEnabled: true, |
| 40 | + command: 'cat', |
| 41 | + image: "akeneo/php:7.1", |
| 42 | + resourceRequestCpu: '100m', |
| 43 | + resourceRequestMemory: '1000Mi', |
| 44 | + envVars: [ |
| 45 | + envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}") |
| 46 | + ] |
| 47 | + ), |
| 48 | + ]) { |
| 49 | + node('excel-init-ee') { |
| 50 | + container("php") { |
| 51 | + checkout([$class: 'GitSCM', |
| 52 | + branches: [[name: "2.1"]], |
42 | 53 | userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/akeneo/pim-enterprise-standard.git']] |
43 | | - ]) |
44 | | - sh "chmod -R 777 ${env.WORKSPACE}" |
45 | | - stash "pim_enterprise" |
46 | | - }) |
47 | | -} |
48 | | - |
49 | | -if (launchUnitTests.equals("yes")) { |
50 | | - stage("Unit tests") { |
51 | | - def tasks = [:] |
52 | | - |
53 | | - tasks["phpspec-7.1"] = {runPhpSpecTest(phpVersion)} |
54 | | - tasks["php-cs-fixer-7.1"] = {runPhpCsFixerTest(phpVersion)} |
55 | | - |
56 | | - parallel tasks |
57 | | - } |
58 | | -} |
59 | | - |
60 | | -if (launchIntegrationTests.equals("yes")) { |
61 | | - stage("Integration tests") { |
62 | | - def tasks = [:] |
63 | | - |
64 | | - tasks["phpunit-7.1-ce"] = {runIntegrationTest(phpVersion)} |
65 | | - tasks["phpunit-7.1-ee"] = {runIntegrationTestEE(phpVersion)} |
66 | | - |
67 | | - parallel tasks |
68 | | - } |
69 | | -} |
70 | | - |
71 | | -def runPhpSpecTest(version) { |
72 | | - podPHP(version, { |
73 | | - |
74 | | - try { |
75 | | - unstash "excel_init" |
76 | | - |
77 | | - sh "composer install --optimize-autoloader --no-interaction --no-progress --prefer-dist" |
78 | | - sh "mkdir -p app/build/logs/" |
79 | | - sh "./bin/phpspec run --no-interaction --format=junit > app/build/logs/phpspec.xml" |
80 | | - } finally { |
81 | | - sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${version}] /\" app/build/logs/*.xml" |
82 | | - junit "app/build/logs/*.xml" |
83 | | - |
84 | | - } |
85 | | - }) |
86 | | -} |
87 | | - |
88 | | -def runPhpCsFixerTest(version) { |
89 | | - podPHP(version, { |
90 | | - |
91 | | - try { |
92 | | - unstash "excel_init" |
93 | | - |
94 | | - sh "composer install --optimize-autoloader --no-interaction --no-progress --prefer-dist" |
95 | | - sh "mkdir -p app/build/logs/" |
96 | | - sh "./bin/php-cs-fixer fix --diff --format=junit --config=.php_cs.php > app/build/logs/phpcs.xml" |
97 | | - } finally { |
98 | | - sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${version}] /\" app/build/logs/*.xml" |
99 | | - junit "app/build/logs/*.xml" |
100 | | - } |
101 | | - }) |
102 | | -} |
103 | | - |
104 | | -def runIntegrationTest(version) { |
105 | | - podIntegration(version, { |
106 | | - unstash "pim_community" |
107 | | - |
108 | | - sh "composer require --no-update phpunit/phpunit akeneo/excel-init-bundle:${Globals.extensionBranch}" |
109 | | - sh "composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist" |
110 | | - sh "chmod -R 777 ${env.WORKSPACE}" |
111 | | - sh "bin/console assets:install" |
112 | | - sh "bin/console pim:installer:dump-require-paths" |
113 | | - |
114 | | - dir("vendor/akeneo/excel-init-bundle") { |
115 | | - |
116 | | - unstash "excel_init" |
117 | | - } |
118 | | - sh "composer dump-autoload -o" |
119 | | - |
120 | | - sh "cp app/config/parameters.yml.dist app/config/parameters_test.yml" |
121 | | - sh "sed -i 's/database_host:.*/database_host: 127.0.0.1/' app/config/parameters_test.yml" |
122 | | - sh "echo '' >> app/config/parameters_test.yml" |
123 | | - sh "echo ' pim_installer.fixture_loader.job_loader.config_file: PimExcelInitBundle/Resources/config/fixtures_jobs.yml' >> app/config/parameters_test.yml" |
124 | | - sh "echo ' installer_data: PimExcelInitBundle:minimal' >> app/config/parameters_test.yml" |
125 | | - sh "sed -i \"s#index_hosts: .*#index_hosts: '127.0.0.1:9200'#g\" app/config/parameters_test.yml" |
126 | | - sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExcelInitBundle\\\\PimExcelInitBundle(),#' app/AppKernel.php" |
127 | | - |
128 | | - sh "sleep 10" |
129 | | - |
130 | | - sh "./bin/console --env=test pim:install --force" |
131 | | - }) |
132 | | -} |
133 | | - |
134 | | -def runIntegrationTestEE(version) { |
135 | | - podIntegration(version, { |
136 | | - unstash "pim_enterprise" |
137 | | - |
138 | | - sh "composer require --no-update phpunit/phpunit akeneo/excel-init-bundle:${Globals.extensionBranch}" |
139 | | - sh "composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist" |
140 | | - sh "chmod -R 777 ${env.WORKSPACE}" |
141 | | - sh "bin/console assets:install" |
142 | | - sh "bin/console pim:installer:dump-require-paths" |
143 | | - |
144 | | - dir("vendor/akeneo/excel-init-bundle") { |
145 | | - unstash "excel_init" |
146 | | - } |
147 | | - sh "composer dump-autoload -o" |
148 | | - |
149 | | - sh "cp app/config/parameters.yml.dist app/config/parameters_test.yml" |
150 | | - sh "sed -i 's/database_host:.*/database_host: 127.0.0.1/' app/config/parameters_test.yml" |
151 | | - sh "echo '' >> app/config/parameters_test.yml" |
152 | | - sh "echo ' pim_installer.fixture_loader.job_loader.config_file: PimExcelInitBundle/Resources/config/fixtures_jobs_ee.yml' >> app/config/parameters_test.yml" |
153 | | - sh "echo ' installer_data: PimExcelInitBundle:minimal_EE' >> app/config/parameters_test.yml" |
154 | | - sh "sed -i \"s#index_hosts: .*#index_hosts: '127.0.0.1:9200'#g\" app/config/parameters_test.yml" |
155 | | - sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExcelInitBundle\\\\PimExcelInitBundle(),#' app/AppKernel.php" |
156 | | - |
157 | | - sh "sleep 10" |
158 | | - sh "./bin/console --env=test pim:install --force" |
159 | | - }) |
160 | | -} |
161 | | - |
162 | | -def podPHP(phpVersion, body) { |
163 | | - def podName = "ExcelInitBundle-" + UUID.randomUUID().toString() |
164 | | - withCredentials([string(credentialsId: 'composer-token', variable: 'token')]) { |
165 | | - podTemplate(label: podName, containers: [ |
166 | | - containerTemplate(name: "php", ttyEnabled: true, command: 'cat', image: "akeneo/php:${phpVersion}", resourceRequestCpu: '100m', resourceRequestMemory: '1000Mi', |
167 | | - envVars: [ |
168 | | - envVar(key: "COMPOSER_HOME", value: "${env.WORKSPACE}/.composer"), |
169 | | - envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}") |
170 | | - ] |
171 | | - ), |
172 | | - ]) { |
173 | | - node(podName) { |
174 | | - container("php") { |
175 | | - body() |
176 | | - } |
177 | | - } |
178 | | - } |
179 | | - } |
180 | | -} |
181 | | - |
182 | | - |
183 | | -def podIntegration(phpVersion, body) { |
184 | | - def podName = "ExcelInitBundle-" + UUID.randomUUID().toString() |
185 | | - withCredentials([string(credentialsId: 'composer-token', variable: 'token')]) { |
186 | | - podTemplate(label: podName, containers: [ |
187 | | - containerTemplate(name: "elasticsearch", image: "elasticsearch:5.5", resourceRequestCpu: '100m', resourceRequestMemory: '200Mi', |
188 | | - envVars: [ |
189 | | - envVar(key: "ES_JAVA_OPTS", value: "-Xms256m -Xmx256m"), |
190 | | - envVar(key: "FORCE", value: "true"), |
191 | | - ] |
192 | | - ), |
193 | | - containerTemplate(name: "mysql", image: "mysql:5.7", resourceRequestCpu: '100m', resourceRequestMemory: '200Mi', |
194 | | - envVars: [ |
195 | | - envVar(key: "MYSQL_ROOT_PASSWORD", value: "root"), |
196 | | - envVar(key: "MYSQL_USER", value: "akeneo_pim"), |
197 | | - envVar(key: "MYSQL_PASSWORD", value: "akeneo_pim"), |
198 | | - envVar(key: "MYSQL_DATABASE", value: "akeneo_pim"), |
199 | | - ], volumes: [ |
200 | | - |
201 | | - emptyDirVolume(memory: false, mountPath: "/var/lib/mysql"), |
202 | | - emptyDirVolume(memory: false, mountPath: "/tmp") |
203 | | - ] |
204 | | - |
205 | | - ), |
206 | | - containerTemplate(name: "php", ttyEnabled: true, command: 'cat', image: "akeneo/php:${phpVersion}", resourceRequestCpu: '100m', resourceRequestMemory: '1000Mi', |
207 | | - envVars: [ |
208 | | - envVar(key: "COMPOSER_HOME", value: "${env.WORKSPACE}/.composer"), |
209 | | - envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}") |
210 | | - ] |
211 | | - ), |
212 | | - ]) { |
213 | | - node(podName) { |
214 | | - container("php") { |
215 | | - sh "chmod -R 777 /tmp" |
216 | | - body() |
217 | | - } |
218 | | - } |
| 54 | + ]) |
| 55 | + |
| 56 | + sh """ |
| 57 | + php -d memory_limit=3G /usr/local/bin/composer require phpunit/phpunit akeneo/excel-init-bundle:dev-master --no-interaction --no-progress --prefer-dist |
| 58 | + chmod -R 777 vendor |
| 59 | + """ |
| 60 | + |
| 61 | + dir("vendor/akeneo/excel-init-bundle") { |
| 62 | + deleteDir() |
| 63 | + checkout scm |
| 64 | + } |
| 65 | + |
| 66 | + sh """ |
| 67 | + composer dump-autoload -o |
| 68 | + rm var/cache/* -rf |
| 69 | + cp vendor/akeneo/excel-init-bundle/.ci/config/parameters_test.yml app/config/parameters_test.yml |
| 70 | + sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExcelInitBundle\\\\PimExcelInitBundle(),#' app/AppKernel.php |
| 71 | + sleep 10 |
| 72 | + """ |
| 73 | + |
| 74 | + sh "bin/console pim:install --force --env=test" |
219 | 75 | } |
| 76 | + } |
220 | 77 | } |
221 | | -} |
222 | | - |
223 | | - |
224 | | -@NonCPS |
225 | | -def clearTemplateNames() { |
226 | | - // see https://issues.jenkins-ci.org/browse/JENKINS-42184 |
227 | | - currentBuild.rawBuild.getAction( PodTemplateAction.class )?.stack?.clear() |
| 78 | + } |
228 | 79 | } |
0 commit comments