Skip to content

Commit

Permalink
Fixes #2964: When manually deploying using a tag also push that tag t…
Browse files Browse the repository at this point in the history
…o source repo. (#2992)

* Adding a cutSourceTag method and invoking when deploying tag.

* Set default deploy.tag_source config setting and check it when deploying.

* Refactoring to use a single cutTag method.

* Remove line about expectation you already have a tag on your source before you tag a release.

* Warn if user is creating a tag but tag_source option is false.

* Updating deploy documentation.
  • Loading branch information
ba66e77 authored and danepowell committed Aug 31, 2018
1 parent c5eaf13 commit 9b6e6f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ To create a new git tag for the artifact (rather than committing to a branch) ru

This will generate the artifact, tag it with `1.0.0`, and push it to the remotes defined in blt.yml.

When deploying a tag to the artifact repo, if the config option `deploy.tag_source` is set to TRUE, BLT will also create the supplied tag on the source repository. This makes it easier to verify the source commit upon which an artifact tag is based.

*Note* however that BLT _does not_ automatically push the tag created on the source repository to its remote.

## Modifying the artifact

The artifact is built by running the `artifact:build` target, which does the following:
Expand Down
35 changes: 27 additions & 8 deletions src/Robo/Commands/Deploy/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DeployCommand extends BltTasks {
protected $commitMessage;
protected $excludeFileTemp;
protected $deployDir;
protected $tagSource;

/**
* This hook will fire for all commands in this command file.
Expand All @@ -28,6 +29,7 @@ class DeployCommand extends BltTasks {
public function initialize() {
$this->excludeFileTemp = $this->getConfigValue('deploy.exclude_file') . '.tmp';
$this->deployDir = $this->getConfigValue('deploy.dir');
$this->tagSource = $this->getConfigValue('deploy.tag_source', TRUE);
}

/**
Expand All @@ -53,12 +55,15 @@ public function deploy($options = [
$this->checkDirty($options);

if (!$options['tag'] && !$options['branch']) {
$this->say("Typically, you would only create a tag if you currently have a tag checked out on your source repository.");
$this->createTag = $this->confirm("Would you like to create a tag?", $this->createTag);
}
$this->commitMessage = $this->getCommitMessage($options);

if ($options['tag'] || $this->createTag) {
// Warn if they're creating a tag and we won't tag the source for them.
if (!$this->tagSource) {
$this->say("Config option deploy.tag_source if FALSE. The source repo will not be tagged.");
}
$this->deployToTag($options);
}
else {
Expand Down Expand Up @@ -188,7 +193,14 @@ protected function deployToTag($options) {
$this->checkoutLocalDeployBranch();
$this->build();
$this->commit();
$this->cutTag();
$this->cutTag('build');

// Check the deploy.tag_source config value and also tag the source repo if
// it is set to TRUE (the default).
if ($this->tagSource) {
$this->cutTag('source');
}

$this->push($this->tagName, $options);
}

Expand Down Expand Up @@ -531,15 +543,22 @@ protected function push($identifier, $options) {

/**
* Creates a tag on the build repository.
*
* @param $repo
* The repo in which a tag should be cut.
*/
protected function cutTag() {
$this->taskExecStack()
protected function cutTag($repo = 'build') {
$execStack = $this->taskExecStack()
->exec("git tag -a {$this->tagName} -m '{$this->commitMessage}'")
->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE)
->stopOnFail()
->dir($this->deployDir)
->run();
$this->say("The tag {$this->tagName} was created for the build artifact.");
->stopOnFail();

if ($repo == 'build') {
$execStack->dir($this->deployDir);
}

$execStack->run();
$this->say("The tag {$this->tagName} was created on the {$repo} repository.");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions template/blt/blt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ git:
default_branch: master
remotes: []

deploy:
# When manually deploying a tag, also tag the source repository.
tag_source: TRUE

drush:
# You can set custom project aliases in drush/sites/*.site.yml.
aliases:
Expand Down

0 comments on commit 9b6e6f0

Please sign in to comment.