Skip to content
Permalink
Browse files

Added deprecation for PackageBuild variables (Use interpolated variab…

…les instead).
  • Loading branch information
corpsee committed Feb 5, 2020
1 parent a42b78a commit fa6086f3eb5c1e1e35fd012253872516e34902df
@@ -37,3 +37,9 @@ Where `VARIABLE` can be one of the following:
* **BUILD_PATH** - The path to the build.

* **BUILD_LINK** - The URL to the build in PHP Censor.

* **CURRENT_DATE** - Current date in format "Y-m-d".

* **CURRENT_TIME** - Current time in format "H-i-s".

* **CURRENT_DATETIME** - Current date and time in format "Y-m-d_H-i-s".
@@ -11,12 +11,3 @@ Configuration
* **directory** - Required - Directory in which to put the package file.
* **filename** - Required - File name for the package.
* **format** - Required - `tar` or `zip`.

You can use following variables in filename:

* %build.commit%
* %build.id%
* %build.branch%
* %project.title%
* %date%
* %time%
@@ -47,6 +47,22 @@ public function setupInterpolationVars(BaseBuild $build, $url)
$this->interpolationVars['%BRANCH_LINK%'] = $build->getBranchLink();
$this->interpolationVars['%ENVIRONMENT%'] = $build->getEnvironment();

putenv('PHP_CENSOR=1');
putenv('PHP_CENSOR_COMMIT_ID=' . $this->interpolationVars['%COMMIT_ID%']);
putenv('PHP_CENSOR_SHORT_COMMIT_ID=' . $this->interpolationVars['%SHORT_COMMIT_ID%']);
putenv('PHP_CENSOR_COMMITTER_EMAIL=' . $this->interpolationVars['%COMMITTER_EMAIL%']);
putenv('PHP_CENSOR_COMMIT_MESSAGE=' . $this->interpolationVars['%COMMIT_MESSAGE%']);
putenv('PHP_CENSOR_COMMIT_LINK=' . $this->interpolationVars['%COMMIT_LINK%']);
putenv('PHP_CENSOR_PROJECT_ID=' . $this->interpolationVars['%PROJECT_ID%']);
putenv('PHP_CENSOR_PROJECT_TITLE=' . $this->interpolationVars['%PROJECT_TITLE%']);
putenv('PHP_CENSOR_PROJECT_LINK=' . $this->interpolationVars['%PROJECT_LINK%']);
putenv('PHP_CENSOR_BUILD_ID=' . $this->interpolationVars['%BUILD_ID%']);
putenv('PHP_CENSOR_BUILD_PATH=' . $this->interpolationVars['%BUILD_PATH%']);
putenv('PHP_CENSOR_BUILD_LINK=' . $this->interpolationVars['%BUILD_LINK%']);
putenv('PHP_CENSOR_BRANCH=' . $this->interpolationVars['%BRANCH%']);
putenv('PHP_CENSOR_BRANCH_LINK=' . $this->interpolationVars['%BRANCH_LINK%']);
putenv('PHP_CENSOR_ENVIRONMENT=' . $this->interpolationVars['%ENVIRONMENT%']);

/** @deprecated The variables are deprecated and will be deleted in version 2.0. Use the variables '%COMMIT_ID%', '%SHORT_COMMIT_ID%' etc. instead. */
$this->interpolationVars['%COMMIT%'] = $this->interpolationVars['%COMMIT_ID%'];
$this->interpolationVars['%SHORT_COMMIT%'] = $this->interpolationVars['%SHORT_COMMIT_ID%'];
@@ -58,6 +74,17 @@ public function setupInterpolationVars(BaseBuild $build, $url)
$this->interpolationVars['%BUILD_URI%'] = $this->interpolationVars['%BUILD_LINK%'];
$this->interpolationVars['%BRANCH_URI%'] = $this->interpolationVars['%BRANCH_LINK%'];

putenv('PHP_CENSOR_COMMIT=' . $this->interpolationVars['%COMMIT_ID%']);
putenv('PHP_CENSOR_SHORT_COMMIT=' . $this->interpolationVars['%SHORT_COMMIT_ID%']);
putenv('PHP_CENSOR_COMMIT_EMAIL=' . $this->interpolationVars['%COMMITTER_EMAIL%']);
putenv('PHP_CENSOR_COMMIT_URI=' . $this->interpolationVars['%COMMIT_LINK%']);
putenv('PHP_CENSOR_PROJECT=' . $this->interpolationVars['%PROJECT_ID%']);
putenv('PHP_CENSOR_PROJECT_URI=' . $this->interpolationVars['%PROJECT_LINK%']);
putenv('PHP_CENSOR_BUILD=' . $this->interpolationVars['%BUILD_ID%']);
putenv('PHP_CENSOR_BUILD_URI=' . $this->interpolationVars['%BUILD_LINK%']);
putenv('PHP_CENSOR_BRANCH_URI=' . $this->interpolationVars['%BRANCH_LINK%']);

/** @deprecated This environment variables are deprecated and will be deleted in version 2.0. Use the variables 'PHP_CENSOR_' instead. */
$this->interpolationVars['%PHPCI%'] = 1;
$this->interpolationVars['%PHPCI_COMMIT%'] = $this->interpolationVars['%COMMIT_ID%'];
$this->interpolationVars['%PHPCI_SHORT_COMMIT%'] = $this->interpolationVars['%SHORT_COMMIT_ID%'];
@@ -74,23 +101,6 @@ public function setupInterpolationVars(BaseBuild $build, $url)
$this->interpolationVars['%PHPCI_BRANCH_URI%'] = $this->interpolationVars['%BRANCH_LINK%'];
$this->interpolationVars['%PHPCI_ENVIRONMENT%'] = $this->interpolationVars['%ENVIRONMENT%'];

putenv('PHP_CENSOR=1');
putenv('PHP_CENSOR_COMMIT_ID=' . $this->interpolationVars['%COMMIT_ID%']);
putenv('PHP_CENSOR_SHORT_COMMIT_ID=' . $this->interpolationVars['%SHORT_COMMIT_ID%']);
putenv('PHP_CENSOR_COMMITTER_EMAIL=' . $this->interpolationVars['%COMMITTER_EMAIL%']);
putenv('PHP_CENSOR_COMMIT_MESSAGE=' . $this->interpolationVars['%COMMIT_MESSAGE%']);
putenv('PHP_CENSOR_COMMIT_LINK=' . $this->interpolationVars['%COMMIT_LINK%']);
putenv('PHP_CENSOR_PROJECT_ID=' . $this->interpolationVars['%PROJECT_ID%']);
putenv('PHP_CENSOR_PROJECT_TITLE=' . $this->interpolationVars['%PROJECT_TITLE%']);
putenv('PHP_CENSOR_PROJECT_LINK=' . $this->interpolationVars['%PROJECT_LINK%']);
putenv('PHP_CENSOR_BUILD_ID=' . $this->interpolationVars['%BUILD_ID%']);
putenv('PHP_CENSOR_BUILD_PATH=' . $this->interpolationVars['%BUILD_PATH%']);
putenv('PHP_CENSOR_BUILD_LINK=' . $this->interpolationVars['%BUILD_LINK%']);
putenv('PHP_CENSOR_BRANCH=' . $this->interpolationVars['%BRANCH%']);
putenv('PHP_CENSOR_BRANCH_LINK=' . $this->interpolationVars['%BRANCH_LINK%']);
putenv('PHP_CENSOR_ENVIRONMENT=' . $this->interpolationVars['%ENVIRONMENT%']);

/** @deprecated This environment variables are deprecated and will be deleted in version 2.0. Use the variables 'PHP_CENSOR_' instead. */
putenv('PHPCI=1');
putenv('PHPCI_COMMIT=' . $this->interpolationVars['%COMMIT_ID%']);
putenv('PHPCI_SHORT_COMMIT=' . $this->interpolationVars['%SHORT_COMMIT_ID%']);
@@ -106,16 +116,20 @@ public function setupInterpolationVars(BaseBuild $build, $url)
putenv('PHPCI_BRANCH=' . $this->interpolationVars['%BRANCH%']);
putenv('PHPCI_BRANCH_URI=' . $this->interpolationVars['%BRANCH_LINK%']);
putenv('PHPCI_ENVIRONMENT=' . $this->interpolationVars['%ENVIRONMENT%']);
}

putenv('PHP_CENSOR_COMMIT=' . $this->interpolationVars['%COMMIT_ID%']);
putenv('PHP_CENSOR_SHORT_COMMIT=' . $this->interpolationVars['%SHORT_COMMIT_ID%']);
putenv('PHP_CENSOR_COMMIT_EMAIL=' . $this->interpolationVars['%COMMITTER_EMAIL%']);
putenv('PHP_CENSOR_COMMIT_URI=' . $this->interpolationVars['%COMMIT_LINK%']);
putenv('PHP_CENSOR_PROJECT=' . $this->interpolationVars['%PROJECT_ID%']);
putenv('PHP_CENSOR_PROJECT_URI=' . $this->interpolationVars['%PROJECT_LINK%']);
putenv('PHP_CENSOR_BUILD=' . $this->interpolationVars['%BUILD_ID%']);
putenv('PHP_CENSOR_BUILD_URI=' . $this->interpolationVars['%BUILD_LINK%']);
putenv('PHP_CENSOR_BRANCH_URI=' . $this->interpolationVars['%BRANCH_LINK%']);
/**
* @param string $input
*
* @return string
*/
private function realtimeInterpolate($input)
{
$input = str_replace('%CURRENT_DATE%', \date('Y-m-d'), $input);
$input = str_replace('%CURRENT_TIME%', \date('H-i-s'), $input);
$input = str_replace('%CURRENT_DATETIME%', \date('Y-m-d_H-i-s'), $input);

return $input;
}

/**
@@ -128,6 +142,8 @@ public function setupInterpolationVars(BaseBuild $build, $url)
*/
public function interpolate($input)
{
$input = $this->realtimeInterpolate($input);

$keys = array_keys($this->interpolationVars);
$values = array_values($this->interpolationVars);

@@ -14,7 +14,7 @@
*/
class CleanBuild extends Plugin
{
protected $remove;
protected $removeFiles;

/**
* @return string
@@ -31,7 +31,7 @@ public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);

$this->remove = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : [];
$this->removeFiles = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : [];
}

/**
@@ -41,12 +41,9 @@ public function execute()
{
$cmd = 'rm -Rf "%s"';

$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.phar');
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.lock');

$success = true;

foreach ($this->remove as $file) {
foreach ($this->removeFiles as $file) {
$ok = $this->builder->executeCommand($cmd, $this->builder->buildPath . $file);

if (!$ok) {
@@ -14,8 +14,6 @@
class Grunt extends Plugin
{
protected $task;
protected $preferDist;

protected $gruntfile;

/**
@@ -14,7 +14,6 @@
class Gulp extends Plugin
{
protected $task;
protected $preferDist;
protected $gulpfile;

/**
@@ -47,18 +47,28 @@ public function execute()
return false;
}

/** @deprecated Variables: "%build.commit%", "%build.id%", "%build.branch%", "%project.title%", "%date%"
* and "%time%" is deprecated and will be deleted in version 2.0. Use the variables "%COMMIT_ID%",
* "%BUILD_ID%", "%BRANCH%", "%PROJECT_TITLE%", "%CURRENT_DATE%", "CURRENT_TIME" instead.
*/
$filename = str_replace('%build.commit%', $build->getCommitId(), $this->filename);
$filename = str_replace('%build.id%', $build->getId(), $filename);
$filename = str_replace('%build.branch%', $build->getBranch(), $filename);
$filename = str_replace('%project.title%', $build->getProject()->getTitle(), $filename);
$filename = str_replace('%date%', date('Y-m-d'), $filename);
$filename = str_replace('%time%', date('Hi'), $filename);

$this->builder->logWarning(
'[DEPRECATED] Variables: "%build.commit%", "%build.id%", "%build.branch%", "%project.title%", "%date%" and "%time%" is deprecated and will be deleted in version 2.0. Use the variables "%COMMIT_ID%", "%BUILD_ID%", "%BRANCH%", "%PROJECT_TITLE%", "%CURRENT_DATE%", "CURRENT_TIME" instead.'
);

$filename = preg_replace('/([^a-zA-Z0-9_-]+)/', '', $filename);

if (!is_array($this->format)) {
$this->format = [$this->format];
}

$success = true;
foreach ($this->format as $format) {
switch ($format) {
case 'tar':
@@ -70,7 +80,11 @@ public function execute()
break;
}

$success = $this->builder->executeCommand($cmd, $this->directory, $filename);
$success = $this->builder->executeCommand(
$cmd,
$this->directory,
$this->builder->interpolate($filename)
);
}

return $success;

0 comments on commit fa6086f

Please sign in to comment.
You can’t perform that action at this time.