Skip to content

Commit b08da17

Browse files
committed
chore: migrate redis cobuild test repo to use phases
1 parent e3f116c commit b08da17

File tree

18 files changed

+187
-46
lines changed

18 files changed

+187
-46
lines changed

build-tests/rush-redis-cobuild-plugin-integration-test/README.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,74 +35,74 @@ Sandbox repo folder: **build-tests/rush-redis-cobuild-plugin-integration-test/sa
3535

3636
```sh
3737
cd sandbox/repo
38-
rush update
38+
node ../../lib/runRush.js update
3939
```
4040

41-
## Case 1: Disable cobuild by setting `RUSH_COBUILD_ENABLED=0`
41+
## Case 1: Normal build, Cobuild is disabled because of missing RUSH_COBUILD_CONTEXT_ID
4242

43-
```sh
44-
rm -rf common/temp/build-cache && RUSH_COBUILD_ENABLED=0 REDIS_PASS=redis123 node ../../lib/runRush.js --debug cobuild
45-
```
46-
47-
Expected behavior: Cobuild feature is disabled. Run command successfully.
43+
1. Write to build cache
4844

4945
```sh
50-
RUSH_COBUILD_ENABLED=0 REDIS_PASS=redis123 node ../../lib/runRush.js --debug cobuild
46+
rm -rf common/temp/build-cache && node ../../lib/runRush.js --debug cobuild
5147
```
5248

53-
Expected behavior: Cobuild feature is disabled. Build cache was restored successfully.
54-
55-
## Case 2: Cobuild enabled without specifying RUSH_COBUILD_CONTEXT_ID
56-
57-
Run `rush cobuild` command without specifying cobuild context id.
49+
2. Read from build cache
5850

5951
```sh
60-
rm -rf common/temp/build-cache && REDIS_PASS=redis123 node ../../lib/runRush.js --debug cobuild
52+
node ../../lib/runRush.js --debug cobuild
6153
```
6254

63-
Expected behavior: Cobuild feature is disabled. Build cache was restored successfully.
55+
Expected behavior: Cobuild feature is disabled. Build cache is saved/restored as normal.
6456

65-
## Case 3: Cobuild enabled, run one cobuild command only
57+
# Case 2: Cobuild enabled by specifying RUSH_COBUILD_CONTEXT_ID and Redis authentication
6658

6759
1. Clear redis server
6860

6961
```sh
7062
(cd ../.. && docker compose down && docker compose up -d)
7163
```
7264

73-
2. Run `rush cobuild` command
65+
2. Run cobuilds
7466

7567
```sh
76-
rm -rf common/temp/build-cache && RUSH_COBUILD_CONTEXT_ID=foo REDIS_PASS=redis123 node ../../lib/runRush.js --debug cobuild
68+
rm -rf common/temp/build-cache && RUSH_COBUILD_CONTEXT_ID=foo REDIS_PASS=redis123 RUSH_COBUILD_RUNNER_ID=runner1 node ../../lib/runRush.js --debug cobuild
7769
```
7870

7971
Expected behavior: Cobuild feature is enabled. Run command successfully.
8072
You can also see cobuild related logs in the terminal.
8173

8274
```sh
83-
Get completed state for cobuild:v1:foo:c2df36270ec5faa8ef6497fa7367a476de3e2861:completed: null
84-
Acquired lock for cobuild:v1:foo:c2df36270ec5faa8ef6497fa7367a476de3e2861:lock: 1, 1 is success
85-
Set completed state for cobuild:v1:foo:c2df36270ec5faa8ef6497fa7367a476de3e2861:completed: SUCCESS;c2df36270ec5faa8ef6497fa7367a476de3e2861
75+
Running cobuild (runner foo/runner1)
76+
Analyzing repo state... DONE (0.11 seconds)
77+
78+
Executing a maximum of 10 simultaneous processes...
79+
80+
==[ b (build) ]====================================================[ 1 of 9 ]==
81+
Get completed_state(cobuild:completed:foo:2e477baf39a85b28fc40e63b417692fe8afcc023)_package(b)_phase(_phase:build): SUCCESS;2e477baf39a85b28fc40e63b417692fe8afcc023
82+
Get completed_state(cobuild:completed:foo:cfc620db4e74a6f0db41b1a86d0b5402966b97f3)_package(a)_phase(_phase:build): SUCCESS;cfc620db4e74a6f0db41b1a86d0b5402966b97f3
83+
Successfully acquired lock(cobuild:lock:foo:4c36160884a7a502f9894e8f0adae05c45c8cc4b)_package(b)_phase(_phase:build) to runner(runner1) and it expires in 30s
8684
```
8785

8886
## Case 4: Cobuild enabled, run two cobuild commands in parallel
8987

9088
> Note: This test requires Visual Studio Code to be installed.
9189
92-
1. Clear redis server
90+
1. Open predefined `.vscode/redis-cobuild.code-workspace` in Visual Studio Code.
91+
92+
2. Clear redis server
9393

9494
```sh
95-
(cd ../.. && docker compose down && docker compose up -d)
95+
# Under rushstack/build-tests/rush-redis-cobuild-plugin-integration-test
96+
docker compose down && docker compose up -d
9697
```
9798

98-
2. Clear build cache
99+
3. Clear build cache
99100

100101
```sh
102+
# Under rushstack/build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo
101103
rm -rf common/temp/build-cache
102104
```
103105

104-
3. Open predefined `.vscode/redis-cobuild.code-workspace` in Visual Studio Code.
105-
106106
4. Open command palette (Ctrl+Shift+P or Command+Shift+P) and select `Tasks: Run Task` and select `cobuild`.
107107

108108
> In this step, two dedicated terminal windows will open. Running `rush cobuild` command under sandbox repo respectively.
@@ -113,32 +113,33 @@ Expected behavior: Cobuild feature is enabled, cobuild related logs out in both
113113

114114
> Note: This test requires Visual Studio Code to be installed.
115115
116-
1. Making the cobuild command of project "A" fails
116+
1. Open predefined `.vscode/redis-cobuild.code-workspace` in Visual Studio Code.
117+
118+
2. Making the cobuild command of project "A" fails
117119

118120
**sandbox/repo/projects/a/package.json**
119121

120122
```diff
121123
"scripts": {
122-
- "cobuild": "node ../build.js a",
123-
+ "cobuild": "sleep 5 && exit 1",
124-
"build": "node ../build.js a"
124+
- "_phase:build": "node ../build.js a",
125+
+ "_phase:build": "exit 1",
125126
}
126127
```
127128

128-
2. Clear redis server
129+
3. Clear redis server
129130

130131
```sh
131-
(cd ../.. && docker compose down && docker compose up -d)
132+
# Under rushstack/build-tests/rush-redis-cobuild-plugin-integration-test
133+
docker compose down && docker compose up -d
132134
```
133135

134-
3. Clear build cache
136+
4. Clear build cache
135137

136138
```sh
139+
# Under rushstack/build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo
137140
rm -rf common/temp/build-cache
138141
```
139142

140-
4. Open predefined `.vscode/redis-cobuild.code-workspace` in Visual Studio Code.
141-
142143
5. Open command palette (Ctrl+Shift+P or Command+Shift+P) and select `Tasks: Run Task` and select `cobuild`.
143144

144145
Expected behavior: Cobuild feature is enabled, cobuild related logs out in both terminals. These two cobuild commands fail because of the failing build of project "A". And, one of them restored the failing build cache created by the other one.

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/common/config/rush/command-line.json

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
*/
1313
"commands": [
1414
{
15-
"commandKind": "bulk",
15+
"commandKind": "phased",
1616
"summary": "Concurrent version of rush build",
1717
"name": "cobuild",
1818
"safeForSimultaneousRushProcesses": true,
1919
"enableParallelism": true,
20-
"incremental": true
20+
"incremental": true,
21+
"phases": ["_phase:pre-build", "_phase:build"]
2122
}
2223

2324
// {
@@ -177,7 +178,34 @@
177178
// }
178179
],
179180

180-
"phases": [],
181+
"phases": [
182+
{
183+
/**
184+
* The name of the phase. Note that this value must start with the \"_phase:\" prefix.
185+
*/
186+
"name": "_phase:build",
187+
/**
188+
* The dependencies of this phase.
189+
*/
190+
"dependencies": {
191+
"upstream": ["_phase:build"],
192+
"self": ["_phase:pre-build"]
193+
}
194+
},
195+
{
196+
/**
197+
* The name of the phase. Note that this value must start with the \"_phase:\" prefix.
198+
*/
199+
"name": "_phase:pre-build",
200+
/**
201+
* The dependencies of this phase.
202+
*/
203+
"dependencies": {
204+
"upstream": ["_phase:build"]
205+
},
206+
"missingScriptBehavior": "silent"
207+
}
208+
],
181209

182210
/**
183211
* Custom "parameters" introduce new parameters for specified Rush command-line commands.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* This configuration file allows repo maintainers to enable and disable experimental
3+
* Rush features. More documentation is available on the Rush website: https://rushjs.io
4+
*/
5+
{
6+
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/experiments.schema.json",
7+
8+
/**
9+
* By default, 'rush install' passes --no-prefer-frozen-lockfile to 'pnpm install'.
10+
* Set this option to true to pass '--frozen-lockfile' instead for faster installs.
11+
*/
12+
"usePnpmFrozenLockfileForRushInstall": true,
13+
14+
/**
15+
* By default, 'rush update' passes --no-prefer-frozen-lockfile to 'pnpm install'.
16+
* Set this option to true to pass '--prefer-frozen-lockfile' instead to minimize shrinkwrap changes.
17+
*/
18+
"usePnpmPreferFrozenLockfileForRushUpdate": true,
19+
20+
/**
21+
* If using the 'preventManualShrinkwrapChanges' option, restricts the hash to only include the layout of external dependencies.
22+
* Used to allow links between workspace projects or the addition/removal of references to existing dependency versions to not
23+
* cause hash changes.
24+
*/
25+
"omitImportersFromPreventManualShrinkwrapChanges": true,
26+
27+
/**
28+
* If true, the chmod field in temporary project tar headers will not be normalized.
29+
* This normalization can help ensure consistent tarball integrity across platforms.
30+
*/
31+
// "noChmodFieldInTarHeaderNormalization": true,
32+
33+
/**
34+
* If true, build caching will respect the allowWarningsInSuccessfulBuild flag and cache builds with warnings.
35+
* This will not replay warnings from the cached build.
36+
*/
37+
// "buildCacheWithAllowWarningsInSuccessfulBuild": true,
38+
39+
/**
40+
* If true, the phased commands feature is enabled. To use this feature, create a "phased" command
41+
* in common/config/rush/command-line.json.
42+
*/
43+
"phasedCommands": true
44+
45+
/**
46+
* If true, perform a clean install after when running `rush install` or `rush update` if the
47+
* `.npmrc` file has changed since the last install.
48+
*/
49+
// "cleanInstallAfterNpmrcChanges": true,
50+
51+
/**
52+
* If true, print the outputs of shell commands defined in event hooks to the console.
53+
*/
54+
// "printEventHooksOutputToConsole": true
55+
}

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/a/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"operationSettings": [
3+
{
4+
"operationName": "_phase:build",
5+
"outputFolderNames": ["dist"]
6+
},
37
{
48
"operationName": "cobuild",
59
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/a/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js a",
6-
"_cobuild": "sleep 5 && exit 1",
7-
"build": "node ../build.js a"
6+
"build": "node ../build.js a",
7+
"__phase:build": "exit 1",
8+
"_phase:build": "node ../build.js a"
89
}
910
}

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/b/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"operationSettings": [
3+
{
4+
"operationName": "_phase:build",
5+
"outputFolderNames": ["dist"]
6+
},
37
{
48
"operationName": "cobuild",
59
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/b/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:build": "node ../build.js b"
78
}
89
}

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/c/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"operationSettings": [
3+
{
4+
"operationName": "_phase:build",
5+
"outputFolderNames": ["dist"]
6+
},
37
{
48
"operationName": "cobuild",
59
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/c/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:build": "node ../build.js"
78
},
89
"dependencies": {
910
"b": "workspace:*"

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/d/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"operationSettings": [
3+
{
4+
"operationName": "_phase:build",
5+
"outputFolderNames": ["dist"]
6+
},
37
{
48
"operationName": "cobuild",
59
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/d/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:build": "node ../build.js"
78
},
89
"dependencies": {
910
"b": "workspace:*",

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/e/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"operationSettings": [
3+
{
4+
"operationName": "_phase:build",
5+
"outputFolderNames": ["dist"]
6+
},
37
{
48
"operationName": "cobuild",
59
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/e/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:build": "node ../build.js"
78
},
89
"dependencies": {
910
"b": "workspace:*",

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/f/config/rush-project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"disableBuildCacheForProject": true,
33
"operationSettings": [
4+
{
5+
"operationName": "_phase:build",
6+
"outputFolderNames": ["dist"]
7+
},
48
{
59
"operationName": "cobuild",
610
"outputFolderNames": ["dist"]

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/f/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:pre-build": "node ../pre-build.js",
8+
"_phase:build": "node ../validate-pre-build.js && node ../build.js f"
79
},
810
"dependencies": {
911
"b": "workspace:*"

build-tests/rush-redis-cobuild-plugin-integration-test/sandbox/repo/projects/g/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.0.0",
44
"scripts": {
55
"cobuild": "node ../build.js",
6-
"build": "node ../build.js"
6+
"build": "node ../build.js",
7+
"_phase:pre-build": "node ../pre-build.js",
8+
"_phase:build": "node ../validate-pre-build.js && node ../build.js g"
79
},
810
"dependencies": {
911
"b": "workspace:*"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-env es6 */
2+
const path = require('path');
3+
const { FileSystem } = require('@rushstack/node-core-library');
4+
5+
setTimeout(() => {
6+
const outputFolder = path.resolve(process.cwd(), 'dist');
7+
const outputFile = path.resolve(outputFolder, 'pre-build');
8+
FileSystem.ensureFolder(outputFolder);
9+
FileSystem.writeFile(outputFile, `Hello world!`);
10+
console.log('done');
11+
}, 2000);

0 commit comments

Comments
 (0)