From dfa83929158651eb2fa4c6248fd27f1ff1275493 Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 16:11:55 -0600 Subject: [PATCH 1/6] Allow pushing, keeping or discarding the artifact after building. --- src/TheBuild/SelectOneTask.php | 129 +++++++++++++++++++++++++++++++++ tasks/artifact.xml | 48 ++++++++---- tasks/the-build.xml | 3 + 3 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 src/TheBuild/SelectOneTask.php diff --git a/src/TheBuild/SelectOneTask.php b/src/TheBuild/SelectOneTask.php new file mode 100644 index 00000000..2b65d71a --- /dev/null +++ b/src/TheBuild/SelectOneTask.php @@ -0,0 +1,129 @@ + + * + * + * @endcode + * + * @copyright 2018 Palantir.net, Inc. + */ + +namespace TheBuild; + +use BuildException; +use Project; + + +class SelectOneTask extends \Task { + + /** + * @var string + * Required. List of values to select among. + */ + protected $list = ''; + + /** + * @var string + * String to split the list by. + */ + protected $delimiter = ','; + + /** + * @var string + * Required. Property to populate with the selected value. + */ + protected $propertyName = ''; + + /** + * @var string + * Message to display to the user when more than one key is available. + */ + protected $message = 'Select one:'; + + + /** + * Select menu. + */ + public function main() { + $this->validate(); + + $project = $this->getProject(); + + if ($existing_value = $this->project->getProperty($this->propertyName)) { + $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO); + return; + } + + $keys = array_map('trim', explode($this->delimiter, $this->list)); + + if (count($keys) > 1) { + // Prompt for input. + $request = new MenuInputRequest($this->message); + $request->setOptions($keys); + + $this->project->getInputHandler()->handleInput($request); + + $value = $request->getInput(); + } + elseif (count($keys) == 1) { + $value = current($keys); + $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO); + } + + if ($value) { + $project->setNewProperty($this->propertyName, $value); + } + } + + + /** + * Verify that the required attributes are set. + */ + public function validate() { + foreach (['list', 'propertyName'] as $attribute) { + if (empty($this->$attribute)) { + throw new BuildException("$attribute attribute is required.", $this->location); + } + } + } + + /** + * @param string $value + */ + public function setList($value) { + $this->list = $value; + } + + /** + * @param string $value + */ + public function setDelimiter($value) { + $this->delimiter = $value; + } + + /** + * @param string $value + */ + public function setPropertyName($value) { + $this->propertyName = $value; + } + + /** + * @param string $value + */ + public function setMessage($value) { + $this->message = $value; + } + +} diff --git a/tasks/artifact.xml b/tasks/artifact.xml index 24bb4c6c..0588189d 100644 --- a/tasks/artifact.xml +++ b/tasks/artifact.xml @@ -277,35 +277,53 @@ + + - - - - + - + + - + - Pushing changes. - + Artifact changes are in the temporary branch '${artifact.git.temporary_branch}' + + - - - - - - - + + + + + + + + + + + Pushing changes. + + + + + + + + + + + + + diff --git a/tasks/the-build.xml b/tasks/the-build.xml index 0dd92d46..c3362df7 100644 --- a/tasks/the-build.xml +++ b/tasks/the-build.xml @@ -27,6 +27,9 @@ + + + From 2a5b6915a4c350613303eb9e15dcda94a6635c0f Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 16:41:27 -0600 Subject: [PATCH 2/6] Set the full composer path. --- tasks/the-build.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/the-build.xml b/tasks/the-build.xml index c3362df7..38dbb629 100644 --- a/tasks/the-build.xml +++ b/tasks/the-build.xml @@ -95,15 +95,15 @@ - - + + - - + + - - + + From daa83436f1230e59c9f0e16c9806c4a36c301d2a Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 17:53:49 -0600 Subject: [PATCH 3/6] Fix artifact cleanup. --- tasks/artifact.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/artifact.xml b/tasks/artifact.xml index 0588189d..0362c042 100644 --- a/tasks/artifact.xml +++ b/tasks/artifact.xml @@ -324,8 +324,8 @@ - - + + From d4c7fcafb48a92b4709b14f91fa24deee7623cc4 Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 18:01:09 -0600 Subject: [PATCH 4/6] Clean up once. --- tasks/artifact.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tasks/artifact.xml b/tasks/artifact.xml index 0362c042..3afd0b27 100644 --- a/tasks/artifact.xml +++ b/tasks/artifact.xml @@ -63,9 +63,7 @@ - - - + @@ -276,7 +274,7 @@ - + From 892f070230005e13cca2fa8f9353999cfd50590a Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 18:04:29 -0600 Subject: [PATCH 5/6] Update artifact docs to reflect the new push/keep/discard actions. --- docs/artifacts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/artifacts.md b/docs/artifacts.md index c68c1c9d..1ad3edc8 100644 --- a/docs/artifacts.md +++ b/docs/artifacts.md @@ -16,10 +16,10 @@ All artifact configuration should be in your project's base properties file, `.t ## Runtime flags -* `push` - Value should be `y` or `n`. When this flag is provided, it will bypass the "Push artifact changes?" prompt. +* `artifact.result` - Value should be `push`, `keep`, or `discard`. When this flag is provided, it will bypass the "Push artifact changes?" prompt. ``` -$> phing artifact -Dpush=y +$> phing artifact -Dartifact.result=keep ``` ## Examples From d39b712295ea143e0e04f1fc05d23237efb22e9d Mon Sep 17 00:00:00 2001 From: Bec White Date: Tue, 13 Nov 2018 18:11:38 -0600 Subject: [PATCH 6/6] Clean up any tags that were created on the artifact UNLESS the artifact changes were pushed. --- tasks/artifact.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tasks/artifact.xml b/tasks/artifact.xml index 3afd0b27..b9b9b3b9 100644 --- a/tasks/artifact.xml +++ b/tasks/artifact.xml @@ -280,6 +280,7 @@ + @@ -288,6 +289,9 @@ + + Artifact changes are in the temporary branch '${artifact.git.temporary_branch}' @@ -295,6 +299,8 @@ + + @@ -315,13 +321,17 @@ - + + + + +