Skip to content

Commit

Permalink
Adding more verbosity control variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Oct 10, 2016
1 parent 09a445d commit f027b73
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 59 deletions.
3 changes: 2 additions & 1 deletion phing/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<taskdef name="randomstring" classname="phingcludes.RandomStringTask" />
<taskdef name="disabletargets" classname="phingcludes.DisableTargetsTask" />
<taskdef name="filterFileListByFileSet" classname="phingcludes.FilterFileListByFileSetTask"/>
<taskdef name="verbosityTask" classname="phingcludes.VerbosityTask"/>
<taskdef name="phpVariable" classname="phingcludes.PhpVariableTask"/>

<if>
Expand Down Expand Up @@ -89,7 +90,7 @@
<available file="${target-hooks.${hook-name}.dir}" type="dir" property="dirExists" />
<then>
<echo>Executing command in ${target-hooks.${hook-name}.dir}:</echo>
<exec dir="${target-hooks.${hook-name}.dir}" command="${target-hooks.${hook-name}.command}" logoutput="true" checkreturn="true" level="info" passthru="true" />
<exec dir="${target-hooks.${hook-name}.dir}" command="${target-hooks.${hook-name}.command}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true" />
</then>
<else>
<fail>The directory ${target-hooks.${hook-name}.dir} does not exist. Will not run command for ${hook-name}.</fail>
Expand Down
10 changes: 9 additions & 1 deletion phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ behat:
# - ${docroot}/profiles
- ${repo.root}/tests/behat
tags: '~ajax'
verbose: ${blt.verbose}

blt:
update:
ignore-existing-file: ${blt.root}/scripts/blt/ignore-existing.txt
# If blt.verbose, then exec_level = info.
exec_level: verbose
verbose: false
# From most to least verbose: debug, verbose, info, warn, error.
# Equivalent of using Phing arguments -debug, -verbose, [none], -quiet, -silent
# Note that this does not affect passthru output.
level: info

composer:
bin: ${repo.root}/vendor/bin
Expand Down Expand Up @@ -44,7 +52,7 @@ drush:
uri: ${multisite.name}
assume: yes
passthru: yes
verbose: yes
verbose: ${blt.verbose}

multisite:
# The docroot/sites/default directory is used by default.
Expand Down
20 changes: 18 additions & 2 deletions phing/phingcludes/BehatTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function setStrict($strict)
*/
public function setVerbose($verbose)
{
$this->verbose = StringHelper::booleanValue($verbose);
$this->verbose = StringHelper::booleanValue($verbose) || StringHelper::booleanValue((bool) $verbose);
}

/**
Expand Down Expand Up @@ -385,6 +385,13 @@ protected function behatExists($executable)
return (empty($return) ? false : true);
}

/**
* Initialize the task.
*/
public function init() {
$this->setVerbose($this->getProject()->getProperty('behat.verbose'));
}

/**
* The main entry point method.
*
Expand Down Expand Up @@ -471,6 +478,10 @@ public function main()
$this->options[] = 'verbose';
}

if (Phing::getMsgOutputLevel() >= Project::MSG_VERBOSE) {
$this->options[] = 'verbose';
}

if ($this->colors) {
$this->options[] = 'colors';
}
Expand All @@ -488,7 +499,12 @@ public function main()
$command[] = $this->createOption($name, $value);
}
$command = implode(' ', $command);
$this->log("Running '$command'");
if ($this->verbose) {
$this->log("Running '$command'", Project::MSG_INFO);
}
else {
$this->log("Running '$command'", Project::MSG_VERBOSE);
}

// Run Behat.
$last_line = system($command, $return);
Expand Down
52 changes: 52 additions & 0 deletions phing/phingcludes/VerbosityTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* A phing task to loop through properties.
*/
require_once 'phing/Task.php';
use Symfony\Component\Yaml\Yaml;

class VerbosityTask extends Task {

/**
* Path the Drush executable.
*/
public function setLevel($str) {
$this->level = $str;
}


/**
* The main entry point method.
*
* @return bool
* @throws BuildException
*/
public function main() {

$map = [
'debug' => Project::MSG_DEBUG,
'verbose' => Project::MSG_VERBOSE,
'info' => Project::MSG_INFO,
'warn' => Project::MSG_WARN,
'error' => Project::MSG_ERR,
];

if (is_numeric($this->level)) {
$this->setLoggerLevel($this->level);
}
elseif (array_key_exists($this->level, $map)) {
$this->setLoggerLevel($map[$this->level]);
}
else {
$this->log("blt.level '{$this->level}' is invalid. Acceptable values are " . implode(', ', array_keys($map)), Project::MSG_ERR);
}
}
public function setLoggerLevel($level) {
$listeners = $this->getProject()->getBuildListeners();
foreach ($listeners as $listener) {
$listener->setMessageOutputLevel($level);
}
}

}
2 changes: 1 addition & 1 deletion phing/tasks/acsf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<target name="acsf:init" description="Initializes ACSF support for project.">
<echo>Adding acsf module as a dependency.</echo>
<exec dir="${repo.root}" command="composer require drupal/acsf:^8" logoutput="true" checkreturn="true" passthru="true" level="info"/>
<exec dir="${repo.root}" command="composer require drupal/acsf:^8" logoutput="true" checkreturn="true" passthru="true" level="${blt.exec_level}"/>
<echo>Executing initialization command for acsf module.</echo>
<drush command="acsf-init">
<option name="include">"${docroot}/modules/contrib/acsf/acsf_init"</option>
Expand Down
26 changes: 13 additions & 13 deletions phing/tasks/blt.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<project name="blt" default="update">
<target name="create-project" hidden="true">
<exec dir="${repo.root}" command="git init" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="git init" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<echo>Updating composer dependencies, this make take a while...</echo>
<exec dir="${repo.root}" command="export COMPOSER_PROCESS_TIMEOUT=600; composer update --no-interaction" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="git add -A" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="git commit -m 'Initial commit.'" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="export COMPOSER_PROCESS_TIMEOUT=600; composer update --no-interaction" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="git add -A" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="git commit -m 'Initial commit.'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${repo.root}" command="cat ${blt.root}/scripts/blt/ascii-art.txt" logoutput="true" passthru="true" checkreturn="false"/>
</target>

Expand All @@ -17,10 +17,10 @@
<target name="blt:rsync-template" hidden="true">
<echo>Copying files from BLT's template into your project.</echo>
<!-- @todo Do not overwrite structured or executable files. Instead, update them intelligently settings.php, drush.wrapper etc. -->
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --exclude-from=${blt.update.ignore-existing-file}" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --exclude-from=${blt.update.ignore-existing-file}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

<!--Rsync files without overwriting existing-->
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --include-from=${blt.update.ignore-existing-file} --ignore-existing" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g ${blt.root}/template/ ${repo.root}/ --include-from=${blt.update.ignore-existing-file} --ignore-existing" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>

<target name="update" depends="blt:rsync-template, blt:update-composer, blt:update-yml, setup:drupal:settings" hidden="true">
Expand All @@ -41,9 +41,9 @@
<echo>Merging BLT's composer.json template with your project's composer.json.</echo>
<echo>This MAY overwrite some existing values.</echo>
<!--Values in the project's existing composer.json file will be overwritten.-->
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console composer:munge ${repo.root}/composer.json ${blt.root}/template/composer.json > ${repo.root}/composer.json.tmp" logoutput="true" checkreturn="true" level="info"/>
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console composer:munge ${repo.root}/composer.json ${blt.root}/template/composer.json > ${repo.root}/composer.json.tmp" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<!--@todo Find out why can't we just redirect output directly back to composer.json. -->
<exec dir="${repo.root}" command="mv ${repo.root}/composer.json.tmp ${repo.root}/composer.json" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="mv ${repo.root}/composer.json.tmp ${repo.root}/composer.json" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<echo>If your composer.json was modified, you need to run "composer update".</echo>
</target>

Expand All @@ -52,14 +52,14 @@
<echo>Merging BLT's project.yml template with your project's project.yml.</echo>
<echo>This WILL NOT overwrite existing values.</echo>
<!--Values in the project's existing project.yml file will be preserved and not overridden.-->
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console yaml:munge ${blt.root}/template/project.yml ${repo.root}/project.yml > ${repo.root}/project.yml.tmp" logoutput="true" checkreturn="true" level="info"/>
<exec dir="${repo.root}" command="${repo.root}/vendor/bin/blt-console yaml:munge ${blt.root}/template/project.yml ${repo.root}/project.yml > ${repo.root}/project.yml.tmp" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<!--@todo Find out why can't we just redirect output directly back to project.yml. -->
<exec dir="${repo.root}" command="mv ${repo.root}/project.yml.tmp ${repo.root}/project.yml" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="mv ${repo.root}/project.yml.tmp ${repo.root}/project.yml" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<echo>project.yml has been modified.</echo>
</target>

<target name="cleanup" description="Removes deprecated BLT files and directories.">
<exec dir="${repo.root}" command="${blt.root}/scripts/blt/remove-deprecated.sh" logoutput="true" checkreturn="true" level="info" passthru="true" />
<exec dir="${repo.root}" command="${blt.root}/scripts/blt/remove-deprecated.sh" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true" />
</target>

<target name="install-alias" description="Installs the BLT alias for command line usage." hidden="true">
Expand All @@ -69,10 +69,10 @@
<if>
<equals arg1="${create_alias}" arg2="true"/>
<then>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh -y" logoutput="true" level="info" passthru="true"/>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh -y" logoutput="true" level="${blt.exec_level}" passthru="true"/>
</then>
<else>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh" logoutput="true" level="info" passthru="true"/>
<exec dir="${blt.root}/scripts/blt" command="./install-alias.sh" logoutput="true" level="${blt.exec_level}" passthru="true"/>
</else>
</if>
</then>
Expand Down
28 changes: 14 additions & 14 deletions phing/tasks/deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@
<echo message="Fetching from git remote ${deploy.remote}"/>

<!-- Generate an md5 sum of the remote URL to use as remote name. -->
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName" checkreturn="true" level="info"/>
<exec command="git remote add ${remoteName} ${deploy.remote}" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName" checkreturn="true" level="${blt.exec_level}"/>
<exec command="git remote add ${remoteName} ${deploy.remote}" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

<!-- @todo Only call this for the first remote. -->
<phingcall target="deploy:remote:pull" />
</target>

<target name="deploy:remote:pull" description="Checks out deploy branch from upstream remote." hidden="true">
<exec command="git fetch ${remoteName} ${deploy.branch}" dir="${deploy.dir}" logoutput="true" level="info" passthru="true"/>
<exec command="git fetch ${remoteName} ${deploy.branch}" dir="${deploy.dir}" logoutput="true" level="${blt.exec_level}" passthru="true"/>

<!-- Create the new branch, "[source-branch-name]-build". -->
<!-- We intentionally use checkreturn="false" in case the branch already exists. `git checkout -B` does not seem to work as advertised -->
<exec command="git checkout -b ${deploy.branch}" dir="${deploy.dir}" logoutput="true" checkreturn="false" level="info" passthru="true"/>
<exec command="git checkout -b ${deploy.branch}" dir="${deploy.dir}" logoutput="true" checkreturn="false" level="${blt.exec_level}" passthru="true"/>

<!-- Pull the latest updates (if available). -->
<exec command="git merge ${remoteName}/${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true"/>
Expand All @@ -88,8 +88,8 @@

<target name="deploy:commit" hidden="true">
<!-- We make these commands quiet because they can cause the output to be so long that Travis CI stops logging. -->
<exec command="git add -A" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="git commit -m '${deploy.commitMsg}' --quiet" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="git add -A" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec command="git commit -m '${deploy.commitMsg}' --quiet" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>

<target name="deploy:composer:install" description="Downloads core and contrib to deploy folder." hidden="true">
Expand All @@ -104,7 +104,7 @@
<include name="composer.lock"/>
</fileset>
</copy>
<exec dir="${deploy.dir}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${deploy.dir}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</then>
<else>
<echo>Dependencies will not be built because deploy.build-dependencies is not enabled.</echo>
Expand All @@ -119,7 +119,7 @@
<!-- @todo Support multisite. -->
<chmod file="${docroot}/sites/default" mode="0777" />

<exec dir="${repo.root}" command="rsync -a --no-g --delete --delete-excluded --exclude-from=${deploy.exclude_file} ${repo.root}/ ${deploy.dir}/ --filter 'protect /.git/'" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${repo.root}" command="rsync -a --no-g --delete --delete-excluded --exclude-from=${deploy.exclude_file} ${repo.root}/ ${deploy.dir}/ --filter 'protect /.git/'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>

<!-- Use our own .gitignore -->
<copy file="${deploy.gitignore_file}" tofile="${deploy.dir}/.gitignore" overwrite="true"/>
Expand All @@ -131,8 +131,8 @@

<target name="deploy:prepare-dir" description="Delete the existing deploy directory and re-initialize as an empty git repository." hidden="true">
<delete dir="${deploy.dir}" failonerror="false" quiet="true" />
<exec command="git init ${deploy.dir}" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec dir="${deploy.dir}" command="git config --local core.excludesfile false" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="git init ${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${deploy.dir}" command="git config --local core.excludesfile false" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<echo>Global .gitignore file is being disabled for this repository to prevent unexpected behavior.</echo>
</target>

Expand All @@ -142,13 +142,13 @@

<target name="deploy:push-remote" description="Pushes to a git remote." hidden="true">
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName"/>
<exec command="git push ${remoteName} ${deploy.branch}" dir="${deploy.dir}" outputProperty="deploy.push.output" logoutput="true" checkreturn="true" level="info"/>
<exec command="export DEPLOY_UPTODATE=$(echo '${deploy.push.output}' | grep --quiet 'Everything up-to-date')" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="git push ${remoteName} ${deploy.branch}" dir="${deploy.dir}" outputProperty="deploy.push.output" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<exec command="export DEPLOY_UPTODATE=$(echo '${deploy.push.output}' | grep --quiet 'Everything up-to-date')" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>

<target name="deploy:sanitize" description="Removes sensitive files from the deploy docroot." hidden="true">
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/docroot" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/vendor" logoutput="true" checkreturn="true" level="info" passthru="true"/>
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/docroot" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/vendor" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<delete>
<fileset dir="${deploy.dir}/docroot">
<include name="core/*.txt"/>
Expand Down
14 changes: 14 additions & 0 deletions phing/tasks/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
</then>
</if>

<verbosityTask level="${blt.level}"/>
<!-- When blt verbosity level is above "warn", then increase verbosity of exec_level and various other tasks using blt.verbose property (Behat, Drush). -->
<if>
<or>
<equals arg1="${blt.level}" arg2="debug"/>
<equals arg1="${blt.level}" arg2="verbose"/>
<equals arg1="${blt.level}" arg2="info"/>
</or>
<then>
<property name="blt.exec_level" value="info"/>
<property name="blt.verbose" value="true"/>
</then>
</if>

<echo level="verbose">Executing commands against multisite "${multisite.name}"</echo>

<!-- Default drush alias. -->
Expand Down
Loading

0 comments on commit f027b73

Please sign in to comment.