Skip to content

Commit

Permalink
Fixes acquia#1246: Allow deploy-exclude-additions.txt to be defined (a…
Browse files Browse the repository at this point in the history
…cquia#1327)

* Allow deploy-exclude-additions.txt to be defined.

* Add unit test for new text:munge command.

* Update docs to include new exclude additions feature.

* Add deploy-exclude-additions.txt to ignore-existing.txt.
  • Loading branch information
malikkotob authored and grasmash committed Apr 7, 2017
1 parent d50eb1c commit a3cb96a
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/blt-console
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use Acquia\Blt\Console\Command\ComposerMungeCommand;
use Acquia\Blt\Console\Command\SchemaVersionCommand;
use Acquia\Blt\Console\Command\YamlMungeCommand;
use Acquia\Blt\Console\Command\UpdateCommand;
use Acquia\Blt\Console\Command\TextMungeCommand;
use Symfony\Component\Console\Application;

set_time_limit(0);
Expand All @@ -28,5 +29,6 @@ $application->add(new ComposerMungeCommand());
$application->add(new SchemaVersionCommand());
$application->add(new UpdateCommand());
$application->add(new YamlMungeCommand());
$application->add(new TextMungeCommand());

$application->run();
1 change: 1 addition & 0 deletions phing/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ deploy:
build-dependencies: true
dir: ${repo.root}/deploy
exclude_file: ${blt.root}/phing/files/deploy-exclude.txt
exclude_additions_file: ${repo.root}/blt/deploy-exclude-additions.txt
gitignore_file: ${blt.root}/phing/files/.gitignore

# File and Directory locations.
Expand Down
19 changes: 18 additions & 1 deletion phing/tasks/deploy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,25 @@
</target>

<target name="deploy:copy" description="Copy required files from each /docroot/sites to /deploy/docroot/sites." hidden="true">
<property name="deploy.exclusions" value="${deploy.exclude_file}"/>
<!-- Check for existence of the exclude_additions_file. -->
<if>
<available file="${deploy.exclude_additions_file}"/>
<then>
<echo>Combining exclusions from deploy-exclude-additions and deploy-exclude files...</echo>
<exec dir="${repo.root}" command="${composer.bin}/blt-console text:munge ${deploy.exclude_file} ${deploy.exclude_additions_file} > ${deploy.exclude_file}.tmp" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<property name="deploy.exclusions" value="${deploy.exclude_file}.tmp" override="true"/>
</then>
</if>
<foreach list="${multisite.name}" param="multisite.name" target="deploy:copy:site:perms-writable"/>
<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"/>
<exec dir="${repo.root}" command="rsync -a --no-g --delete --delete-excluded --exclude-from=${deploy.exclusions} ${repo.root}/ ${deploy.dir}/ --filter 'protect /.git/'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<if>
<available file="${deploy.exclude_file}.tmp"/>
<then>
<!-- Get rid of the temporary file we created. -->
<exec dir="${repo.root}" command="rm ${deploy.exclude_file}.tmp" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</then>
</if>
<foreach list="${multisite.name}" param="multisite.name" target="deploy:copy:site:perms-unwritable"/>

<!-- Use our own .gitignore -->
Expand Down
6 changes: 6 additions & 0 deletions readme/extending-blt.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ To modify the behavior of the `deploy:build` target, you may override BLT's `dep
build-dependencies: true
dir: ${repo.root}/deploy
exclude_file: ${blt.root}/phing/files/deploy-exclude.txt
exclude_additions_file: ${repo.root}/blt/deploy-exclude-additions.txt
gitignore_file: ${blt.root}/phing/files/.gitignore

More specifically, you can modify the build artifact in the following key ways:
Expand All @@ -117,6 +118,11 @@ More specifically, you can modify the build artifact in the following key ways:
deploy:
exclude_file: ${repo.root}/blt/deploy/rsync-exclude.txt

1. If you'd simply like to add onto the [upstream deploy-exclude.txt](https://github.com/acquia/blt/blob/8.x/phing/files/deploy-exclude.txt) instead of overriding it, you need not define your own `deploy.exclude_file`. Instead, simply leverage the `deploy-exclude-additions.txt` file found under the top-level `blt` directory by adding each file or directory you'd like to exclude on its own line. E.g.,

/directorytoexclude
excludeme.txt

1. Change which files are gitignored in the artifact by providing your own `deploy.gitignore_file` value in project.yml. See [upstream .gitignore](https://github.com/acquia/blt/blob/8.x/phing/files/.gitignore) for example contents. E.g.,

deploy:
Expand Down
1 change: 1 addition & 0 deletions scripts/blt/ignore-existing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.gitattributes
.gitignore
blt/composer.overrides.json
blt/deploy-exclude-additions.txt
blt/example.project.local.yml
blt/project.yml
composer.json
Expand Down
81 changes: 81 additions & 0 deletions src/Console/Command/TextMungeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Acquia\Blt\Console\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
*
*/
class TextMungeCommand extends BaseCommand {

/**
* ${inheritdoc}.
*/
protected function configure() {
$this
->setName('text:munge')
->setAliases(['txt:munge'])
->setDescription('Munge values in two text|txt files')
->addArgument(
'file1',
InputArgument::REQUIRED,
'The first text or txt.'
)
->addArgument(
'file2',
InputArgument::REQUIRED,
'The second text or txt.'
);
}

/**
* ${inheritdoc}.
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$file1 = $input->getArgument('file1');
$file2 = $input->getArgument('file2');
$munged_contents = $this->munge($file1, $file2);
$output->writeln($munged_contents);
}

/**
* Merges the arrays in two text files.
*
* @param string $file1
* The file path of the first file.
* @param string $file2
* The file path of the second file.
*
* @return string
* The merged arrays, in yaml format.
*/
protected function munge($file1, $file2) {
$file1_contents = file($file1);
$file2_contents = file($file2);

$munged_contents = self::arrayMergeNoDuplicates($file1_contents, $file2_contents);

return $munged_contents;
}

/**
* Merges two arrays and removes duplicate values.
*
* @param array $array1
* The first array.
* @param array $array2
* The second array.
*
* @return array
*/
public static function arrayMergeNoDuplicates(array &$array1, array &$array2) {
$merged = array_merge($array1, $array2);
$merged_without_dups = array_unique($merged);

return $merged_without_dups;
}

}
Empty file.
99 changes: 99 additions & 0 deletions tests/phpunit/Blt/TextMungeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Acquia\Blt\Tests\Blt;

use Acquia\Blt\Console\Command\TextMungeCommand;

/**
* Tests text:munge command in blt-console.
*/
class TextMungeCommandTest extends \PHPUnit_Framework_TestCase {

/**
* Tests arrayMergeNoDuplicates().
*
* @dataProvider getValueProvider
*/
public function testArrayMergeNoDuplicates(
$array1,
$array2,
$expected_array
) {
$this->assertEquals(TextMungeCommand::arrayMergeNoDuplicates($array1,
$array2), $expected_array);
}

/**
* Provides values to testArrayMergeNoDuplicates().
*
* @return array
* An array of values to test.
*/
public function getValueProvider() {
return [
[
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
],
[
'/.vagrant',
'/acquia-pipelines.yml',
'/blt.sh',
'/box',
'/build',
'/additionalfile.txt',
],
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
'/blt.sh',
'/box',
'/build',
'/additionalfile.txt',
],
],
[
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
],
[],
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
],
],
[
[],
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
],
[
'/.drush-use',
'/.idea',
'/.travis.yml',
'/.vagrant',
'/acquia-pipelines.yml',
],
],
];
}

}

0 comments on commit a3cb96a

Please sign in to comment.