diff --git a/bin/tag.php b/bin/tag.php index 6db510331..1e11d0ebd 100755 --- a/bin/tag.php +++ b/bin/tag.php @@ -2,9 +2,9 @@ normalize($tag); + if ($versionParser::parseStability($version) === 'stable') { + return true; + } + } catch (Throwable) { + // ignore + } + return false; +} + (new SingleCommandApplication()) ->setName('Tag me') ->setCode(code: function (InputInterface $input, OutputInterface $output): int { @@ -46,31 +60,38 @@ function runCmd($commandLine, $cwd): string $package = $helper->ask($input, $output, $question); $output->writeln(sprintf('You have just selected: "%s"', basename($package))); - $tagPrefix = sprintf("%s/%s-", basename($package), $branch); + $packagePrefix = basename($package) . '/'; + $tags = runCmd(sprintf( + 'git tag --sort=refname -l \'%s*\'', + $packagePrefix + ), + $cwd + ); + $tags = explode(PHP_EOL, $tags); + $tags = array_map(fn($i) => str_replace($packagePrefix, '', $i), $tags); + $tags = array_filter($tags, fn($i) => isValidStableSemver($i)); + $tags = Semver::rsort($tags); + $latest = '1'; + if ($tags !== []) { + $latest = $tags[0]; + } + $tagSuffix = '-dev'; + $tagPrefix = sprintf("%s/%s-%s-", basename($package), $latest, $branch); $tags = runCmd(sprintf('git tag --sort=refname -l \'%s*\'', $tagPrefix), $cwd); $tags = explode(PHP_EOL, $tags); $lastNumericTagId = 0; if ($tags !== []) { foreach ($tags as $tag) { - $tagId = str_replace($tagPrefix, '', $tag); + $tagId = str_replace([$tagPrefix, $tagSuffix], '', $tag); if (is_numeric($tagId)) { $lastNumericTagId = (int) $tagId; } } } $newTagId = $lastNumericTagId + 1; - $question = new Question( - sprintf( - 'Add tag suffix "%s{suffix}" manually or ignore this by pressing which will set "%s"', - $tagPrefix, - $tagPrefix . $newTagId - ), - $newTagId - ); - $suffix = $helper->ask($input, $output, $question); - $newTag = $tagPrefix . $suffix; + $newTag = $tagPrefix . $newTagId . $tagSuffix; $output->writeln(sprintf('New tag will be "%s"', $newTag)); diff --git a/composer.json b/composer.json index cbe01f372..6e913371d 100755 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "php": "^8.1", "symfony/console": "^5.2|^6", "symfony/filesystem": "^5.2|^6", - "symfony/process": "^4.4|^5.0|^6.0" + "symfony/process": "^4.4|^5.0|^6.0", + "composer/semver": "^3.4" }, "require-dev": { "keboola/coding-standard": "^14",