Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function run(OutputInterface $output)
 {
     $baseBranch = $this->getParameter('base_branch');
     $release = $this->getParameter('release');
     $this->runGit($output, ['git', 'checkout', $baseBranch]);
     $lastTag = $this->runCommand(['git', 'describe', '--tags', '--abbrev=0', 'HEAD']);
     $builder = Parser::toBuilder($lastTag);
     switch (true) {
         case 'major' === $release:
             $builder->incrementMajor();
             break;
         case 'minor' === $release:
             $builder->incrementMinor();
             break;
         case 'patch' === $release:
             $builder->incrementPatch();
             break;
         default:
             $builder->incrementPatch();
             break;
     }
     $newNumber = Dumper::toString($builder->getVersion());
     $this->runGit($output, ['git', 'tag', '-a', $newNumber, '-m', 'auto tagged']);
     $this->runGit($output, ['git', 'push', '--tags']);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pr = $this->getAdapter()->getPullRequest($input->getArgument('pr_number'));
     $sourceOrg = $pr['head']['user'];
     $branchName = $pr['head']['ref'];
     /** @var GitConfigHelper $gitConfigHelper */
     $gitConfigHelper = $this->getHelper('git_config');
     $gitConfigHelper->ensureRemoteExists($sourceOrg, $pr['head']['repo']);
     /** @var GitHelper $gitHelper */
     $gitHelper = $this->getHelper('git');
     $gitHelper->remoteUpdate($sourceOrg);
     $lastTag = $gitHelper->getLastTagOnBranch($sourceOrg . '/' . $branchName);
     if (empty($lastTag)) {
         $lastTag = '0.0.0';
     }
     // adjust case for format v2.3
     $lastTag = ltrim($lastTag, 'v');
     $builder = Parser::toBuilder($lastTag);
     switch (true) {
         case $input->getOption('major'):
             $builder->incrementMajor();
             break;
         case $input->getOption('minor'):
             $builder->incrementMinor();
             break;
         case $input->getOption('patch'):
             $builder->incrementPatch();
             break;
         default:
             $builder->incrementPatch();
             break;
     }
     $output->writeln(Dumper::toString($builder->getVersion()));
     return self::COMMAND_SUCCESS;
 }
Exemplo n.º 3
0
 protected function setUp()
 {
     $this->v1 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Parser::toVersion('1.2.3'));
     $this->v1p = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Parser::toVersion('2.0.0-alpha.2'));
     $this->v2 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Parser::toVersion('4.5.6'));
     $this->manifest = new Manifest(array($this->v1, $this->v1p, $this->v2));
 }
Exemplo n.º 4
0
 public function testToVersion()
 {
     $version = Parser::toVersion('1.2.3-pre.1+build.1');
     $this->assertSame(1, $version->getMajor());
     $this->assertSame(2, $version->getMinor());
     $this->assertSame(3, $version->getPatch());
     $this->assertSame(array('pre', '1'), $version->getPreRelease());
     $this->assertSame(array('build', '1'), $version->getBuild());
 }
Exemplo n.º 5
0
 /**
  * Initialize the version.
  *
  * If the version is not given, a 0.0.0 version is assumed.
  *
  * @param string The version.
  */
 public function __construct($version = null)
 {
     $this->_versionString = $version ?: 'v0.0.0';
     try {
         $this->_version = VersionParser::toVersion(ltrim($this->_versionString, 'v'));
         $this->_isSemantic = true;
     } catch (InvalidStringRepresentationException $e) {
         $this->_isSemantic = false;
     }
 }
 /**
  * @throws \RuntimeException
  * @return Version
  */
 public function getVersion()
 {
     $semVersionRegex = substr(Validator::VERSION_REGEX, 2, -2);
     $describeRegex = sprintf(self::DESCRIBE_REGEX, $semVersionRegex);
     $version = $this->getGitDescribe();
     if (!preg_match($describeRegex, $version, $matches)) {
         throw new \RuntimeException($this->getName() . " describe returned no valid version");
     }
     $builder = Parser::toBuilder($matches[1]);
     $this->handleMetaData($builder, $matches);
     return $builder->getVersion();
 }
Exemplo n.º 7
0
 /**
  * Updates the running Phar if any is available.
  *
  * @param string|Version $version  The current version.
  * @param boolean        $major    Lock to current major version?
  * @param boolean        $pre      Allow pre-releases?
  *
  * @return boolean TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false)
 {
     if (false === $version instanceof Version) {
         $version = Parser::toVersion($version);
     }
     if (null !== ($update = $this->manifest->findRecent($version, $major, $pre))) {
         $update->getFile();
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manifest = Manifest::loadFile(self::MANIFEST_FILE);
     $currentVersion = Parser::toVersion($this->getApplication()->getVersion());
     $update = $manifest->findRecent($currentVersion, true);
     if (false === $update instanceof Update) {
         $output->writeln(sprintf('You are already using the latest version: <info>%s</info>', $currentVersion));
         return 0;
     }
     $output->writeln(sprintf('Updating to version <info>%s</info>', $update->getVersion()));
     $manager = new Manager($manifest);
     $manager->update($this->getApplication()->getVersion(), true);
     $output->writeln(sprintf('SHA1 verified <info>%s</info>', $update->getSha1()));
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getReleases()
 {
     $response = $this->client->apiRepository()->tags($this->getUsername(), $this->getRepository());
     $resultArray = json_decode($response->getContent(), true);
     $releases = [];
     foreach ($resultArray as $name => $release) {
         $version = ltrim($name, 'v');
         $releases[] = ['url' => sprintf('%s/%s/%s/commits/tag/%s', $this->domain, $this->getUsername(), $this->getRepository(), $name), 'id' => null, 'name' => $name, 'tag_name' => $name, 'body' => $release['message'], 'draft' => false, 'prerelease' => VersionValidator::isVersion($version) && !Parser::toVersion($version)->isStable(), 'created_at' => new \DateTime($release['utctimestamp']), 'updated_at' => null, 'published_at' => new \DateTime($release['utctimestamp']), 'user' => $release['author']];
     }
     return $releases;
 }
Exemplo n.º 10
0
 /**
  * @param string  $currentVersion
  * @param Manager $manager
  * @param bool    $lockMajor
  * @param bool    $allowPreRelease
  *
  * @return string
  */
 private function getNewVersion($currentVersion, Manager $manager, $lockMajor = false, $allowPreRelease = false)
 {
     $newVersionObject = $manager->getManifest()->findRecent(Parser::toVersion($currentVersion), $lockMajor, $allowPreRelease)->getVersion();
     $newVersion = sprintf('%s.%s', $newVersionObject->getMajor(), implode('.', array_filter([$newVersionObject->getMinor(), $newVersionObject->getPatch()])));
     return $newVersion;
 }
Exemplo n.º 11
0
 /**
  * Will init the instance of our core class
  *
  * @return null
  */
 protected function init()
 {
     $this->baseVersion = Parser::toBuilder('1.0.0');
     $this->inspector = new DefaultInspector();
     $this->cache = new Cache();
 }
Exemplo n.º 12
0
 /**
  * Imports the version string representation.
  *
  * @param string $version The string representation.
  *
  * @return Builder The Version builder.
  */
 public function importString($version)
 {
     return $this->importComponents(Parser::toComponents($version));
 }
Exemplo n.º 13
0
 if (!defined('HHVM_VERSION') && !extension_loaded('apcu') && extension_loaded('apc')) {
     check('The "apc.enable_cli" setting is off.', 'Notice: The "apc.enable_cli" is on and may cause problems with Phars.', function () {
         return false == ini_get('apc.enable_cli');
     }, false);
 }
 echo "{$n}Everything seems good!{$n}{$n}";
 echo "Download{$n}";
 echo "--------{$n}{$n}";
 // Retrieve manifest
 echo " - Downloading manifest...{$n}";
 $manifest = file_get_contents('http://box-project.github.io/box2/manifest.json');
 echo " - Reading manifest...{$n}";
 $manifest = json_decode($manifest);
 $current = null;
 foreach ($manifest as $item) {
     $item->version = Parser::toVersion($item->version);
     if ($current && Comparator::isGreaterThan($item->version, $current->version)) {
         $current = $item;
     }
 }
 if (!$item) {
     echo " x No application download was found.{$n}";
 }
 echo " - Downloading Box v", Dumper::toString($item->version), "...{$n}";
 file_put_contents($item->name, file_get_contents($item->url));
 echo " - Checking file checksum...{$n}";
 if ($item->sha1 !== sha1_file($item->name)) {
     unlink($item->name);
     echo " x The download was corrupted.{$n}";
 }
 echo " - Checking if valid Phar...{$n}";
Exemplo n.º 14
0
 /**
  * Increment the patch version
  *
  * @param string $version
  * @return string
  */
 private function incrementVersion($version)
 {
     $builder = Version\Parser::toBuilder($version);
     $builder->incrementPatch();
     return Version\Dumper::toString($builder->getVersion());
 }
Exemplo n.º 15
0
 /**
  * Validates the data, processes it, and returns a new instance of Manifest.
  *
  * @param array $decoded The decoded JSON data.
  * @param Json  $json    The Json instance used to decode the data.
  *
  * @return Manifest The new instance.
  */
 private static function create($decoded, Json $json)
 {
     $json->validate($json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA), $decoded);
     $updates = array();
     foreach ($decoded as $update) {
         $updates[] = new Update($update->name, $update->sha1, $update->url, Parser::toVersion($update->version), isset($update->publicKey) ? $update->publicKey : null);
     }
     usort($updates, function (Update $a, Update $b) {
         return Comparator::isGreaterThan($a->getVersion(), $b->getVersion());
     });
     return new static($updates);
 }
Exemplo n.º 16
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $kernelRoot = $this->getContainer()->getParameter('kernel.root_dir');
     $file = $this->getContainer()->getParameter('shivas_versioning.version_file');
     $param = $this->getContainer()->getParameter('shivas_versioning.version_parameter');
     $paramFile = "{$kernelRoot}/config/{$file}";
     /** @var VersionsManager $manager */
     $manager = $this->getContainer()->get('shivas_versioning.manager');
     if ($input->getOption('list-handlers')) {
         $this->listHandlers($manager, $output);
         return;
     }
     if ($input->getArgument('version') === null) {
         $version = $manager->getVersion();
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
             $output->writeln(sprintf('Handler: <comment>%s</comment>', $manager->getActiveHandler()->getName()));
         }
         $builder = VersionParser::toBuilder(Dumper::toString($version));
         if ($input->getOption('major') > 0) {
             $builder->incrementMajor(intval($input->getOption('major')));
         }
         if ($input->getOption('minor') > 0) {
             $builder->incrementMinor(intval($input->getOption('minor')));
         }
         if ($input->getOption('patch') > 0) {
             $builder->incrementPatch(intval($input->getOption('patch')));
         }
         if ($input->getOption('prerelease')) {
             $preRelease = $input->getOption('prerelease');
             if (in_array(null, $preRelease)) {
                 $preRelease = array();
             }
             $builder->setPreRelease($preRelease);
         }
         if ($input->getOption('build')) {
             $build = $input->getOption('build');
             if (in_array(null, $build)) {
                 $build = array();
             }
             $builder->setBuild($build);
         }
         $version = $builder->getVersion();
     } else {
         $version = VersionParser::toVersion($input->getArgument('version'));
     }
     if (!$input->getOption('dry-run')) {
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $output->writeln(sprintf('Updating parameters file with version number: <info>%s</info>', Dumper::toString($version)));
         } else {
             $output->writeln(Dumper::toString($version));
         }
         if (!file_exists($paramFile)) {
             $this->createParametersFile($version, $paramFile, $param);
         } else {
             $this->updateParametersFile($version, $paramFile, $param);
         }
     } else {
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $output->writeln(sprintf('Version: <comment>%s</comment>', Dumper::toString($version)));
         } else {
             $output->writeln(Dumper::toString($version));
         }
     }
 }
Exemplo n.º 17
0
 protected function setUp()
 {
     $this->update = new Update('test.phar', '1234567890123456789012345678901234567890', 'http://example.com/test.phar', $this->version = Parser::toVersion('1.2.3'), 'http://example.com/test-1.2.3.phar.pubkey');
 }
Exemplo n.º 18
0
 /**
  * @return Version
  */
 public function getVersion()
 {
     $parameters = $this->readParametersFile();
     return VersionParser::toVersion($parameters['parameters'][$this->versionParameter]);
 }
Exemplo n.º 19
0
 /**
  * Updates the running Phar if any is available.
  *
  * @param string|Version $version  The current version.
  * @param boolean        $major    Lock to current major version?
  * @param boolean        $pre      Allow pre-releases?
  *
  * @return boolean TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false, $newVersion = null)
 {
     if (false === $version instanceof Version) {
         $version = Parser::toVersion($version);
     }
     if ($newVersion !== null && false === $newVersion instanceof Version) {
         $newVersion = Parser::toVersion($newVersion);
     }
     if ($newVersion) {
         if (Comparator::isEqualTo($version, $newVersion)) {
             $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version));
         }
         $update = $this->manifest->find($newVersion);
         if (null === $update) {
             $this->logger->error(sprintf('No update found for version "%s".', (string) $newVersion));
             return false;
         }
     } else {
         $update = $this->manifest->findRecent($version, $major, $pre);
     }
     if (null === $update) {
         $this->logger->error(sprintf('You are already using jarvis version "%s".', (string) $version));
         return false;
     }
     if ($update instanceof Update) {
         if (!$this->downloadFile($update)) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 20
0
 public function testUpdateNone()
 {
     $manager = new Manager(new Manifest(array(new Update('new.phar', 'test', 'test', Parser::toVersion('2.0.1')))));
     $manager->setRunningFile($this->createFile());
     $this->assertFalse($manager->update('1.0.0', true));
 }