@@ -161,7 +161,28 @@ function usage($command)
161161}
162162
163163$ currentVersionBuild = str_replace ('-dev ' , '' , $ currentVersionBuild );
164- $ currentMinorVersion = $ currentVersionBuildParts ['major ' ] . '. ' . $ currentVersionBuildParts ['minor ' ];
164+
165+ if ($ currentVersionBuildParts ['minor ' ] > 0 ) {
166+ if (version_compare ($ currentVersionBuild , $ currentVersionBuildParts ['major ' ] . '. ' . $ currentVersionBuildParts ['minor ' ] . '.0-alpha1 ' , '> ' )) {
167+ // There should be a previous release for that minor version.
168+ $ previousPackageVersion = $ currentVersionBuildParts ['major ' ] . '. ' . $ currentVersionBuildParts ['minor ' ];
169+ } else {
170+ // There is no previous release for that minor version: Check for previous minor version.
171+ $ previousPackageVersion = $ currentVersionBuildParts ['major ' ] . '. ' . ($ currentVersionBuildParts ['minor ' ] - 1 );
172+ }
173+ } elseif (version_compare ($ currentVersionBuild , $ currentVersionBuildParts ['major ' ] . '.0.0-alpha1 ' , '> ' )) {
174+ // There should be a previous release for minor version zero.
175+ $ previousPackageVersion = $ currentVersionBuildParts ['major ' ] . '. ' . $ currentVersionBuildParts ['minor ' ];
176+ } else {
177+ // There is no previous release package for this major version.
178+ $ previousPackageVersion = false ;
179+ }
180+
181+ if (!$ previousPackageVersion && isset ($ options ['relZipUrl ' ])) {
182+ echo PHP_EOL ;
183+ echo 'There cannot be a previous release package for the build version" ' . $ currentVersionBuild . '". The "relZipUrl" parameter will be ignored. ' . PHP_EOL ;
184+ unset($ options ['relZipUrl ' ]);
185+ }
165186
166187// Clone and build previous major version or download from URL
167188if (PREVIOUS_CHECK ) {
@@ -244,7 +265,7 @@ function usage($command)
244265
245266if (isset ($ options ['relZipUrl ' ])) {
246267 $ previousVersionPackageUrl = $ options ['relZipUrl ' ];
247- } else {
268+ } elseif ( $ previousPackageVersion ) {
248269 // Fetch release information from GitHub
249270 echo PHP_EOL ;
250271 echo 'Fetching releases information from GitHub. ' . PHP_EOL ;
@@ -269,7 +290,7 @@ function usage($command)
269290 }
270291
271292 if (
272- version_compare (substr ($ gitHubRelease ->tag_name , 0 , \strlen ($ currentMinorVersion )), $ currentMinorVersion , '= ' )
293+ version_compare (substr ($ gitHubRelease ->tag_name , 0 , \strlen ($ previousPackageVersion )), $ previousPackageVersion , '= ' )
273294 && version_compare ($ gitHubRelease ->tag_name , $ currentVersionBuild , '< ' )
274295 ) {
275296 foreach ($ gitHubRelease ->assets as $ asset ) {
@@ -290,21 +311,23 @@ function usage($command)
290311 }
291312}
292313
293- $ previousVersionPackage = $ packagesPath . '/ ' . basename ($ previousVersionPackageUrl );
314+ if ($ previousPackageVersion ) {
315+ $ previousVersionPackage = $ packagesPath . '/ ' . basename ($ previousVersionPackageUrl );
294316
295- // Download full zip package of latest release before current version if not done before
296- if (!is_file ($ previousVersionPackage )) {
297- echo PHP_EOL ;
298- echo 'Downloading package " ' . $ previousVersionPackageUrl . '". ' . PHP_EOL ;
317+ // Download full zip package of latest release before current version if not done before
318+ if (!is_file ($ previousVersionPackage )) {
319+ echo PHP_EOL ;
320+ echo 'Downloading package " ' . $ previousVersionPackageUrl . '". ' . PHP_EOL ;
299321
300- system ('curl -L -o ' . $ previousVersionPackage . ' ' . $ previousVersionPackageUrl );
301- }
322+ system ('curl -L -o ' . $ previousVersionPackage . ' ' . $ previousVersionPackageUrl );
323+ }
302324
303- if (!is_file ($ previousVersionPackage )) {
304- echo PHP_EOL ;
305- echo 'Error: Could not download package. ' . PHP_EOL ;
325+ if (!is_file ($ previousVersionPackage )) {
326+ echo PHP_EOL ;
327+ echo 'Error: Could not download package. ' . PHP_EOL ;
306328
307- exit (1 );
329+ exit (1 );
330+ }
308331}
309332
310333$ addedFilesFile = __DIR__ . '/added_files.txt ' ;
@@ -333,17 +356,19 @@ function usage($command)
333356 $ renamedFilesRows = [];
334357}
335358
336- echo PHP_EOL ;
337- echo 'Comparing from ". ' . substr ($ previousVersionPackage , \strlen (__DIR__ )) . '" ' . PHP_EOL ;
338- echo ' to ". ' . substr ($ currentVersionPackage , \strlen (__DIR__ )) . '". ' . PHP_EOL ;
359+ if ($ previousPackageVersion ) {
360+ echo PHP_EOL ;
361+ echo 'Comparing from ". ' . substr ($ previousVersionPackage , \strlen (__DIR__ )) . '" ' . PHP_EOL ;
362+ echo ' to ". ' . substr ($ currentVersionPackage , \strlen (__DIR__ )) . '". ' . PHP_EOL ;
339363
340- system ('php ./deleted_file_check.php --from= ' . $ previousVersionPackage . ' --to= ' . $ currentVersionPackage . ' > /dev/null ' );
364+ system ('php ./deleted_file_check.php --from= ' . $ previousVersionPackage . ' --to= ' . $ currentVersionPackage . ' > /dev/null ' );
341365
342- $ addedFiles = array_unique (array_merge ($ addedFiles , file_exists ($ addedFilesFile ) ? explode ("\n" , file_get_contents ($ addedFilesFile )) : []));
343- $ addedFolders = array_unique (array_merge ($ addedFolders , file_exists ($ addedFoldersFile ) ? explode ("\n" , file_get_contents ($ addedFoldersFile )) : []));
344- $ deletedFiles = array_unique (array_merge ($ deletedFiles , file_exists ($ deletedFilesFile ) ? explode ("\n" , file_get_contents ($ deletedFilesFile )) : []));
345- $ deletedFolders = array_unique (array_merge ($ deletedFolders , file_exists ($ deletedFoldersFile ) ? explode ("\n" , file_get_contents ($ deletedFoldersFile )) : []));
346- $ renamedFilesRows = array_unique (array_merge ($ renamedFilesRows , file_exists ($ renamedFilesFile ) ? explode ("\n" , file_get_contents ($ renamedFilesFile )) : []));
366+ $ addedFiles = array_unique (array_merge ($ addedFiles , file_exists ($ addedFilesFile ) ? explode ("\n" , file_get_contents ($ addedFilesFile )) : []));
367+ $ addedFolders = array_unique (array_merge ($ addedFolders , file_exists ($ addedFoldersFile ) ? explode ("\n" , file_get_contents ($ addedFoldersFile )) : []));
368+ $ deletedFiles = array_unique (array_merge ($ deletedFiles , file_exists ($ deletedFilesFile ) ? explode ("\n" , file_get_contents ($ deletedFilesFile )) : []));
369+ $ deletedFolders = array_unique (array_merge ($ deletedFolders , file_exists ($ deletedFoldersFile ) ? explode ("\n" , file_get_contents ($ deletedFoldersFile )) : []));
370+ $ renamedFilesRows = array_unique (array_merge ($ renamedFilesRows , file_exists ($ renamedFilesFile ) ? explode ("\n" , file_get_contents ($ renamedFilesFile )) : []));
371+ }
347372
348373asort ($ deletedFiles );
349374rsort ($ deletedFolders );
0 commit comments