Skip to content

Commit

Permalink
Merge pull request #65 from moderntribe/fix/using-containers-duplication
Browse files Browse the repository at this point in the history
Fix init issues
  • Loading branch information
lucatume authored Dec 10, 2020
2 parents 553d61a + 3039e4a commit fdabc1d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.18] - 2020-12-07
### Changed
- Fix an issue where the `USING_CONTAINERS` environment variable would be duplicated in environment files set up by
`tric` init command.
- Fix an issue where a negative answer to build targets with sub-directories, e.g. TEC and ET, would result in the
target being built anyway.

## [0.5.17] - 2020-12-04
### Changed

Expand Down
7 changes: 6 additions & 1 deletion src/scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ function write_tric_env_file( $plugin_path ) {
}
}

$plugin_env .= "\n# We're using Docker to run the tests.\nUSING_CONTAINERS=1\n";
if ( false === strpos( $plugin_env, 'USING_CONTAINERS=' ) ) {
$plugin_env .= "\n# We're using Docker to run the tests.\nUSING_CONTAINERS=1\n";
} else {
// In `tric`, we're most definitely using containers.
$plugin_env = str_replace( 'USING_CONTAINERS=0', 'USING_CONTAINERS=1', $plugin_env );
}

$file = $plugin_path . '/.env.testing.tric';
$put = file_put_contents( $file, $plugin_env );
Expand Down
45 changes: 19 additions & 26 deletions src/tric.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,23 +892,6 @@ function dir_has_req_build_file( $base_command, $path ) {
* @return array Result of command execution.
*/
function maybe_build_install_command_pool( $base_command, $target, array $sub_directories = [] ) {
$subdirs_to_check = [];

foreach ( $sub_directories as $sub_directory ) {
$subdirs_to_check[] = $target . DIRECTORY_SEPARATOR . $sub_directory;
}

$sub_has_build = false;

foreach ( $subdirs_to_check as $sub_check ) {
$path = tric_plugins_dir( $sub_check );

if ( dir_has_req_build_file( $base_command, $path ) ) {
$sub_has_build = true;
break;
}
}

// Only prompt if the target itself has has been identified as available to build. If any subs need to build, will auto-try.
if ( dir_has_req_build_file( $base_command, tric_plugins_dir( $target ) ) ) {
$run = ask(
Expand All @@ -917,14 +900,23 @@ function maybe_build_install_command_pool( $base_command, $target, array $sub_di
);
}

if (
empty( $run )
&& empty( $sub_has_build )
) {
if ( empty( $run ) ) {
// Do not run the command on sub-directories if not running on the target.
return [];
}

return build_command_pool( $base_command, [ 'install' ], $sub_directories );
$subdirs_to_build = array_reduce( $sub_directories, static function ( array $buffer, $sub_directory ) use (
$base_command
) {
$subdir_path = target_absolute_path( $sub_directory );
if ( dir_has_req_build_file( $base_command, $subdir_path ) ) {
$buffer[] = $sub_directory;
}

return $buffer;
}, [] );

return count( $subdirs_to_build ) ? build_command_pool( $base_command, [ 'install' ], $sub_directories ) : [];
}

/**
Expand Down Expand Up @@ -1336,8 +1328,10 @@ function tric_target_or_fail( $reason = null ) {
*
* @return string The absolute path to the current target.
*/
function absolute_plugin_target_path( $append_path = null ) {
$full_target_path = rtrim( getenv( 'TRIC_HERE_DIR' ), '\\/' ) . '/' . trim( tric_target(), '\\/' );
function target_absolute_path( $append_path = null ) {
$here_abs_path = rtrim( getenv( 'TRIC_HERE_DIR' ), '\\/' );
$target_rel_path = '/' . trim( tric_target(), '\\/' );
$full_target_path = $here_abs_path . $target_rel_path;
if ( empty( $append_path ) ) {
return $full_target_path;
}
Expand All @@ -1353,7 +1347,7 @@ function absolute_plugin_target_path( $append_path = null ) {
*/
function collect_target_suites() {
// If the command is just `run`, without arguments, then collect the available suites and run them separately.
$dir_iterator = new \DirectoryIterator( absolute_plugin_target_path( 'tests' ) );
$dir_iterator = new \DirectoryIterator( target_absolute_path( 'tests' ) );
$suitesFilter = new \CallbackFilterIterator( $dir_iterator, static function ( \SplFileInfo $file ) {
return $file->isFile() && preg_match( '/^.*\\.suite(\\.dist)?\\.yml$/', $file->getBasename() );
} );
Expand All @@ -1364,4 +1358,3 @@ function collect_target_suites() {

return $suites;
}

2 changes: 1 addition & 1 deletion tric
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $args = args( [
] );

$cli_name = basename( $argv[0] );
const CLI_VERSION = '0.5.17';
const CLI_VERSION = '0.5.18';

$cli_header = implode( ' - ', [
light_cyan( $cli_name ) . ' version ' . light_cyan( CLI_VERSION ),
Expand Down

0 comments on commit fdabc1d

Please sign in to comment.