Skip to content

Commit

Permalink
Merge pull request #28 from moderntribe/fix/ci-message-not-a-tty
Browse files Browse the repository at this point in the history
Ensure exec does not run allocating a TTY
  • Loading branch information
lucatume authored Jul 2, 2020
2 parents 17b33ee + eae0ba4 commit a168ad8
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .env.tric
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ TRIC_WP_DIR=./_wordpress
# The build-prompt mode of tric. Set to `0` to avoid prompting/defaulting prompts for composer/npm builds during CLI operations.
TRIC_BUILD_PROMPT=1

# The build-subdir mode of tric. Set to `0` to avoid tric from prompting, and running, composer/npm commands during CLI operations.
TRIC_BUILD_SUBDIR=1

# The interactive mode of tric. Set to `0` to avoid prompts during CLI operations.
TRIC_INTERACTIVE=1

Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ 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.4.8] - 2020-07-02
### Added

- Added `tric build-subdir` which allows you to control whether sub-directories (e.g. `common` in The Events Calendar) should be built during composer/npm commands or not.

### Changed

- Fix an issue where the `build-prompt` status was reported incorrectly.

## [0.4.7] - 2020-07-01
### Changed

Expand Down
21 changes: 21 additions & 0 deletions src/commands/build-subdir.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tribe\Test;

if ( $is_help ) {
echo "Activates or deactivates whether or not composer/npm build should apply to sub-directories.\n";
echo PHP_EOL;
echo colorize( "signature: <light_cyan>{$cli_name} build-subdir (on|off|status)</light_cyan>\n" );
echo colorize( "example: <light_cyan>{$cli_name} build-subdir on</light_cyan>\n" );
echo colorize( "example: <light_cyan>{$cli_name} build-subdir off</light_cyan>\n" );
echo colorize( "example: <light_cyan>{$cli_name} build-subdir status</light_cyan>\n" );
return;
}

$subdir_args = args( [ 'toggle' ], $args( '...' ), 0 );

tric_handle_build_subdir( $subdir_args );

echo colorize( "\n\nToggle this setting by using: <light_cyan>tric build-subdir [on|off]</light_cyan>\n" );
echo colorize( "- on: composer/npm commands will apply to sub-directories.\n" );
echo colorize( "- off: composer/npm commands will NOT apply to sub-directories.\n" );
56 changes: 46 additions & 10 deletions src/tric.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ function tric_wp_dir( $path = '' ) {
* Prints the current build-prompt status to screen.
*/
function build_prompt_status() {
$enabled = getenv( 'TRIC_INTERACTIVE' );
$enabled = getenv( 'TRIC_BUILD_PROMPT' );

echo 'Interactive status is: ' . ( $enabled ? light_cyan( 'on' ) : magenta( 'off' ) ) . PHP_EOL;
}
Expand Down Expand Up @@ -790,13 +790,15 @@ function build_command_pool( string $base_command, array $command, array $sub_di
$using = tric_target();
$targets = [ 'target' ];

// Prompt for execution within subdirectories.
foreach ( $sub_directories as $dir ) {
if (
file_exists( tric_plugins_dir( "{$using}/{$dir}" ) )
&& ask( "\nWould you also like to run that {$base_command} command against {$dir}?", 'yes' )
) {
$targets[] = $dir;
// Prompt for execution within subdirectories if enabled.
if ( getenv( 'TRIC_BUILD_SUBDIR' ) ) {
foreach ( $sub_directories as $dir ) {
if (
file_exists( tric_plugins_dir( "{$using}/{$dir}" ) )
&& ask( "\nWould you also like to run that {$base_command} command against {$dir}?", 'yes' )
) {
$targets[] = $dir;
}
}
}

Expand Down Expand Up @@ -1079,7 +1081,7 @@ function fix_container_dir_file_modes( $service, $dir, $modes = 'a+rwx' ) {
$status = tric_realtime()( [ 'up', '-d', $service ] );

if ( 0 !== $status ) {
echo "\n" . magenta( 'Could not start the WordPress container.' );
echo "\n" . magenta( "Could not start the {$service} container." );
exit( 1 );
}

Expand All @@ -1090,11 +1092,45 @@ function fix_container_dir_file_modes( $service, $dir, $modes = 'a+rwx' ) {

// Recursively set file modes on the target directory.
$status = (int) tric_process()(
[ 'exec', '-u "0:0"', $service, 'chmod', '-R', $modes, $dir ]
[ 'exec', '-T', '-u "0:0"', $service, 'chmod', '-R', $modes, $dir ]
)( 'status' );
if ( 0 !== $status ) {
echo "\n" . magenta( "Could not fix {$service} file modes: {$dir} {$modes}." );
exit( 1 );
}
}
}

/**
* Handles the build-subdir command request.
*
* @param callable $args The closure that will produce the current subdirectories build arguments.
*/
function tric_handle_build_subdir( callable $args ) {
$run_settings_file = root( '/.env.tric.run' );
$toggle = $args( 'toggle', 'on' );

if ( 'status' === $toggle ) {
build_subdir_status();

return;
}

$value = 'on' === $toggle ? 1 : 0;
echo 'Build Sub-directories status: ' . ( $value ? light_cyan( 'on' ) : magenta( 'off' ) );

if ( $value === (int) getenv( 'TRIC_BUILD_SUBDIR' ) ) {
return;
}

write_env_file( $run_settings_file, [ 'TRIC_BUILD_SUBDIR' => $value ], true );
}

/**
* Prints the current build-subdir status to screen.
*/
function build_subdir_status() {
$enabled = getenv( 'TRIC_BUILD_SUBDIR' );

echo 'Sub-directories build status is: ' . ( $enabled ? light_cyan( 'on' ) : magenta( 'off' ) ) . PHP_EOL;
}
4 changes: 3 additions & 1 deletion tric
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $args = args( [
] );

$cli_name = basename( $argv[0] );
const CLI_VERSION = '0.4.7';
const CLI_VERSION = '0.4.8';

$cli_header = implode( ' - ', [
light_cyan( $cli_name ) . ' version ' . light_cyan( CLI_VERSION ),
Expand Down Expand Up @@ -67,6 +67,7 @@ Available commands:
<yellow>Info:</yellow>
<light_cyan>build-prompt</light_cyan> Activates or deactivates whether or not composer/npm build prompts should be provided.
<light_cyan>build-subdir</light_cyan> Activates or deactivates whether or not composer/npm build should apply to sub-directories.
<light_cyan>config</light_cyan> Prints the stack configuration as interpolated from the environment.
<light_cyan>debug</light_cyan> Activates or deactivates {$cli_name} debug output or returns the current debug status.
<light_cyan>help</light_cyan> Displays this help message.
Expand Down Expand Up @@ -111,6 +112,7 @@ switch ( $subcommand ) {
case 'airplane-mode':
case 'build-prompt':
case 'build-stack':
case 'build-subdir':
case 'cache':
case 'cc':
case 'cli':
Expand Down
2 changes: 2 additions & 0 deletions tric-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ services:
XDEBUG_DISABLE: "${XDEBUG_DISABLE:-0}"
# Declare that we are in a tric context so plugins can set custom test configs.
TRIBE_TRIC: 1
# If we're in CI context, then pass it through.
CI: "${CI:-}"
# Let's set the lines and columns number explicitly to have the shell mirror the current one.
LINES: "${LINES:-24}"
COLUMNS: "${COLUMNS:-80}"
Expand Down

0 comments on commit a168ad8

Please sign in to comment.