public function execute(Context $context) { $this->io->write(sprintf('Comparing <info>%s</info> (<comment>%s</comment>) with <info>%s</info> (<comment>%s</comment>)', $context->getVersion()->getName(), $context->getVersion()->getBuild(), $context->getRemoteVersion()->getName(), $context->getRemoteVersion()->getBuild())); $result = $this->repository->diff($context->getRemoteVersion(), $context->getVersion()); if ($result) { foreach ($result as $fileinfo) { switch ($fileinfo->getStatus()) { case Status::ADDED: $symbol = '+'; $color = 'info'; break; case Status::MODIFIED: $symbol = '*'; $color = 'comment'; break; case Status::DELETED: $symbol = '-'; $color = 'error'; break; } $this->io->write(sprintf(' <%s>%-2s %s</%s>', $color, $symbol, $fileinfo->getPathname(), $color)); } } else { $this->io->write('No changes between versions'); } }
public function execute(Context $context) { // this was filled by the builder $filesModified = $context->getFilesModified(); $filesDeleted = $context->getFilesDeleted(); if (false === $context->isFullDeploy()) { $diff = $this->repository->diff($context->getRemoteVersion(), $context->getVersion()); $subselectionModified = new FileCollection($context->getBuilddir()); foreach ($diff as $fileinfo) { if (Status::ADDED === $fileinfo->getStatus()) { $subselectionModified[] = $fileinfo->getPathname(); } elseif (Status::MODIFIED === $fileinfo->getStatus()) { $subselectionModified[] = $fileinfo->getPathname(); } elseif (Status::DELETED === $fileinfo->getStatus()) { $filesDeleted->add($fileinfo->getPathname(), true); } else { // @todo handle other cases if they actually exist } } foreach ($this->derivedFiles as $derivable) { $source = $derivable['source']; $derived = $derivable['derived']; if ($subselectionModified->has($source)) { $subselectionModified->add($derived); } } // only keep files that are changed $filesModified->intersect($subselectionModified); // if (0 === count($filesAdded) && count($subselectionAdded) > 0) { // // hmm.. so files have changed but nothing to deploy // // it looks like we forgot to specify some derived files // // @todo inform the user about this? // } // @todo we could also check here if all files are accounted for (maybe // some files were deleted and not told to us by setting it in // the `removes` config?) in other words: file_exists on all files? } else { foreach ($this->derivedFiles as $derivable) { $source = $derivable['source']; $derived = $derivable['derived']; if ($filesModified->has($source)) { $filesModified->add($derived); } } } // never upload the conveyor configuration! $filesModified->remove('conveyor.yml'); // validate result, throw exception when we have nothing to deploy if (0 === count($filesModified) && 0 === count($filesDeleted)) { throw new EmptyChangesetException(); } $context->setFilesModified($filesModified); $context->setFilesDeleted($filesDeleted); }
protected function compareRemoteVersionBuild(Context $context) { if ($context->isFullDeploy()) { return true; } if ($context->getVersion()->equals($context->getRemoteVersion())) { $this->io->write('Remote version is already up-to-date.', true); return false; } elseif (1 === $this->repository->versionCompare($context->getRemoteVersion(), $context->getVersion())) { if ($context->isForce()) { $answer = true; } else { $answer = $this->io->askConfirmation(sprintf('Remote version (%s) is newer than the selected version (%s). ' . 'Would you like to continue as full deploy? (Y/n): ', $context->getRemoteVersion()->getBuild(), $context->getVersion()->getBuild()), 'Y'); } if ($answer) { $context->setFullDeploy(true); } else { return false; } } return true; }
/** * Retrieve the status for each target * * @param null|string $target when given only get the status for a single target * @return array */ public function status($target = null) { $config = $this->getConfig()->getConfig(); $targets = null !== $target ? array($target) : array_keys($config['targets']); $repository = $this->getRepository(); $remoteInfoFile = $this->container->getParameter('conveyor.remoteinfofile'); $retval = array(); foreach ($targets as $target) { $this->assertTargetExists($target, $config); } foreach ($targets as $target) { $transporter = $this->getTransporter($target); $strategy = $this->getStrategy($transporter); $context = new Context(); $context->setTarget($target)->setStrategy($strategy); try { $versionFile = FilePath::join($transporter->getPath(), $strategy->getCurrentReleasePath(), $remoteInfoFile); $isDeployed = $transporter->exists($versionFile); if ($isDeployed) { $manager = new StageManager($context, $this->container->get('dispatcher')); $manager->addStage('get.remote.version', new Stage\RetrieveRemoteVersionInfoStage($transporter, $repository, new NullIO(), $remoteInfoFile, array('getRemoteVersion'))); $manager->execute(); // @todo don't compare to master branch, compare to the remote version's ancestor $localVersion = $repository->getVersion(sprintf('dev-%s', $repository->getMasterBranch())); $remoteVersion = $context->getRemoteVersion(); $compare = $repository->versionCompare($localVersion, $remoteVersion); $changelog = array(); if (1 === $compare) { $changelog = $repository->changelog($remoteVersion, $localVersion); } elseif (-1 === $compare) { $changelog = $repository->changelog($localVersion, $remoteVersion); } $retval[$target] = array('remoteVersion' => $context->getRemoteVersion(), 'localVersion' => $localVersion, 'changelog' => $changelog, 'compare' => $compare); } else { $retval[$target] = false; } } catch (\Exception $e) { $retval[$target] = array('error' => $e); } } return $retval; }