diff --git a/readme.md b/readme.md index 45a3f5f..30bb018 100644 --- a/readme.md +++ b/readme.md @@ -60,11 +60,15 @@ This command has these options: * `--directory ` to specify the folder to create or look for this project in. If you don't specify this, it will install to the path specified by `./release-` in the current directory. * `--repository ` will allow a custom composer package url to be specified. E.g. `http://packages.cwp.govt.nz` + Note: If you specify the repository during setup it will be re-used for subsquent commands + unless the `.cow.repository` file is deleted. * `--branching ` will specify a branching strategy. This allows these options: * `auto` - Default option, will branch to the minor version (e.g. 1.1) unless doing a non-stable tag (e.g. rc1) * `major` - Branch all repos to the major version (e.g. 1) unless already on a more-specific minor version. * `minor` - Branch all repos to the minor semver branch (e.g. 1.1) * `none` - Release from the current branch and do no branching. +* `--skip-tests` to skip tests +* `--skip-i18n` to skip updating localisations `release` actually has several sub-commands which can be run independently. These are as below: @@ -91,6 +95,9 @@ This command has these options: omit this option. * `--aws-profile ` to specify the AWS profile name for uploading releases to s3. Check with damian@silverstripe.com if you don't have an AWS key setup. +* `--skip-archive-upload` to disable both "archive" and "upload". This is useful if doing a private release and + you don't want to upload this file to AWS. +* `--skip-upload` to disable the "upload" command (but not archive) The release process, as with the initial `cow release` command, will actually be composed of several sub-commands, each of which could be run separately. diff --git a/src/Commands/Release/Publish.php b/src/Commands/Release/Publish.php index f720110..14d4067 100644 --- a/src/Commands/Release/Publish.php +++ b/src/Commands/Release/Publish.php @@ -22,13 +22,21 @@ class Publish extends Release protected function configureOptions() { parent::configureOptions(); - $this->addOption( - 'aws-profile', - null, - InputOption::VALUE_REQUIRED, - "AWS profile to use for upload", - "silverstripe" - ); + $this + ->addOption('skip-archive-upload', null, InputOption::VALUE_NONE, 'Skip archive & upload to AWS') + ->addOption( + 'skip-upload', + null, + InputOption::VALUE_NONE, + 'Skip uploading to AWS, but still generates archives' + ) + ->addOption( + 'aws-profile', + null, + InputOption::VALUE_REQUIRED, + "AWS profile to use for upload", + "silverstripe" + ); } protected function fire() @@ -37,6 +45,7 @@ protected function fire() $project = $this->getProject(); $releasePlan = $this->getReleasePlan(); $awsProfile = $this->getInputAWSProfile(); + $repository = $this->getInputRepository(); // Does bulk of module publishing, rewrite of dev branches, rewrite of tags, and actual tagging $publish = new PublishRelease($this, $project, $releasePlan); @@ -47,12 +56,36 @@ protected function fire() $wait->run($this->input, $this->output); // Create packages - $package = new BuildArchive($this, $project, $releasePlan); - $package->run($this->input, $this->output); + if (!$this->skipArchive()) { + $package = new BuildArchive($this, $project, $releasePlan, $repository); + $package->run($this->input, $this->output); + } // Upload - $upload = new UploadArchive($this, $project, $releasePlan, $awsProfile); - $upload->run($this->input, $this->output); + if (!$this->skipUpload()) { + $upload = new UploadArchive($this, $project, $releasePlan, $awsProfile); + $upload->run($this->input, $this->output); + } + } + + /** + * Is archive skipped? + * + * @return mixed + */ + protected function skipArchive() + { + return $this->input->getOption('skip-archive-upload'); + } + + /** + * Is uploading skipped? + * + * @return bool + */ + protected function skipUpload() + { + return $this->input->getOption('skip-upload') || $this->input->getOption('skip-archive-upload'); } /** diff --git a/src/Commands/Release/Release.php b/src/Commands/Release/Release.php index ec30457..d4ab7b8 100644 --- a/src/Commands/Release/Release.php +++ b/src/Commands/Release/Release.php @@ -31,8 +31,20 @@ protected function configureOptions() $this ->addArgument('version', InputArgument::REQUIRED, 'Exact version tag to release this project as') ->addArgument('recipe', InputArgument::OPTIONAL, 'Recipe to release', 'silverstripe/installer') - ->addOption('repository', "r", InputOption::VALUE_REQUIRED, "Custom repository url") + ->addOption('repository', 'r', InputOption::VALUE_REQUIRED, "Custom repository url") ->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Optional directory to release project from') + ->addOption( + 'skip-tests', + null, + InputOption::VALUE_NONE, + 'Skip the tests suite run when performing the release' + ) + ->addOption( + 'skip-i18n', + null, + InputOption::VALUE_NONE, + 'Skip the text collection task when performing the release' + ) ->addOption( 'branching', 'b', @@ -65,19 +77,21 @@ protected function fire() $branchAlias->run($this->input, $this->output); // Update all translations - $translate = new UpdateTranslations($this, $project, $releasePlan); - $translate->run($this->input, $this->output); + if (!$this->input->getOption('skip-i18n')) { + $translate = new UpdateTranslations($this, $project, $releasePlan); + $translate->run($this->input, $this->output); + } // Run tests - $test = new RunTests($this, $project); - $test->run($this->input, $this->output); + if (!$this->input->getOption('skip-tests')) { + $test = new RunTests($this, $project); + $test->run($this->input, $this->output); + } // Generate changelog $changelogs = new CreateChangelog($this, $project, $releasePlan); $changelogs->run($this->input, $this->output); - - // Output completion $this->output->writeln("Success! Release has been updated."); $command = $this->getPublishCommand($version, $project); @@ -119,7 +133,20 @@ protected function getInputDirectory() */ protected function getInputRepository() { - return $this->input->getOption('repository'); + // Check specified repository + $repository = $this->input->getOption('repository'); + if ($repository) { + return $repository; + } + + // Check if repository was used during install + // Prevents mistake publishing a project created with a repository + $directory = $this->getInputDirectory(); + if (file_exists($directory . '/.cow.repository')) { + return file_get_contents($directory . '/.cow.repository'); + } + + return null; } /** @@ -132,7 +159,7 @@ protected function pickDirectory() $version = $this->getInputVersion(); $recipe = $this->getInputRecipe(); - $filename = DIRECTORY_SEPARATOR . 'release-' . str_replace('/', '_', $recipe) . '-'. $version->getValue(); + $filename = DIRECTORY_SEPARATOR . 'release-' . str_replace('/', '_', $recipe) . '-' . $version->getValue(); $cwd = getcwd(); // Check if we are already in this directory diff --git a/src/Steps/Release/BuildArchive.php b/src/Steps/Release/BuildArchive.php index b63433e..32e37c4 100644 --- a/src/Steps/Release/BuildArchive.php +++ b/src/Steps/Release/BuildArchive.php @@ -4,7 +4,10 @@ use Exception; use InvalidArgumentException; +use SilverStripe\Cow\Commands\Command; +use SilverStripe\Cow\Model\Modules\Project; use SilverStripe\Cow\Model\Release\Archive; +use SilverStripe\Cow\Model\Release\LibraryRelease; use SilverStripe\Cow\Utility\Composer; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -14,6 +17,31 @@ */ class BuildArchive extends ReleaseStep { + /** + * Custom composer repository + * + * @var string + */ + protected $repository; + + /** + * Construct new archive builder + * + * @param Command $command + * @param Project $project + * @param LibraryRelease|null $releasePlan + * @param string $repository Custom composer repository for this install + */ + public function __construct( + Command $command, + Project $project, + LibraryRelease $releasePlan = null, + $repository = null + ) { + parent::__construct($command, $project, $releasePlan); + $this->setRepository($repository); + } + public function getStepName() { return 'release:archive'; @@ -144,7 +172,7 @@ protected function createArchiveFiles(OutputInterface $output, Archive $archive) // Install to this location $this->log($output, "Installing version {$version}"); - Composer::createProject($this->getCommandRunner($output), $name, $path, $version, null, true); + Composer::createProject($this->getCommandRunner($output), $name, $path, $version, $this->getRepository(), true); // Copy composer.phar to the project // Write version info to the core folders (shouldn't be in version control) @@ -190,4 +218,24 @@ protected function getArchiveCommand($file) } throw new InvalidArgumentException("Cannot build archive for file {$file}"); } + + /** + * Get custom composer repository + * + * @return string + */ + public function getRepository() + { + return $this->repository; + } + + /** + * @param string $repository + * @return $this + */ + protected function setRepository($repository) + { + $this->repository = $repository; + return $this; + } } diff --git a/src/Steps/Release/CreateProject.php b/src/Steps/Release/CreateProject.php index 3238cde..111db02 100644 --- a/src/Steps/Release/CreateProject.php +++ b/src/Steps/Release/CreateProject.php @@ -47,7 +47,7 @@ class CreateProject extends Step * @param Version $version * @param string $recipe * @param string $directory - * @param string $repository + * @param string $repository Custom composer repository for this install */ public function __construct(Command $command, Version $version, $recipe, $directory = '.', $repository = null) { @@ -92,6 +92,11 @@ public function run(InputInterface $input, OutputInterface $output) $repo->run("checkout", ["--", $path]); } + // If using custom repository, write `.cow.repository` file for later + if ($this->getRepository()) { + file_put_contents($path.'/.cow.repository', $this->getRepository()); + } + // Success $this->log($output, "Project successfully created!"); } diff --git a/src/Steps/Release/UpdateTranslations.php b/src/Steps/Release/UpdateTranslations.php index 403dbaf..b88ecac 100644 --- a/src/Steps/Release/UpdateTranslations.php +++ b/src/Steps/Release/UpdateTranslations.php @@ -237,7 +237,7 @@ protected function pullSource(OutputInterface $output, $modules) } /** - * Tidy yaml files using yamlclean ruby gem + * Tidy yaml files using symfony yaml * * @param OutputInterface $output * @param Module[] $modules List of modules diff --git a/src/Utility/Composer.php b/src/Utility/Composer.php index 920da5d..7db86be 100644 --- a/src/Utility/Composer.php +++ b/src/Utility/Composer.php @@ -45,7 +45,15 @@ public static function createProject( $repository = null, $preferDist = false ) { - $command = ["composer", "create-project", "--no-interaction", $recipe, $directory, $version]; + $command = [ + "composer", + "create-project", + "--no-interaction", + "--ignore-platform-reqs", + $recipe, + $directory, + $version + ]; if ($preferDist) { $command[] = "--prefer-dist"; $command[] = "--no-dev";