Update changelogger validation to work with turborepo (#33388)

* Update changelogger validation to work with turborepo

* Update file_get_contents call to include base_path
This commit is contained in:
jonathansadowski 2022-06-10 15:23:14 -05:00 committed by GitHub
parent 9d98f1b1da
commit 1fe5137152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 18 deletions

View File

@ -86,26 +86,20 @@ if ( $verbose ) {
$base_path = dirname( dirname( __DIR__ ) ); $base_path = dirname( dirname( __DIR__ ) );
// Read workspace.json file to find potential composer files. $workspace_paths = array();
try { $workspace_yaml = file_get_contents( $base_path . '/pnpm-workspace.yaml' );
$workspace = json_decode( file_get_contents( $base_path . '/workspace.json' ), true, 10, JSON_THROW_ON_ERROR ); if ( preg_match( '/^packages:((\n\s+.+)+)/', $workspace_yaml, $matches ) ) {
} catch ( Exception $e ) { $packages_config = $matches[1];
$workspace = false; if ( preg_match_all( "/^\s+-\s?'([^']+)'/m", $packages_config, $matches ) ) {
} $workspace_paths = $matches[1];
if ( ! $workspace || ! is_array( $workspace['projects'] ) ) { }
debug( 'Unable to parse workspace file' );
exit( 1 );
} }
$composer_projects = array(); $composer_files = array_map( function( $path ) {
foreach( $workspace['projects'] as $project => $directory ) { return glob( $path . '/composer.json' );
if ( $path && $directory !== $path ) { }, $workspace_paths );
continue; $composer_files = array_merge( ...$composer_files );
} $composer_projects = array_map( 'dirname', $composer_files );
if ( file_exists( $base_path . '/' . $directory . '/composer.json' ) ) {
$composer_projects[] = $directory;
}
}
if ( $path && ! count( $composer_projects ) ) { if ( $path && ! count( $composer_projects ) ) {
debug( sprintf( 'The provided project path, %s, did not contain a composer file.', $path ) ); debug( sprintf( 'The provided project path, %s, did not contain a composer file.', $path ) );