Skip to content

Commit e88d208

Browse files
authored
Merge pull request #17 from moderntribe/feature/prompt-for-update
Prompt user to update if tric version mismatches current build version
2 parents 89ddde5 + 49e9fee commit e88d208

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ _plugins
2525
# Any .env.tric.* file created to override the tric cli tool configuration or to configure the runs.
2626
.env.tric.local
2727
.env.tric.run
28+
29+
# Any .build-version file created by the tric cli tool.
30+
.build-version

changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [0.3.0] - TBD
88
### Added
99

10+
- Prompt to `tric update` when container build version are out of sync from the tric version.
11+
- Output npm error log when one is generated.
12+
1013
### Changed
1114

1215
- Separated out poolable (passive) command functions from realtime command functions to prevent issues with interactivity.
@@ -15,10 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1518
### Added
1619

1720
- Added phpcs and phpcbf commands.
21+
- Added parallel processing of commands.
1822

1923
### Changed
2024

21-
- Added parallel processing of commands.
2225
- Changed `tric build` to `tric build-stack`.
2326

2427
## [0.1.1] - 2020-05-26

containers/npm/docker-entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@
66
test "${FIXUID:-1}" != "0" && eval "$( fixuid )"
77

88
npm --prefix /project "$@"
9+
10+
# Output error logs if present.
11+
if compgen -G "/home/node/.npm/_logs/*.log" > /dev/null; then
12+
echo "---------------------------------------"
13+
echo "Error log found. Here are the contents (excluding the overly verbose saveTree lines):"
14+
echo "---------------------------------------"
15+
cat /home/node/.npm/_logs/*.log | grep -v "saveTree"
16+
echo "---------------------------------------"
17+
echo "End of error log"
18+
echo "---------------------------------------"
19+
fi

src/tric.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,18 @@ function teardown_stack() {
457457
*/
458458
function rebuild_stack() {
459459
echo "Building the stack images...\n\n";
460-
tric_realtime()( [ 'build-stack' ] );
460+
tric_realtime()( [ 'build' ] );
461+
write_build_version();
461462
echo light_cyan( "\nStack images built.\n\n" );
462463
}
463464

465+
/**
466+
* Write the current CLI_VERSION to the build-version file
467+
*/
468+
function write_build_version() {
469+
file_put_contents( TRIC_ROOT_DIR . '/.build-version', CLI_VERSION );
470+
}
471+
464472
/**
465473
* Prints information about tric tool.
466474
*/
@@ -929,3 +937,37 @@ function switch_plugin_branch( $branch, $plugin = null ) {
929937
exit( 1 );
930938
}
931939
}
940+
941+
/**
942+
* If tric stack is out of date, prompt for an execution of tric update.
943+
*/
944+
function maybe_prompt_for_update() {
945+
$build_version = '0.0.1';
946+
$cli_version = CLI_VERSION;
947+
948+
if ( file_exists( TRIC_ROOT_DIR . '/.build-version' ) ) {
949+
$build_version = file_get_contents( TRIC_ROOT_DIR . '/.build-version' );
950+
}
951+
952+
// If there isn't a .env.tric.run, this is likely a fresh install. Bail.
953+
if ( ! file_exists( TRIC_ROOT_DIR . '/.env.tric.run' ) ) {
954+
return;
955+
}
956+
957+
// If the version of the CLI is the same as the most recently built version, bail.
958+
if ( version_compare( $build_version, $cli_version, '=' ) ) {
959+
return;
960+
}
961+
962+
echo magenta( "\n****************************************************************\n\n" );
963+
echo yellow( " ____________ ____ __\n" );
964+
echo yellow( " | ____\ \ / / | |\n" );
965+
echo yellow( " | |__ \ \/ / | |\n" );
966+
echo yellow( " | __| \_ _/ | |\n" );
967+
echo yellow( " | | | | | |\n" );
968+
echo yellow( " |__| |__| |__|\n\n" );
969+
echo magenta( "Your tric containers are not up to date with the latest version.\n" );
970+
echo magenta( " To update, please run:\n\n" );
971+
echo yellow( " tric update\n\n" );
972+
echo magenta( "****************************************************************\n" );
973+
}

src/utils.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ function write_env_file( $file, array $lines = [], $update = false ) {
407407
return "{$key}={$value}";
408408
}, array_keys( $new_lines ), $new_lines ) );
409409

410+
// If this is the first time creating the .env.tric.run file, assume this is the first run and place the CLI version in `.build-version`.
411+
if ( false !== strpos( $file, '.env.tric.run' ) && ! file_exists( $file ) ) {
412+
write_build_version();
413+
}
414+
410415
$put = file_put_contents( $file, $data );
411416

412417
if ( false === $put ) {

tric

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use function Tribe\Test\args;
1414
use function Tribe\Test\colorize;
1515
use function Tribe\Test\root;
1616
use function Tribe\Test\light_cyan;
17+
use function Tribe\Test\maybe_prompt_for_update;
1718
use function Tribe\Test\setup_tric_env;
1819

1920
// Set up the argument parsing function.
@@ -90,10 +91,15 @@ $subcommand = $args( 'subcommand', 'help' );
9091

9192
$cli_name = basename( $argv[0] );
9293

94+
if ( ! in_array( $subcommand, [ 'help', 'update'] ) ) {
95+
maybe_prompt_for_update();
96+
}
97+
9398
switch ( $subcommand ) {
9499
default:
95100
case 'help':
96101
echo $help_message;
102+
maybe_prompt_for_update();
97103
break;
98104
case 'airplane-mode':
99105
case 'build-prompt':

0 commit comments

Comments
 (0)