-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the Command changes for #120 #156
Open
Jonathanm10
wants to merge
4
commits into
master
Choose a base branch
from
sseidelmann-variables_in_commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,12 @@ | |
*/ | ||
class CommandAction extends BaseAction | ||
{ | ||
/** | ||
* Saves the command vars. | ||
* @var array | ||
*/ | ||
protected $commandVars = []; | ||
|
||
public function __construct($options) | ||
{ | ||
$this->options = array_merge(array( | ||
|
@@ -31,11 +37,13 @@ public function __construct($options) | |
if ($this->options['cmd'] == null) { | ||
throw new \RuntimeException('Missing [cmd] option'); | ||
} | ||
|
||
$this->commandVars['version'] = Context::get('version-persister')->getCurrentVersion(); | ||
} | ||
|
||
public function execute() | ||
{ | ||
$command = $this->options['cmd']; | ||
$command = $this->prepareCommand($this->options['cmd'], $this->commandVars); | ||
Context::get('output')->write("<comment>$command</comment>\n\n"); | ||
|
||
// Prepare a callback for live output | ||
|
@@ -64,4 +72,29 @@ public function execute() | |
throw new \RuntimeException("Command [$command] exit with code " . $process->getExitCode()); | ||
} | ||
} | ||
|
||
/** | ||
* Prepares the command. | ||
* @param string $command | ||
* @return string | ||
*/ | ||
protected function prepareCommand($command) | ||
{ | ||
if (substr_count($command, '%') < 2) { | ||
return $command; | ||
} | ||
|
||
$this->commandVars['new_version'] = Context::getParam('new-version'); | ||
extract($this->commandVars); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know that extract() function. This is no magique. So ugly. So... :puke:
|
||
|
||
preg_match_all('@%([A-Za-z0-9_]*)%@', $command, $matches); | ||
if (array_key_exists(1, $matches)) { | ||
foreach ($matches[1] as $var) { | ||
$command = str_replace('%' . $var . '%', $$var, $command); | ||
} | ||
|
||
} | ||
|
||
return $command; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,18 @@ public function testCommand() | |
// $this->manualDebug(); | ||
$this->assertContains('Command Action : echo "hello world"', $output); | ||
} | ||
|
||
public function testVersionsOutputOnPostRelease() | ||
{ | ||
$this->createChangelog('simple'); | ||
$this->createConfig('simple', 'changelog', array( | ||
'post-release-actions' => array( | ||
'command' => array('cmd' => 'echo %version% %new_version%'), | ||
), | ||
)); | ||
|
||
exec('./RMT release -n --no-ansi --comment="test"', $output); | ||
$output = implode("\n", $output); | ||
$this->assertContains('Command Action : echo 1 2', $output); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, for the tests, thanks! |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need that class property? Why not doing everything into the execute() method?
For info, from the execute method, you can do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running
Context::getParam('current-version')
in theexecute()
method would break since it's not yet defined for instance when ran in the prerequisites.Running
Context::get('version-persister')->getCurrentVersion()
do the trick but if ran let's say in theprepareCommand()
, that will end up being the new released version and not the current one.The only way found at this point to get the current version is to get it in the constructor but I might be missing something