示例#1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || !is_writeable($dir)) {
         $output->writeln("<error>Given directory does not exists or is not writeable</error>");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     $errors = 0;
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use(&$updates, &$errors, $input) {
             list($prefix, $ver) = array_slice($matches, 1);
             try {
                 $semver = new version($ver);
             } catch (\Exception $e) {
                 $errors++;
                 return $prefix . $ver;
             }
             if ($input->getOption("major")) {
                 $semver->inc("major");
             } elseif ($input->getOption("minor")) {
                 $semver->inc("minor");
             } elseif ($input->getOption("patch")) {
                 $semver->inc("patch");
             } else {
                 $semver->inc("patch");
             }
             if (!isset($updates[$ver])) {
                 $updates[$ver] = ["count" => 0, "ver" => $semver->getVersion()];
             }
             $updates[$ver]['count']++;
             return $prefix . $semver->getVersion();
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count['count']} files have been updated from {$update} to {$count['ver']}</info>");
     }
 }
示例#2
0
 /**
  * Process the New Release command.
  *
  * {@inheritDoc}
  *
  * - Update the version.php file
  * - Commit the change and tag it
  *
  * This command assumes you are running it from the root of the repository.
  * Additionally, this command makes changes to the master branch.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Get the version information from the project config.
     $config_vars = $this->getConfigParameter('vars');
     if (array_key_exists('version_file', $config_vars)) {
         $version_file = $config_vars['version_file'];
     } else {
         throw new \Exception("You must have a vars:version_file set up in your project-config.yml. Ex. version_file: ./version.php");
     }
     if (array_key_exists('version_constant', $config_vars)) {
         $version_constant = $config_vars['version_constant'];
     } else {
         throw new \Exception("You must have a vars:version_constant set up in your project-config.yml. Ex. version_constant: MY_PROJECT_VERSION");
     }
     // Determine the new version number.
     $increment = $input->getArgument('increment');
     try {
         // This will succeed when a specific version number is provided (as
         // opposed to "major" or "minor" or "patch"), otherwise an exception will
         // be thrown and the "catch" is used.
         $version = new version($increment);
         $version_number = $version->getVersion();
     } catch (\Exception $e) {
         // Get the current version from the version file if it exists. Otherwise
         // we're starting from scratch.
         if (file_exists($version_file)) {
             include $version_file;
         }
         $current_version = defined($version_constant) ? new version(constant($version_constant)) : new version('0.0.0');
         $version_number = $current_version->inc($increment);
     }
     // Update version file.
     $fs = new Filesystem();
     $fs->dumpFile($version_file, "<?php define('{$version_constant}', '{$version_number}');\n");
     $output->writeln("<info>Successfully updated the {$version_file} file and set the {$version_constant} to {$version_number}</info>");
     // Commit the updated version file.
     $process = new Process('git add ' . $version_file . ' && git commit -m "Preparing for new tag: ' . $version_number . '"');
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     // Tag the commit.
     $process = new Process('git tag ' . $version_number);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
 }
示例#3
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $version = $input->getArgument("version");
     try {
         $semver = new version($version);
     } catch (\Exception $e) {
         $output->writeln("<error>Given version is not valid. Please provide a semver version</error>");
         return;
     }
     $version = $semver->getVersion();
     $dir = $input->getOption("dir");
     $dir = realpath(getcwd() . "/" . ($dir ?: ""));
     if (!is_dir($dir) || is_writeable($dir)) {
         $output->writeln("Given directory does not exists or is not writeable");
         return;
     }
     $fs = new Filesystem(new Adapter($dir));
     $files = $fs->listContents("", true);
     $updates = [];
     foreach ($files as $file) {
         if ($file['type'] === 'dir') {
             continue;
         }
         $content = $fs->read($file['path']);
         $content = preg_replace_callback(static::SEMVER_REGEX, function ($matches) use($version, &$updates) {
             list($prefix, $ver) = array_slice($matches, 1);
             if (!isset($updates[$ver])) {
                 $updates[$ver] = 0;
             }
             $updates[$ver]++;
             return $prefix . $version;
         }, $content);
         $fs->update($file['path'], $content);
     }
     foreach ($updates as $update => $count) {
         $output->writeln("<info>{$count} files have been updated from {$update} to {$version}</info>");
     }
 }
示例#4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $type = $input->getArgument('type');
     //Check the type is valid
     if (!in_array($type, array('major', 'minor', 'patch', 'build'))) {
         $output->writeln('<error>You must specify the release type (major, minor, patch or build)</error>');
     }
     //Fetch the current version from git
     $process = new Process('git describe --tags --abbrev=0');
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Git repository invalid or doesn\'t contain any tags');
         return;
     }
     $oldVersion = new version($process->getOutput());
     //Incriment the new version
     $newVersion = $oldVersion->inc($type);
     //Incriment the version
     $output->writeln('<info>Tagging new version ' . $newVersion->getVersion() . ' from version ' . $oldVersion->getVersion() . '</info>');
     //Tag the version
     $process = new Process('git tag ' . $newVersion->getVersion());
     $process->run();
     if (!$process->isSuccessful()) {
         $output->writeln('<error>Failed to create new tag. Is your source up to date?</error>');
         return;
     }
     //Push the tags
     $output->writeln('<info>Pushing tags to Origin...</info>');
     $process = new Process('git push origin --tags');
     $process->run();
     if ($process->isSuccessful()) {
         $output->writeln('<info>Success!</info>');
     } else {
         $output->writeln('<error>Failed to push new tag to origin!</error>');
     }
 }
示例#5
0
 /**
  * @param array $tags
  * @param bool  $excludeUnstables
  *
  * @return array
  */
 private function sortTags(array $tags, $excludeUnstables = true)
 {
     $return = array();
     // Don't include invalid tags
     foreach ($tags as $tag) {
         try {
             $fixedName = $this->fixupRawTag($tag['name']);
             $v = new version($fixedName);
             if ($v->valid()) {
                 $version = $v->getVersion();
                 if ($excludeUnstables && $this->isNotStable($v)) {
                     continue;
                 }
                 $tag['parsed_version'] = $v;
                 $return[$version] = $tag;
             }
         } catch (\Exception $ex) {
             // Skip
         }
     }
     uasort($return, function ($a, $b) {
         return version::compare($a['parsed_version'], $b['parsed_version']);
     });
     return $return;
 }
示例#6
0
 /**
  * @param  array $tags
  * @return array
  */
 private function sortTags($tags)
 {
     $return = array();
     // Don't include invalid tags
     foreach ($tags as $tag) {
         try {
             $fixedName = $this->fixupRawTag($tag['name']);
             $v = new version($fixedName, true);
             if ($v->valid()) {
                 $tag['parsed_version'] = $v;
                 $return[$v->getVersion()] = $tag;
             }
         } catch (\Exception $ex) {
             // Skip
         }
     }
     uasort($return, function ($a, $b) {
         return version::compare($a['parsed_version'], $b['parsed_version']);
     });
     return $return;
 }
示例#7
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.sync.versions'));
     $tags = $this->github->repositories()->tags($this->setting('owner'), $this->setting('repository'));
     foreach ($tags as $tag) {
         try {
             $version = new version($tag['name']);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     return $versionsToSync;
 }
示例#8
0
 public function getVersionsToSync()
 {
     $versionsToSync = [];
     $remote = $this->client($this->setting('remote'));
     $currentVersions = $this->project->getRefs();
     $allowedVersionRange = new expression($this->setting('sync.constraints.versions'));
     $tags = $remote->getTags($this->setting('repository'), $this->setting('owner'));
     #$this->remote->repositories()->tags();
     $this->fire('git.syncer.versions.start', [$tags]);
     foreach ($tags as $tag => $sha) {
         try {
             $version = new version($tag);
         } catch (SemVerException $e) {
             continue;
         }
         if ($version->satisfies($allowedVersionRange) === false or in_array($version->getVersion(), $currentVersions, true)) {
             continue;
         }
         $versionsToSync[] = $version;
     }
     $this->fire('git.syncer.versions.finish', [$versionsToSync]);
     return $versionsToSync;
 }
示例#9
0
 /**
  * Checks ifa given string is equal to another
  * @param  string|version $v1 The first version
  * @param  string|version $v2 The second version
  * @return boolean
  */
 public static function eq($v1, $v2)
 {
     if (!$v1 instanceof version) {
         $v1 = new version($v1, true);
     }
     if (!$v2 instanceof version) {
         $v2 = new version($v2, true);
     }
     return $v1->getVersion() === $v2->getVersion();
 }