@@ -58,6 +58,26 @@ class RoboFile extends Glpi\Tools\RoboFile {
5858 'save.sql ' ,
5959 ];
6060
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+
6181 protected static $ tagPrefix = 'v ' ;
6282
6383 protected static $ pluginXmlFile = 'plugin.xml ' ;
@@ -205,56 +225,34 @@ public function archiveBuild($release = 'release') {
205225 throw new Exception ("$ version is not semver compliant. See http://semver.org/ " );
206226 }
207227
208- $ tag = self ::$ tagPrefix . $ version ;
228+ if (!$ this ->checkUpgrade ('head ' )) {
229+ throw new Exception ("Bad upgrade code " );
230+ }
231+
209232 if ($ release != 'release ' ) {
233+ // check the release constant
210234 if ($ this ->getIsRelease () === 'true ' ) {
211235 throw new Exception ('The Official release constant must be false ' );
212236 }
213237
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-
242238 $ rev = 'HEAD ' ;
243239 } else {
244240 // 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 ;
249242 if (!$ this ->tagExists ($ tag )) {
250243 throw new Exception ("The tag $ tag does not exists " );
251244 }
252245
253- //check the current head matches the tag
246+ // check the current head matches the tag
254247 if (!$ this ->isTagMatchesCurrentCommit (self ::$ tagPrefix . $ version )) {
255248 throw new Exception ("HEAD is not pointing to the tag of the version to build " );
256249 }
257250
251+ // check the release constant
252+ if ($ this ->getIsRelease () !== 'true ' ) {
253+ throw new Exception ('The Official release constant must be true ' );
254+ }
255+
258256 // check the version is declared in plugin.xml
259257 $ versionTag = $ this ->getVersionTagFromXML ($ version );
260258 if (!is_array ($ versionTag )) {
@@ -264,18 +262,53 @@ public function archiveBuild($release = 'release') {
264262 $ rev = $ tag ;
265263 }
266264
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+
267300 // Build archive
268301 $ pluginName = $ this ->getPluginName ();
269302 $ pluginPath = $ this ->getPluginPath ();
270303 $ 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 " ;
272305 $ this ->taskDeleteDir ($ archiveWorkdir )->run ();
273306 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 ' " );
277310 $ this ->taskPack ($ archiveFile )
278- ->addDir (' /flyvemdm ' , "$ archiveWorkdir/flyvemdm " )
311+ ->addDir (" / $ pluginName " , "$ archiveWorkdir/ $ pluginName " )
279312 ->run ();
280313 }
281314
@@ -367,41 +400,6 @@ protected function getTrackedFiles($version = null) {
367400 return $ output ;
368401 }
369402
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-
405403 /**
406404 * Returns all tags of the GIT repository
407405 *
@@ -493,7 +491,7 @@ protected function getVersionTagFromXML($versionToSearch) {
493491 protected function getCurrentCommitHash () {
494492 exec ('git rev-parse HEAD ' , $ output , $ retCode );
495493 if ($ retCode != '0 ' ) {
496- throw new Exception ("failed to get curent commit hash " );
494+ throw new Exception ("failed to get current commit hash " );
497495 }
498496 return $ output [0 ];
499497 }
@@ -675,11 +673,20 @@ protected function gitDiff(array $files, $version1 = '', $version2 = '') {
675673 /**
676674 */
677675 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 );
679677 if ($ retCode > 0 ) {
680678 throw new Exception ("Failed to update the changelog " );
681679 }
682680
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 ;
684691 }
685692}
0 commit comments