Skip to content

Commit b0f9700

Browse files
committed
feat: cobuild runner id
1 parent d7a5062 commit b0f9700

18 files changed

+169
-32
lines changed

build-tests/rush-redis-cobuild-plugin-integration-test/.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{
3535
"type": "shell",
3636
"label": "build 1",
37-
"command": "node ../../lib/runRush.js --debug cobuild --parallelism 1 --verbose",
37+
"command": "node ../../lib/runRush.js --debug cobuild --timeline --parallelism 1 --verbose",
3838
"problemMatcher": [],
3939
"options": {
4040
"cwd": "${workspaceFolder}/sandbox/repo",
@@ -57,7 +57,7 @@
5757
{
5858
"type": "shell",
5959
"label": "build 2",
60-
"command": "node ../../lib/runRush.js --debug cobuild --parallelism 1 --verbose",
60+
"command": "node ../../lib/runRush.js --debug cobuild --timeline --parallelism 1 --verbose",
6161
"problemMatcher": [],
6262
"options": {
6363
"cwd": "${workspaceFolder}/sandbox/repo",

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@
174174
"name": "@rushstack/package-extractor",
175175
"allowedCategories": [ "libraries" ]
176176
},
177-
{
178-
"name": "@rushstack/rush-redis-cobuild-plugin",
179-
"allowedCategories": [ "tests" ]
180-
},
181177
{
182178
"name": "@rushstack/rig-package",
183179
"allowedCategories": [ "libraries" ]
@@ -194,6 +190,10 @@
194190
"name": "@rushstack/rush-http-build-cache-plugin",
195191
"allowedCategories": [ "libraries" ]
196192
},
193+
{
194+
"name": "@rushstack/rush-redis-cobuild-plugin",
195+
"allowedCategories": [ "tests" ]
196+
},
197197
{
198198
"name": "@rushstack/rush-sdk",
199199
"allowedCategories": [ "libraries", "tests" ]
@@ -738,6 +738,10 @@
738738
"name": "url-loader",
739739
"allowedCategories": [ "libraries" ]
740740
},
741+
{
742+
"name": "uuid",
743+
"allowedCategories": [ "libraries" ]
744+
},
741745
{
742746
"name": "webpack",
743747
"allowedCategories": [ "libraries", "tests" ]

common/config/rush/pnpm-lock.yaml

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/repo-state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
22
{
3-
"pnpmShrinkwrapHash": "e42ca74053e55c066f8ce4291d494a77ebd367fa",
3+
"pnpmShrinkwrapHash": "03f6c90980f46e8036baf7f321d98c778148cb22",
44
"preferredVersionsHash": "1926a5b12ac8f4ab41e76503a0d1d0dccc9c0e06"
55
}

common/reviews/api/rush-lib.api.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ export class CobuildConfiguration {
102102
readonly cobuildLeafProjectLogOnlyAllowed: boolean;
103103
// (undocumented)
104104
get cobuildLockProvider(): ICobuildLockProvider;
105+
readonly cobuildRunnerId: string;
105106
// (undocumented)
106107
get contextId(): string | undefined;
107108
// (undocumented)
108-
createLockProviderAsync(): Promise<void>;
109+
createLockProviderAsync(terminal: ITerminal): Promise<void>;
109110
// (undocumented)
110111
destroyLockProviderAsync(): Promise<void>;
111112
// (undocumented)
@@ -173,6 +174,7 @@ export class EnvironmentConfiguration {
173174
static get cobuildContextId(): string | undefined;
174175
static get cobuildEnabled(): boolean | undefined;
175176
static get cobuildLeafProjectLogOnlyAllowed(): boolean | undefined;
177+
static get cobuildRunnerId(): string | undefined;
176178
// Warning: (ae-forgotten-export) The symbol "IEnvironment" needs to be exported by the entry point index.d.ts
177179
//
178180
// @internal
@@ -207,6 +209,7 @@ export const EnvironmentVariableNames: {
207209
readonly RUSH_BUILD_CACHE_WRITE_ALLOWED: "RUSH_BUILD_CACHE_WRITE_ALLOWED";
208210
readonly RUSH_COBUILD_ENABLED: "RUSH_COBUILD_ENABLED";
209211
readonly RUSH_COBUILD_CONTEXT_ID: "RUSH_COBUILD_CONTEXT_ID";
212+
readonly RUSH_COBUILD_RUNNER_ID: "RUSH_COBUILD_RUNNER_ID";
210213
readonly RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED: "RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED";
211214
readonly RUSH_GIT_BINARY_PATH: "RUSH_GIT_BINARY_PATH";
212215
readonly RUSH_TAR_BINARY_PATH: "RUSH_TAR_BINARY_PATH";
@@ -452,6 +455,7 @@ export interface _INpmOptionsJson extends IPackageManagerOptionsJsonBase {
452455

453456
// @alpha
454457
export interface IOperationExecutionResult {
458+
readonly cobuildRunnerId: string | undefined;
455459
readonly error: Error | undefined;
456460
readonly nonCachedDurationMs: number | undefined;
457461
readonly status: OperationStatus;
@@ -461,6 +465,10 @@ export interface IOperationExecutionResult {
461465

462466
// @internal (undocumented)
463467
export interface _IOperationMetadata {
468+
// (undocumented)
469+
cobuildContextId: string | undefined;
470+
// (undocumented)
471+
cobuildRunnerId: string | undefined;
464472
// (undocumented)
465473
durationInSeconds: number;
466474
// (undocumented)
@@ -520,6 +528,10 @@ export interface _IOperationStateFileOptions {
520528

521529
// @internal (undocumented)
522530
export interface _IOperationStateJson {
531+
// (undocumented)
532+
cobuildContextId: string | undefined;
533+
// (undocumented)
534+
cobuildRunnerId: string | undefined;
523535
// (undocumented)
524536
nonCachedDurationMs: number;
525537
}
@@ -725,7 +737,7 @@ export class _OperationMetadataManager {
725737
constructor(options: _IOperationMetadataManagerOptions);
726738
get relativeFilepaths(): string[];
727739
// (undocumented)
728-
saveAsync({ durationInSeconds, logPath, errorLogPath }: _IOperationMetadata): Promise<void>;
740+
saveAsync({ durationInSeconds, cobuildContextId, cobuildRunnerId, logPath, errorLogPath }: _IOperationMetadata): Promise<void>;
729741
// (undocumented)
730742
readonly stateFile: _OperationStateFile;
731743
// (undocumented)

libraries/rush-lib/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"strict-uri-encode": "~2.0.0",
5757
"tapable": "2.2.1",
5858
"tar": "~6.1.11",
59-
"true-case-path": "~2.2.1"
59+
"true-case-path": "~2.2.1",
60+
"uuid": "~8.3.2"
6061
},
6162
"devDependencies": {
6263
"@pnpm/logger": "4.0.0",
@@ -79,6 +80,7 @@
7980
"@types/ssri": "~7.1.0",
8081
"@types/strict-uri-encode": "2.0.0",
8182
"@types/tar": "6.1.1",
83+
"@types/uuid": "~8.3.4",
8284
"@types/webpack-env": "1.18.0",
8385
"webpack": "~5.80.0"
8486
},

libraries/rush-lib/src/api/CobuildConfiguration.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import schemaJson from '../schemas/cobuild.schema.json';
77
import { EnvironmentConfiguration } from './EnvironmentConfiguration';
88
import { CobuildLockProviderFactory, RushSession } from '../pluginFramework/RushSession';
99
import { RushConstants } from '../logic/RushConstants';
10+
import { v4 as uuidv4 } from 'uuid';
1011

1112
import type { ICobuildLockProvider } from '../logic/cobuild/ICobuildLockProvider';
1213
import type { RushConfiguration } from './RushConfiguration';
@@ -54,6 +55,12 @@ export class CobuildConfiguration {
5455
* The cobuild feature won't be enabled until the context id is provided as an non-empty string.
5556
*/
5657
public readonly cobuildContextId: string | undefined;
58+
59+
/**
60+
* This is a name of the participating cobuild runner. It can be specified by the environment variable
61+
* RUSH_COBUILD_RUNNER_ID. If it is not provided, a random id will be generated to identify the runner.
62+
*/
63+
public readonly cobuildRunnerId: string;
5764
/**
5865
* If true, Rush will automatically handle the leaf project with build cache "disabled" by writing
5966
* to the cache in a special "log files only mode". This is useful when you want to use Cobuilds
@@ -70,6 +77,7 @@ export class CobuildConfiguration {
7077

7178
this.cobuildEnabled = EnvironmentConfiguration.cobuildEnabled ?? cobuildJson.cobuildEnabled;
7279
this.cobuildContextId = EnvironmentConfiguration.cobuildContextId;
80+
this.cobuildRunnerId = EnvironmentConfiguration.cobuildRunnerId || uuidv4();
7381
this.cobuildLeafProjectLogOnlyAllowed =
7482
EnvironmentConfiguration.cobuildLeafProjectLogOnlyAllowed ?? false;
7583
if (!this.cobuildContextId) {
@@ -129,8 +137,9 @@ export class CobuildConfiguration {
129137
return this.cobuildContextId;
130138
}
131139

132-
public async createLockProviderAsync(): Promise<void> {
140+
public async createLockProviderAsync(terminal: ITerminal): Promise<void> {
133141
if (this.cobuildEnabled) {
142+
terminal.writeLine(`Running cobuild (runner ${this.cobuildContextId}/${this.cobuildRunnerId})`);
134143
const cobuildLockProvider: ICobuildLockProvider = await this._cobuildLockProviderFactory(
135144
this._cobuildJson
136145
);

libraries/rush-lib/src/api/EnvironmentConfiguration.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ export const EnvironmentVariableNames = {
163163
*/
164164
RUSH_COBUILD_CONTEXT_ID: 'RUSH_COBUILD_CONTEXT_ID',
165165

166+
/**
167+
* Explicitly specifies a name for each participating cobuild runner.
168+
*
169+
* Setting this environment variable opt into running with cobuilds.
170+
*
171+
* @remarks
172+
* This environment variable is optional, if it is not provided, a random id is used.
173+
*
174+
* If there is no cobuild configured, then this environment variable is ignored.
175+
*/
176+
RUSH_COBUILD_RUNNER_ID: 'RUSH_COBUILD_RUNNER_ID',
177+
166178
/**
167179
* If this variable is set to "1", When getting distributed builds, Rush will automatically handle the leaf project
168180
* with build cache "disabled" by writing to the cache in a special "log files only mode". This is useful when you
@@ -233,6 +245,8 @@ export class EnvironmentConfiguration {
233245

234246
private static _cobuildContextId: string | undefined;
235247

248+
private static _cobuildRunnerId: string | undefined;
249+
236250
private static _cobuildLeafProjectLogOnlyAllowed: boolean | undefined;
237251

238252
private static _gitBinaryPath: string | undefined;
@@ -350,6 +364,15 @@ export class EnvironmentConfiguration {
350364
return EnvironmentConfiguration._cobuildContextId;
351365
}
352366

367+
/**
368+
* Provides a determined cobuild runner id if configured
369+
* See {@link EnvironmentVariableNames.RUSH_COBUILD_RUNNER_ID}
370+
*/
371+
public static get cobuildRunnerId(): string | undefined {
372+
EnvironmentConfiguration._ensureValidated();
373+
return EnvironmentConfiguration._cobuildRunnerId;
374+
}
375+
353376
/**
354377
* If set, enables or disables the cobuild leaf project log only feature.
355378
* See {@link EnvironmentVariableNames.RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED}
@@ -503,6 +526,11 @@ export class EnvironmentConfiguration {
503526
break;
504527
}
505528

529+
case EnvironmentVariableNames.RUSH_COBUILD_RUNNER_ID: {
530+
EnvironmentConfiguration._cobuildRunnerId = value;
531+
break;
532+
}
533+
506534
case EnvironmentVariableNames.RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED: {
507535
EnvironmentConfiguration._cobuildLeafProjectLogOnlyAllowed =
508536
EnvironmentConfiguration.parseBooleanEnvironmentVariable(

libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
320320
this.rushConfiguration,
321321
this.rushSession
322322
);
323-
await cobuildConfiguration?.createLockProviderAsync();
323+
await cobuildConfiguration?.createLockProviderAsync(terminal);
324324
}
325325

326326
const projectSelection: Set<RushConfigurationProject> =

libraries/rush-lib/src/logic/operations/CacheableOperationPlugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,20 @@ export class CacheableOperationPlugin implements IPhasedCommandPlugin {
339339
runner.hooks.afterExecute.tapPromise(
340340
PLUGIN_NAME,
341341
async (afterExecuteContext: IOperationRunnerAfterExecuteContext) => {
342-
const { context, status, taskIsSuccessful } = afterExecuteContext;
342+
const { context, status, taskIsSuccessful, logPath, errorLogPath } = afterExecuteContext;
343343

344344
const { cobuildLock, projectBuildCache, isCacheWriteAllowed, buildCacheTerminal } = buildCacheContext;
345345

346+
// Save the metadata to disk
347+
const { duration: durationInSeconds } = context.stopwatch;
348+
await context._operationMetadataManager?.saveAsync({
349+
durationInSeconds,
350+
cobuildContextId: cobuildLock?.cobuildConfiguration.cobuildContextId,
351+
cobuildRunnerId: cobuildLock?.cobuildConfiguration.cobuildRunnerId,
352+
logPath,
353+
errorLogPath
354+
});
355+
346356
if (!buildCacheTerminal) {
347357
// This should not happen
348358
throw new InternalError(`Build Cache Terminal is not created`);

0 commit comments

Comments
 (0)