Skip to content

Commit e3f116c

Browse files
committed
refact: clustering operations in cobuilds
1 parent 9a8fc06 commit e3f116c

File tree

19 files changed

+466
-213
lines changed

19 files changed

+466
-213
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"cwd": "${workspaceFolder}/sandbox/repo",
4141
"env": {
4242
"RUSH_COBUILD_CONTEXT_ID": "integration-test",
43+
"RUSH_COBUILD_RUNNER_ID": "runner1",
4344
"RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED": "1",
4445
"REDIS_PASS": "redis123"
4546
}
@@ -63,6 +64,7 @@
6364
"cwd": "${workspaceFolder}/sandbox/repo",
6465
"env": {
6566
"RUSH_COBUILD_CONTEXT_ID": "integration-test",
67+
"RUSH_COBUILD_RUNNER_ID": "runner2",
6668
"RUSH_COBUILD_LEAF_PROJECT_LOG_ONLY_ALLOWED": "1",
6769
"REDIS_PASS": "redis123"
6870
}

build-tests/rush-redis-cobuild-plugin-integration-test/config/heft.json

+4-43
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,11 @@
22
* Defines configuration used by core Heft.
33
*/
44
{
5-
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",
6-
7-
"eventActions": [
8-
{
9-
/**
10-
* The kind of built-in operation that should be performed.
11-
* The "deleteGlobs" action deletes files or folders that match the
12-
* specified glob patterns.
13-
*/
14-
"actionKind": "deleteGlobs",
15-
16-
/**
17-
* The stage of the Heft run during which this action should occur. Note that actions specified in heft.json
18-
* occur at the end of the stage of the Heft run.
19-
*/
20-
"heftEvent": "clean",
21-
22-
/**
23-
* A user-defined tag whose purpose is to allow configs to replace/delete handlers that were added by other
24-
* configs.
25-
*/
26-
"actionId": "defaultClean",
27-
28-
/**
29-
* Glob patterns to be deleted. The paths are resolved relative to the project folder.
30-
*/
31-
"globsToDelete": ["dist", "lib", "temp"]
32-
}
33-
],
5+
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
346

357
/**
36-
* The list of Heft plugins to be loaded.
8+
* Optionally specifies another JSON config file that this file extends from. This provides a way for standard
9+
* settings to be shared across multiple projects.
3710
*/
38-
"heftPlugins": [
39-
// {
40-
// /**
41-
// * The path to the plugin package.
42-
// */
43-
// "plugin": "path/to/my-plugin",
44-
//
45-
// /**
46-
// * An optional object that provides additional settings that may be defined by the plugin.
47-
// */
48-
// // "options": { }
49-
// }
50-
]
11+
"extends": "@rushstack/heft-node-rig/profiles/default/config/heft.json"
5112
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@microsoft/rush-lib": "workspace:*",
1414
"@rushstack/eslint-config": "workspace:*",
1515
"@rushstack/heft": "workspace:*",
16+
"@rushstack/heft-node-rig": "workspace:*",
1617
"@rushstack/node-core-library": "workspace:*",
1718
"@rushstack/rush-redis-cobuild-plugin": "workspace:*",
1819
"@types/http-proxy": "~1.17.8",

build-tests/rush-redis-cobuild-plugin-integration-test/src/testLockProvider.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ async function main(): Promise<void> {
2020
const lockProvider: RedisCobuildLockProvider = new RedisCobuildLockProvider(options, rushSession as any);
2121
await lockProvider.connectAsync();
2222
const context: ICobuildContext = {
23-
contextId: 'test-context-id',
24-
version: 1,
25-
cacheId: 'test-cache-id'
23+
contextId: 'context_id',
24+
cacheId: 'cache_id',
25+
lockKey: 'lock_key',
26+
lockExpireTimeInSeconds: 30,
27+
completedStateKey: 'completed_state_key',
28+
clusterId: 'cluster_id',
29+
runnerId: 'runner_id',
30+
packageName: 'package_name',
31+
phaseName: 'phase_name'
2632
};
2733
await lockProvider.acquireLockAsync(context);
2834
await lockProvider.renewLockAsync(context);
2935
await lockProvider.setCompletedStateAsync(context, {
3036
status: OperationStatus.Success,
31-
cacheId: 'test-cache-id'
37+
cacheId: 'cache_id'
3238
});
3339
const completedState = await lockProvider.getCompletedStateAsync(context);
3440
console.log('Completed state: ', completedState);

common/config/rush/pnpm-lock.yaml

+34-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/repo-state.json

+1-1
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": "343a65be71bc82e4e59e741b0c4d29b4eaf5c561",
3+
"pnpmShrinkwrapHash": "abf9008e956d819415ba592c72fb2f5750e33e27",
44
"preferredVersionsHash": "1926a5b12ac8f4ab41e76503a0d1d0dccc9c0e06"
55
}

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ export class CobuildConfiguration {
102102
get cobuildLockProvider(): ICobuildLockProvider;
103103
readonly cobuildRunnerId: string;
104104
// (undocumented)
105-
get contextId(): string | undefined;
106-
// (undocumented)
107105
createLockProviderAsync(terminal: ITerminal): Promise<void>;
108106
// (undocumented)
109107
destroyLockProviderAsync(): Promise<void>;
@@ -283,8 +281,14 @@ export interface ICobuildCompletedState {
283281
// @beta (undocumented)
284282
export interface ICobuildContext {
285283
cacheId: string;
284+
clusterId: string;
285+
completedStateKey: string;
286286
contextId: string;
287-
version: number;
287+
lockExpireTimeInSeconds: number;
288+
lockKey: string;
289+
packageName: string;
290+
phaseName: string;
291+
runnerId: string;
288292
}
289293

290294
// @beta (undocumented)
@@ -297,18 +301,12 @@ export interface ICobuildJson {
297301

298302
// @beta (undocumented)
299303
export interface ICobuildLockProvider {
300-
// (undocumented)
301-
acquireLockAsync(context: ICobuildContext): Promise<boolean>;
302-
// (undocumented)
304+
acquireLockAsync(context: Readonly<ICobuildContext>): Promise<boolean>;
303305
connectAsync(): Promise<void>;
304-
// (undocumented)
305306
disconnectAsync(): Promise<void>;
306-
// (undocumented)
307-
getCompletedStateAsync(context: ICobuildContext): Promise<ICobuildCompletedState | undefined>;
308-
// (undocumented)
309-
renewLockAsync(context: ICobuildContext): Promise<void>;
310-
// (undocumented)
311-
setCompletedStateAsync(context: ICobuildContext, state: ICobuildCompletedState): Promise<void>;
307+
getCompletedStateAsync(context: Readonly<ICobuildContext>): Promise<ICobuildCompletedState | undefined>;
308+
renewLockAsync(context: Readonly<ICobuildContext>): Promise<void>;
309+
setCompletedStateAsync(context: Readonly<ICobuildContext>, state: ICobuildCompletedState): Promise<void>;
312310
}
313311

314312
// @public
@@ -1061,7 +1059,6 @@ export class RushConstants {
10611059
static readonly bypassPolicyFlagLongName: '--bypass-policy';
10621060
static readonly changeFilesFolderName: string;
10631061
static readonly cobuildFilename: string;
1064-
static readonly cobuildLockVersion: number;
10651062
static readonly commandLineFilename: string;
10661063
static readonly commonFolderName: string;
10671064
static readonly commonVersionsFilename: string;

common/reviews/api/rush-redis-cobuild-plugin.api.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
/// <reference types="node" />
88

9-
import type { ICobuildCompletedState } from '@rushstack/rush-sdk';
10-
import type { ICobuildContext } from '@rushstack/rush-sdk';
11-
import type { ICobuildLockProvider } from '@rushstack/rush-sdk';
9+
import { ICobuildCompletedState } from '@rushstack/rush-sdk';
10+
import { ICobuildContext } from '@rushstack/rush-sdk';
11+
import { ICobuildLockProvider } from '@rushstack/rush-sdk';
1212
import type { IRushPlugin } from '@rushstack/rush-sdk';
1313
import type { RedisClientOptions } from '@redis/client';
1414
import type { RushConfiguration } from '@rushstack/rush-sdk';
15-
import type { RushSession } from '@rushstack/rush-sdk';
15+
import { RushSession } from '@rushstack/rush-sdk';
1616

1717
// @beta
1818
export interface IRedisCobuildLockProviderOptions extends RedisClientOptions {
@@ -22,7 +22,6 @@ export interface IRedisCobuildLockProviderOptions extends RedisClientOptions {
2222
// @beta (undocumented)
2323
export class RedisCobuildLockProvider implements ICobuildLockProvider {
2424
constructor(options: IRedisCobuildLockProviderOptions, rushSession: RushSession);
25-
// (undocumented)
2625
acquireLockAsync(context: ICobuildContext): Promise<boolean>;
2726
// (undocumented)
2827
connectAsync(): Promise<void>;
@@ -32,8 +31,6 @@ export class RedisCobuildLockProvider implements ICobuildLockProvider {
3231
static expandOptionsWithEnvironmentVariables(options: IRedisCobuildLockProviderOptions, environment?: NodeJS.ProcessEnv): IRedisCobuildLockProviderOptions;
3332
// (undocumented)
3433
getCompletedStateAsync(context: ICobuildContext): Promise<ICobuildCompletedState | undefined>;
35-
getCompletedStateKey(context: ICobuildContext): string;
36-
getLockKey(context: ICobuildContext): string;
3734
// (undocumented)
3835
renewLockAsync(context: ICobuildContext): Promise<void>;
3936
// (undocumented)

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

-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ export class CobuildConfiguration {
133133
});
134134
}
135135

136-
public get contextId(): string | undefined {
137-
return this.cobuildContextId;
138-
}
139-
140136
public async createLockProviderAsync(terminal: ITerminal): Promise<void> {
141137
if (this.cobuildEnabled) {
142138
terminal.writeLine(`Running cobuild (runner ${this.cobuildContextId}/${this.cobuildRunnerId})`);

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ export const EnvironmentVariableNames = {
156156
RUSH_COBUILD_ENABLED: 'RUSH_COBUILD_ENABLED',
157157

158158
/**
159-
* Setting this environment variable opt into running with cobuilds.
159+
* Setting this environment variable opt into running with cobuilds. The context id should be the same across
160+
* multiple VMs, but changed when it is a new round of cobuilds.
161+
*
162+
* e.g. `Build.BuildNumber` in Azure DevOps Pipeline.
160163
*
161164
* @remarks
162165
* If there is no cobuild configured, then this environment variable is ignored.

libraries/rush-lib/src/logic/RushConstants.ts

-6
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ export class RushConstants {
187187
*/
188188
public static readonly cobuildFilename: string = 'cobuild.json';
189189

190-
/**
191-
* Cobuild version number, incremented when the logic to create cobuild lock changes.
192-
* Changing this ensures that lock generated by an old version will no longer access as a cobuild lock.
193-
*/
194-
public static readonly cobuildLockVersion: number = 1;
195-
196190
/**
197191
* Per-project configuration filename.
198192
*/

0 commit comments

Comments
 (0)