Skip to content

Commit

Permalink
Merge pull request #61 from open-sausages/1-to-2-merge
Browse files Browse the repository at this point in the history
1 to 2 merge
  • Loading branch information
Damian Mooyman authored Dec 5, 2017
2 parents e65b7a6 + fe129de commit 1ee78d9
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 24 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ This command has these options:
* `--directory <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-<version>` in the current directory.
* `--repository <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 <type>` 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:

Expand All @@ -91,6 +95,9 @@ This command has these options:
omit this option.
* `--aws-profile <profile>` to specify the AWS profile name for uploading releases to s3. Check with
[email protected] 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.
Expand Down
55 changes: 44 additions & 11 deletions src/Commands/Release/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Expand All @@ -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');
}

/**
Expand Down
45 changes: 36 additions & 9 deletions src/Commands/Release/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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("<info>Success!</info> Release has been updated.");
$command = $this->getPublishCommand($version, $project);
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down
50 changes: 49 additions & 1 deletion src/Steps/Release/BuildArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion src/Steps/Release/CreateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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!");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Steps/Release/UpdateTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/Utility/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 1ee78d9

Please sign in to comment.