woocommerce/tools/monorepo-utils/src/index.ts

59 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { Command } from '@commander-js/extra-typings';
import figlet from 'figlet';
import chalk from 'chalk';
import dotenv from 'dotenv';
/**
* Internal dependencies
*/
import CodeFreeze from './code-freeze/commands';
import Slack from './slack/commands/slack';
import Manifest from './md-docs/commands';
import Changefile from './changefile';
Added Monorepo CI Command (#43345) * Added Config Object Types * Added CI Config Parsing * Added Package Loader This is a convenience method for loading the package JSON file with support for caching the files that have already been imported. * Removed Unnecessary Package Values * Specified Node Dependencies * Added Test Environment Config Parsing * Changed Internal Config Representation For convenience it makes more sense to have a single type of Job interface that we can process. This avoids having to complicate checks when we output them. * Added Workspace Dependency Graph Using `pnpm list` we are able to build a graph of all of the workspace projects and their dependencies. This can be used to handle change cascades across a project's dependencies. * Added Changed File Detection We can use `git` to figure out what files have changed and associate them with the respective projects. This will let us identify what jobs to run based on the changes that have happened to a project. * Added Test Environment Config Parsing Tests * Added CI Config To Project Graph In the interest of making it easier to process the jobs we will store the CI config in the graph nodes. * Changed Project Graph Build Output Our usage of the graph depends a lot on how we are choosing to use it. Instead of returning all of the nodes we will return the root. * Added Change-Based Job Creation We can now marry the config, file changes, and project graph to output jobs. This supports checking the changes as well as cascade keys for test jobs. * Added Job Test Env Parsing The ideal time to parse all of the config values for the job's test environment is when creating the job. * Added Command Index With everything in place we can now add the command. In addition to that, I've fixed a few bugs that appeared when testing out the command locally. Since we aren't changing the CI config in this PR we can't easily test the actual command. * Fixed Typo
2024-01-09 19:15:08 +00:00
import CIJobs from './ci-jobs';
import WorkflowProfiler from './workflow-profiler/commands';
import { Logger } from './core/logger';
import { isGithubCI } from './core/environment';
dotenv.config();
if ( ! isGithubCI() ) {
Logger.notice(
chalk
.rgb( 150, 88, 138 )
.bold( figlet.textSync( 'WooCommerce \n Utils' ) )
);
}
const program = new Command()
.name( 'utils' )
.description( 'Monorepo utilities' )
.addCommand( CodeFreeze )
.addCommand( Slack )
.addCommand( Changefile )
Added Monorepo CI Command (#43345) * Added Config Object Types * Added CI Config Parsing * Added Package Loader This is a convenience method for loading the package JSON file with support for caching the files that have already been imported. * Removed Unnecessary Package Values * Specified Node Dependencies * Added Test Environment Config Parsing * Changed Internal Config Representation For convenience it makes more sense to have a single type of Job interface that we can process. This avoids having to complicate checks when we output them. * Added Workspace Dependency Graph Using `pnpm list` we are able to build a graph of all of the workspace projects and their dependencies. This can be used to handle change cascades across a project's dependencies. * Added Changed File Detection We can use `git` to figure out what files have changed and associate them with the respective projects. This will let us identify what jobs to run based on the changes that have happened to a project. * Added Test Environment Config Parsing Tests * Added CI Config To Project Graph In the interest of making it easier to process the jobs we will store the CI config in the graph nodes. * Changed Project Graph Build Output Our usage of the graph depends a lot on how we are choosing to use it. Instead of returning all of the nodes we will return the root. * Added Change-Based Job Creation We can now marry the config, file changes, and project graph to output jobs. This supports checking the changes as well as cascade keys for test jobs. * Added Job Test Env Parsing The ideal time to parse all of the config values for the job's test environment is when creating the job. * Added Command Index With everything in place we can now add the command. In addition to that, I've fixed a few bugs that appeared when testing out the command locally. Since we aren't changing the CI config in this PR we can't easily test the actual command. * Fixed Typo
2024-01-09 19:15:08 +00:00
.addCommand( CIJobs )
.addCommand( WorkflowProfiler )
.addCommand( Manifest );
program.exitOverride();
const run = async () => {
try {
// parseAsync handles cases where the action is async and not async.
await program.parseAsync( process.argv );
} catch ( e ) {
// if github ci, always error
if ( isGithubCI() ) {
Logger.error( e );
} else if ( e.code !== 'commander.help' ) {
// if not github ci, only error if not help
Logger.error( e );
}
}
};
run();