forked from cdmihai/CommandComparer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_cache_comparisons.py
184 lines (164 loc) · 6.09 KB
/
project_cache_comparisons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from command_comparer import *
BASELINE_MSBUILD_EXE = Path(r'E:\projects\msbuild_2\artifacts\bin\bootstrap\net472\MSBuild\Current\Bin\MSBuild.exe')
MSBUILD_EXE = Path(r'E:\projects\msbuild\artifacts\bin\bootstrap\net472\MSBuild\Current\Bin\MSBuild.exe')
LOCAL_CACHE = Path(r"E:\CloudBuildCache")
QUICKBUILD_INSTALLATION = Path(r"E:\projects\CloudBuild\target\distrib\retail\amd64\ClientTools\Client")
TEST_REPOS_ROOT = Path(r"E:\qb_repos")
assert QUICKBUILD_INSTALLATION.is_dir()
quickbuilds_sorted_by_creation_time = sorted(
QUICKBUILD_INSTALLATION.glob(r"**\quickbuild.exe"),
key=lambda p: p.stat().st_ctime)
QUICKBUILD_EXE = quickbuilds_sorted_by_creation_time[-1]
assert QUICKBUILD_EXE.is_file()
assert MSBUILD_EXE.is_file()
assert BASELINE_MSBUILD_EXE.is_file()
assert TEST_REPOS_ROOT.is_dir()
CLEAN_REPOSITORY = ProcessCommand("git", "clean", "-xdf")
DELETE_QB_CACHE = PowershellCommand(
f"if (Test-Path {str(LOCAL_CACHE)})"
f" {{rm -recurse -force {str(LOCAL_CACHE)} ; Write-Output 'Deleted: {str(LOCAL_CACHE)}'}}"
f" else {{Write-Output 'Does not exist: {str(LOCAL_CACHE)}'}}",
validation_checks=[
Func(lambda _: not LOCAL_CACHE.is_dir(), "QB cache dir still exists")
]
)
MSBUILD_SUCCESSFUL_BUILD_VALIDATION = [
Include("Build succeeded."),
Include("0 Error(s)")
]
MSBUILD_ALL_CACHE_HITS_VALIDATION = [
Include("Plugin result: CacheHit. Skipping project."),
Exclude("Plugin result: CacheMiss. Building project.")
]
MSBUILD_RESTORE = ProcessCommand(
str(MSBUILD_EXE), "/t:restore", "/m",
validation_checks=MSBUILD_SUCCESSFUL_BUILD_VALIDATION
)
MSBUILD_COMMON_ARGS = (
"/graph", "/m", "/clp:'verbosity=minimal;summary'", "/restore:false")
BUILD_WITH_MSBUILD = ProcessCommand(
str(MSBUILD_EXE), *MSBUILD_COMMON_ARGS,
validation_checks=MSBUILD_SUCCESSFUL_BUILD_VALIDATION
)
BUILD_WITH_MSBUILD_EXPECT_ALL_CACHE_HITS = BUILD_WITH_MSBUILD.add_validation_checks(
MSBUILD_ALL_CACHE_HITS_VALIDATION)
BUILD_WITH_BASELINE_MSBUILD = ProcessCommand(
str(BASELINE_MSBUILD_EXE), *MSBUILD_COMMON_ARGS,
validation_checks=MSBUILD_SUCCESSFUL_BUILD_VALIDATION
)
BUILD_WITH_BASELINE_MSBUILD_EXPECT_ALL_CACHE_HITS = BUILD_WITH_BASELINE_MSBUILD.add_validation_checks(
MSBUILD_ALL_CACHE_HITS_VALIDATION)
BUILD_WITH_QUICKBUILD = ProcessCommand(
str(QUICKBUILD_EXE), "-notest", "-msbuildrestore:false",
validation_checks=[
Exclude("errors trace messages found"),
Exclude("ERROR")
]
)
BUILD_WITH_QUICKBUILD_EXPECT_NO_BUILDS = BUILD_WITH_QUICKBUILD.add_validation_checks([
Include("(100.0%) retrieved from cache (no build)"),
Exclude("This build had cache misses"),
Exclude("Building (cache miss)")
])
REPOS = [
RepoSpec(
"CloudBuild",
r"private\BuildEngine\Enlistment.Library", # 32 build nodes
r"private\BuildEngine\BuildClient" # 104 build nodes
)
]
TEST_SUITES = [
TestSuite(
name="qb",
tests=[
Test(
name="clean_remote_cache",
repo_root_setup_command=Commands(
DELETE_QB_CACHE, CLEAN_REPOSITORY),
setup_command=MSBUILD_RESTORE,
test_command=BUILD_WITH_QUICKBUILD
),
Test(
name="clean_local_cache",
repo_root_setup_command=CLEAN_REPOSITORY,
setup_command=MSBUILD_RESTORE,
test_command=BUILD_WITH_QUICKBUILD_EXPECT_NO_BUILDS
),
Test(
name="incremental",
test_command=BUILD_WITH_QUICKBUILD_EXPECT_NO_BUILDS
)
]
),
TestSuite(
name="plugin",
tests=[
Test(
name="clean-remote-cache",
repo_root_setup_command=Commands(
DELETE_QB_CACHE, CLEAN_REPOSITORY),
setup_command=MSBUILD_RESTORE,
test_command=BUILD_WITH_MSBUILD
),
Test(
name="clean-local-cache",
repo_root_setup_command=CLEAN_REPOSITORY,
setup_command=Commands(MSBUILD_RESTORE, BUILD_WITH_QUICKBUILD),
test_command=BUILD_WITH_MSBUILD_EXPECT_ALL_CACHE_HITS
),
Test(
name="incremental",
test_command=BUILD_WITH_MSBUILD_EXPECT_ALL_CACHE_HITS
)
],
environment_variables={
"EnableQuickBuildCachePlugin": "true",
"_CurrentQuickBuildPath": str(QUICKBUILD_INSTALLATION)
}
),
TestSuite(
name="plugin-baseline",
tests=[
Test(
name="clean-remote-cache",
repo_root_setup_command=Commands(
DELETE_QB_CACHE, CLEAN_REPOSITORY),
setup_command=MSBUILD_RESTORE,
test_command=BUILD_WITH_BASELINE_MSBUILD
),
Test(
name="clean-local-cache",
repo_root_setup_command=CLEAN_REPOSITORY,
setup_command=Commands(MSBUILD_RESTORE, BUILD_WITH_QUICKBUILD),
test_command=BUILD_WITH_BASELINE_MSBUILD_EXPECT_ALL_CACHE_HITS
),
Test(
name="incremental",
test_command=BUILD_WITH_BASELINE_MSBUILD_EXPECT_ALL_CACHE_HITS
)
],
environment_variables={
"EnableQuickBuildCachePlugin": "true",
"_CurrentQuickBuildPath": str(QUICKBUILD_INSTALLATION)
}
),
TestSuite(
name="msb",
tests=[
Test(
name="clean",
repo_root_setup_command=CLEAN_REPOSITORY,
setup_command=MSBUILD_RESTORE,
test_command=BUILD_WITH_MSBUILD
),
Test(
name="incremental",
test_command=BUILD_WITH_MSBUILD
)
]
)
]
# add msbuild to the path to make qb happy
os.environ["PATH"] = f"{str(MSBUILD_EXE.parent)}{os.pathsep}{os.environ['PATH']}"
repo_results = run_tests(REPOS, TEST_REPOS_ROOT, TEST_SUITES, repetitions=3)
write_results_to_csv(repo_results, Path("repo_results.csv"))