@@ -58,6 +58,26 @@ class RoboFile extends Glpi\Tools\RoboFile {
58
58
'save.sql ' ,
59
59
];
60
60
61
+ protected static $ toArchive = [
62
+ '*.md ' ,
63
+ '*.js ' ,
64
+ '*.php ' ,
65
+ 'composer.* ' ,
66
+ 'package.json ' ,
67
+ 'tools ' ,
68
+ 'scripts ' ,
69
+ 'inc ' ,
70
+ 'pics ' ,
71
+ 'css ' ,
72
+ 'tpl ' ,
73
+ 'locales ' ,
74
+ 'images ' ,
75
+ 'install ' ,
76
+ 'front ' ,
77
+ 'lib ' ,
78
+ 'ajax ' ,
79
+ ];
80
+
61
81
protected static $ tagPrefix = 'v ' ;
62
82
63
83
protected static $ pluginXmlFile = 'plugin.xml ' ;
@@ -205,56 +225,34 @@ public function archiveBuild($release = 'release') {
205
225
throw new Exception ("$ version is not semver compliant. See http://semver.org/ " );
206
226
}
207
227
208
- $ tag = self ::$ tagPrefix . $ version ;
228
+ if (!$ this ->checkUpgrade ('head ' )) {
229
+ throw new Exception ("Bad upgrade code " );
230
+ }
231
+
209
232
if ($ release != 'release ' ) {
233
+ // check the release constant
210
234
if ($ this ->getIsRelease () === 'true ' ) {
211
235
throw new Exception ('The Official release constant must be false ' );
212
236
}
213
237
214
- // update version in package.json
215
- $ this ->sourceUpdatePackageJson ($ version );
216
-
217
- $ this ->updateChangelog ();
218
-
219
- $ diff = $ this ->gitDiff (['package.json ' ]);
220
- $ diff = implode ("\n" , $ diff );
221
- if ($ diff != '' ) {
222
- $ this ->taskGitStack ()
223
- ->stopOnFail ()
224
- ->add ('package.json ' )
225
- ->commit ('docs: bump version package.json ' )
226
- ->run ();
227
- }
228
- $ this ->taskGitStack ()
229
- ->stopOnFail ()
230
- ->add ('CHANGELOG.md ' )
231
- ->commit ('docs(changelog): update changelog ' )
232
- ->run ();
233
-
234
- // Update locales
235
- $ this ->localesGenerate ();
236
- $ this ->taskGitStack ()
237
- ->stopOnFail ()
238
- ->add ('locales/* ' )
239
- ->commit ('docs(locales): update translations ' )
240
- ->run ();
241
-
242
238
$ rev = 'HEAD ' ;
243
239
} else {
244
240
// check a tag exists for the version
245
- if ($ this ->getIsRelease () !== 'true ' ) {
246
- throw new Exception ('The Official release constant must be true ' );
247
- }
248
-
241
+ $ tag = self ::$ tagPrefix . $ version ;
249
242
if (!$ this ->tagExists ($ tag )) {
250
243
throw new Exception ("The tag $ tag does not exists " );
251
244
}
252
245
253
- //check the current head matches the tag
246
+ // check the current head matches the tag
254
247
if (!$ this ->isTagMatchesCurrentCommit (self ::$ tagPrefix . $ version )) {
255
248
throw new Exception ("HEAD is not pointing to the tag of the version to build " );
256
249
}
257
250
251
+ // check the release constant
252
+ if ($ this ->getIsRelease () !== 'true ' ) {
253
+ throw new Exception ('The Official release constant must be true ' );
254
+ }
255
+
258
256
// check the version is declared in plugin.xml
259
257
$ versionTag = $ this ->getVersionTagFromXML ($ version );
260
258
if (!is_array ($ versionTag )) {
@@ -264,18 +262,53 @@ public function archiveBuild($release = 'release') {
264
262
$ rev = $ tag ;
265
263
}
266
264
265
+ // Update locales
266
+ $ this ->localesGenerate ();
267
+
268
+ if ($ release == 'release ' ) {
269
+
270
+ // commit locales update
271
+ $ this ->taskGitStack ()
272
+ ->stopOnFail ()
273
+ ->add ('locales/*.po ' )
274
+ ->add ('locales/*.mo ' )
275
+ ->add ("locales/ $ pluginName.pot " )
276
+ ->commit ('docs(locales): update translations ' )
277
+ ->run ();
278
+
279
+ // bump version in package.json
280
+ $ this ->sourceUpdatePackageJson ($ version );
281
+
282
+ // updte changelog
283
+ $ this ->updateChangelog ();
284
+ $ diff = $ this ->gitDiff (['package.json ' ]);
285
+ $ diff = implode ("\n" , $ diff );
286
+ if ($ diff != '' ) {
287
+ $ this ->taskGitStack ()
288
+ ->stopOnFail ()
289
+ ->add ('package.json ' )
290
+ ->commit ('docs: bump version package.json ' )
291
+ ->run ();
292
+ }
293
+ $ this ->taskGitStack ()
294
+ ->stopOnFail ()
295
+ ->add ('CHANGELOG.md ' )
296
+ ->commit ('docs(changelog): update changelog ' )
297
+ ->run ();
298
+ }
299
+
267
300
// Build archive
268
301
$ pluginName = $ this ->getPluginName ();
269
302
$ pluginPath = $ this ->getPluginPath ();
270
303
$ archiveWorkdir = "$ pluginPath/output/dist/archive_workdir " ;
271
- $ archiveFile = "$ pluginPath/output/dist/glpi- " . $ this -> getPluginName () . " - $ version.tar.bz2 " ;
304
+ $ archiveFile = "$ pluginPath/output/dist/glpi- $ pluginName - $ version.tar.bz2 " ;
272
305
$ this ->taskDeleteDir ($ archiveWorkdir )->run ();
273
306
mkdir ($ archiveWorkdir , 0777 , true );
274
- $ filesToArchive = implode (' ' , $ this -> getFileToArchive ( $ rev ) );
275
- $ this ->_exec ("git archive --prefix= $ pluginName/ $ rev $ filesToArchive | tar x -C ' $ archiveWorkdir' " );
276
- $ this ->_exec ("composer install --no-dev --working-dir=' $ archiveWorkdir/flyvemdm ' " );
307
+ $ filesToArchive = implode (' ' , static :: $ toArchive );
308
+ $ this ->_exec ("git archive --prefix= $ pluginName/ $ rev $ filesToArchive | tar x -C ' $ archiveWorkdir' " );
309
+ $ this ->_exec ("composer install --no-dev --working-dir=' $ archiveWorkdir/ $ pluginName ' " );
277
310
$ this ->taskPack ($ archiveFile )
278
- ->addDir (' /flyvemdm ' , "$ archiveWorkdir/flyvemdm " )
311
+ ->addDir (" / $ pluginName " , "$ archiveWorkdir/ $ pluginName " )
279
312
->run ();
280
313
}
281
314
@@ -367,41 +400,6 @@ protected function getTrackedFiles($version = null) {
367
400
return $ output ;
368
401
}
369
402
370
- /**
371
- * Enumerates all files to save in the distribution archive
372
- *
373
- * @param $version
374
- * @return array
375
- */
376
- protected function getFileToArchive ($ version ) {
377
- $ filesToArchive = $ this ->getTrackedFiles ($ version );
378
-
379
- // prepare banned items for regex
380
- $ patterns = [];
381
- foreach ($ this ->getBannedFiles () as $ bannedItem ) {
382
- $ pattern = "# " . preg_quote ("$ bannedItem " , "# " ) . "# " ;
383
- $ pattern = str_replace ("\\? " , ". " , $ pattern );
384
- $ pattern = str_replace ("\\* " , ".* " , $ pattern );
385
- $ patterns [] = $ pattern ;
386
- }
387
-
388
- // remove banned files from the list
389
- foreach ($ patterns as $ pattern ) {
390
- $ filteredFiles = [];
391
- foreach ($ filesToArchive as $ file ) {
392
- if (preg_match ($ pattern , $ file ) == 0 ) {
393
- //Include the tracked file
394
- $ filteredFiles [] = $ file ;
395
- }
396
- }
397
-
398
- // Repeat filtering from result with next banned files pattern
399
- $ filesToArchive = $ filteredFiles ;
400
- }
401
-
402
- return $ filesToArchive ;
403
- }
404
-
405
403
/**
406
404
* Returns all tags of the GIT repository
407
405
*
@@ -493,7 +491,7 @@ protected function getVersionTagFromXML($versionToSearch) {
493
491
protected function getCurrentCommitHash () {
494
492
exec ('git rev-parse HEAD ' , $ output , $ retCode );
495
493
if ($ retCode != '0 ' ) {
496
- throw new Exception ("failed to get curent commit hash " );
494
+ throw new Exception ("failed to get current commit hash " );
497
495
}
498
496
return $ output [0 ];
499
497
}
@@ -675,11 +673,20 @@ protected function gitDiff(array $files, $version1 = '', $version2 = '') {
675
673
/**
676
674
*/
677
675
protected function updateChangelog () {
678
- exec ("node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s " , $ output , $ retCode );
676
+ exec ("node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s " , $ output , $ retCode );
679
677
if ($ retCode > 0 ) {
680
678
throw new Exception ("Failed to update the changelog " );
681
679
}
682
680
683
- return true ;
681
+ return true ;
682
+ }
683
+
684
+ private function checkUpgrade ($ rev ) {
685
+ $ fileContent = $ this ->getFileFromGit ('install/upgrade_to_develop.php ' , $ rev );
686
+ if ($ fileContent != '' ) {
687
+ throw new Exception ('upgrade_to_develop.php must be renamed ! ' );
688
+ return false ;
689
+ }
690
+ return true ;
684
691
}
685
692
}
0 commit comments