|
1 | | -import java.nio.file.Paths |
2 | | - |
3 | 1 | buildscript { |
4 | 2 | dependencies { |
5 | 3 | classpath "pl.allegro.tech.build:axion-release-plugin:1.14.4" |
@@ -153,208 +151,4 @@ allprojects { |
153 | 151 | } |
154 | 152 | } |
155 | 153 |
|
156 | | -allprojects { project -> |
157 | | - project.ext { |
158 | | - activePartition = true |
159 | | - } |
160 | | - final boolean shouldUseTaskPartitions = project.rootProject.hasProperty("taskPartitionCount") && project.rootProject.hasProperty("taskPartition") |
161 | | - if (shouldUseTaskPartitions) { |
162 | | - final int taskPartitionCount = project.rootProject.property("taskPartitionCount") as int |
163 | | - final int taskPartition = project.rootProject.property("taskPartition") as int |
164 | | - final currentTaskPartition = Math.abs(project.path.hashCode() % taskPartitionCount) |
165 | | - project.setProperty("activePartition", currentTaskPartition == taskPartition) |
166 | | - } |
167 | | -} |
168 | | - |
169 | | -Set<Task> getTaskDependenciesRecursive(Task baseTask, Set<Task> visited = []) { |
170 | | - if (visited.contains(baseTask)) { |
171 | | - return [] |
172 | | - } |
173 | | - Set<Task> dependencies = [baseTask] |
174 | | - visited.add(baseTask) |
175 | | - for (td in baseTask.taskDependencies) { |
176 | | - for (t in td.getDependencies(baseTask)) { |
177 | | - dependencies.add(t) |
178 | | - dependencies.addAll(getTaskDependenciesRecursive(t, visited)) |
179 | | - } |
180 | | - } |
181 | | - return dependencies |
182 | | -} |
183 | | - |
184 | | -File relativeToGitRoot(File f) { |
185 | | - return rootProject.projectDir.toPath().relativize(f.absoluteFile.toPath()).toFile() |
186 | | -} |
187 | | - |
188 | | -String isAffectedBy(Task baseTask, Map<Project, Set<String>> affectedProjects) { |
189 | | - for (Task t in getTaskDependenciesRecursive(baseTask)) { |
190 | | - if (!affectedProjects.containsKey(t.project)) { |
191 | | - continue |
192 | | - } |
193 | | - final Set<String> affectedTasks = affectedProjects.get(t.project) |
194 | | - if (affectedTasks.contains("all")) { |
195 | | - return "${t.project.path}:${t.name}" |
196 | | - } |
197 | | - if (affectedTasks.contains(t.name)) { |
198 | | - return "${t.project.path}:${t.name}" |
199 | | - } |
200 | | - } |
201 | | - return null |
202 | | -} |
203 | | - |
204 | | -List<File> getChangedFiles(String baseRef, String newRef) { |
205 | | - final stdout = new StringBuilder() |
206 | | - final stderr = new StringBuilder() |
207 | | - final proc = "git diff --name-only ${baseRef}..${newRef}".execute() |
208 | | - proc.consumeProcessOutput(stdout, stderr) |
209 | | - proc.waitForOrKill(1000) |
210 | | - assert proc.exitValue() == 0, "git diff command failed, stderr: ${stderr}" |
211 | | - def out = stdout.toString().trim() |
212 | | - if (out.isEmpty()) { |
213 | | - return [] |
214 | | - } |
215 | | - logger.debug("git diff output: ${out}") |
216 | | - return out.split("\n").collect { |
217 | | - new File(rootProject.projectDir, it.trim()) |
218 | | - } |
219 | | -} |
220 | | - |
221 | | -rootProject.ext { |
222 | | - useGitChanges = false |
223 | | -} |
224 | | - |
225 | | -if (rootProject.hasProperty("gitBaseRef")) { |
226 | | - // -PgitBaseRef sets the base git reference to compare changes to. In CI, this should generally be set to the target |
227 | | - // branch, usually master. |
228 | | - final String baseRef = rootProject.property("gitBaseRef") |
229 | | - // -PgitNewRef sets the new git new reference to compare changes to. This is useful for testing the test selection method |
230 | | - // itself. Otherwise, comparing against current HEAD is what makes sense for CI. |
231 | | - final String newRef = rootProject.hasProperty("gitNewRef") ? rootProject.property("gitNewRef") : "HEAD" |
232 | | - |
233 | | - rootProject.ext { |
234 | | - it.changedFiles = getChangedFiles(baseRef, newRef) |
235 | | - useGitChanges = true |
236 | | - } |
237 | | - |
238 | | - // The ignoredFiles FileTree selects any file that should not trigger any tasks. |
239 | | - final ignoredFiles = fileTree(rootProject.projectDir) { |
240 | | - include '.gitingore', '.editorconfig' |
241 | | - include '*.md', '**/*.md' |
242 | | - include 'gradlew', 'gradlew.bat', 'mvnw', 'mvnw.cmd' |
243 | | - include 'NOTICE' |
244 | | - include 'static-analysis.datadog.yml' |
245 | | - } |
246 | | - rootProject.changedFiles.each { File f -> |
247 | | - if (ignoredFiles.contains(f)) { |
248 | | - logger.warn("Ignoring changed file: ${relativeToGitRoot(f)}") |
249 | | - } |
250 | | - } |
251 | | - rootProject.changedFiles = rootProject.changedFiles.findAll { !ignoredFiles.contains(it) } |
252 | | - |
253 | | - // The globalEffectsFile FileTree selects any file that should trigger all tasks, regardless of gradle dependency |
254 | | - // tracking. |
255 | | - final globalEffectFiles = fileTree(rootProject.projectDir) { |
256 | | - include '.circleci/**' |
257 | | - include 'build.gradle' |
258 | | - include 'gradle/**' |
259 | | - } |
260 | | - |
261 | | - for (File f in rootProject.changedFiles) { |
262 | | - if (globalEffectFiles.contains(f)) { |
263 | | - logger.warn("Global effect change: ${relativeToGitRoot(f)} (no tasks will be skipped)") |
264 | | - rootProject.useGitChanges = false |
265 | | - break |
266 | | - } |
267 | | - } |
268 | | - |
269 | | - if (rootProject.useGitChanges) { |
270 | | - logger.warn("Git change tracking is enabled, base: ${baseRef}") |
271 | | - |
272 | | - // Get all projects, sorted by descending path length. |
273 | | - final projects = subprojects.sort { a, b -> b.projectDir.path.length() <=> a.projectDir.path.length() } |
274 | | - for (File f in rootProject.changedFiles) { |
275 | | - Project p = projects.find { f.toString().startsWith(it.projectDir.path + "/") } |
276 | | - if (p == null) { |
277 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} at root project (no tasks will be skipped)") |
278 | | - rootProject.useGitChanges = false |
279 | | - break |
280 | | - } |
281 | | - final relPath = Paths.get(p.projectDir.path).relativize(f.toPath()) |
282 | | - final pathComponents = relPath.collect({ it.toString() }).toList() |
283 | | - Map<Project, Set<String>> _affectedProjects = [:] |
284 | | - if (pathComponents.size() < 3) { |
285 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} in project ${p.path} (all)") |
286 | | - _affectedProjects.computeIfAbsent(p, { new HashSet<String>() }).add("all") |
287 | | - } else if (pathComponents[0] == "src" && pathComponents[1] == "testFixturesClasses") { |
288 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} in project ${p.path} (testFixturesClasses)") |
289 | | - _affectedProjects.computeIfAbsent(p, { new HashSet<String>() }).add("testFixturesClasses") |
290 | | - } else if (pathComponents[0] == "src" && pathComponents[1] == "testClasses") { |
291 | | - // TODO: We could include other variants here such as latestTest, etc. |
292 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} in project ${p.path} (testClasses)") |
293 | | - _affectedProjects.computeIfAbsent(p, { new HashSet<String>() }).add("testClasses") |
294 | | - } else if (pathComponents[0] == "src" && pathComponents[1] == "jmhCompileGeneratedClasses") { |
295 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} in project ${p.path} (jmhCompileGeneratedClasses)") |
296 | | - _affectedProjects.computeIfAbsent(p, { new HashSet<String>() }).add("jmhCompileGeneratedClasses") |
297 | | - } else { |
298 | | - logger.warn("Changed file: ${relativeToGitRoot(f)} in project ${p.path} (all)") |
299 | | - _affectedProjects.computeIfAbsent(p, { new HashSet<String>() }).add("all") |
300 | | - } |
301 | | - rootProject.ext { |
302 | | - it.affectedProjects = _affectedProjects |
303 | | - } |
304 | | - } |
305 | | - } |
306 | | - |
307 | | -} |
308 | | - |
309 | | -def testAggregate(String baseTaskName, includePrefixes, excludePrefixes, boolean forceCoverage = false) { |
310 | | - def createRootTask = { String rootTaskName, String subProjTaskName -> |
311 | | - def coverage = forceCoverage || rootProject.hasProperty("checkCoverage") |
312 | | - tasks.register(rootTaskName) { aggTest -> |
313 | | - subprojects { subproject -> |
314 | | - if (subproject.property("activePartition") && includePrefixes.any { subproject.path.startsWith(it) } && !excludePrefixes.any { subproject.path.startsWith(it) }) { |
315 | | - Task testTask = subproject.tasks.findByName(subProjTaskName) |
316 | | - boolean isAffected = true |
317 | | - if (testTask != null) { |
318 | | - if (rootProject.useGitChanges) { |
319 | | - final fileTrigger = isAffectedBy(testTask, rootProject.property("affectedProjects")) |
320 | | - if (fileTrigger != null) { |
321 | | - logger.warn("Selecting ${subproject.path}:${subProjTaskName} (triggered by ${fileTrigger})") |
322 | | - } else { |
323 | | - logger.warn("Skipping ${subproject.path}:${subProjTaskName} (not affected by changed files)") |
324 | | - isAffected = false |
325 | | - } |
326 | | - } |
327 | | - if (isAffected) { |
328 | | - aggTest.dependsOn(testTask) |
329 | | - } |
330 | | - } |
331 | | - if (isAffected && coverage) { |
332 | | - def coverageTask = subproject.tasks.findByName("jacocoTestReport") |
333 | | - if (coverageTask != null) { |
334 | | - aggTest.dependsOn(coverageTask) |
335 | | - } |
336 | | - coverageTask = subproject.tasks.findByName("jacocoTestCoverageVerification") |
337 | | - if (coverageTask != null) { |
338 | | - aggTest.dependsOn(coverageTask) |
339 | | - } |
340 | | - } |
341 | | - } |
342 | | - } |
343 | | - } |
344 | | - } |
345 | | - |
346 | | - createRootTask "${baseTaskName}Test", 'allTests' |
347 | | - createRootTask "${baseTaskName}LatestDepTest", 'allLatestDepTests' |
348 | | - createRootTask "${baseTaskName}Check", 'check' |
349 | | -} |
350 | | - |
351 | | -testAggregate("smoke", [":dd-smoke-tests"], []) |
352 | | -testAggregate("instrumentation", [":dd-java-agent:instrumentation"], []) |
353 | | -testAggregate("profiling", [":dd-java-agent:agent-profiling"], []) |
354 | | -testAggregate("debugger", [":dd-java-agent:agent-debugger"], [], true) |
355 | | -testAggregate("base", [":"], [ |
356 | | - ":dd-java-agent:instrumentation", |
357 | | - ":dd-smoke-tests", |
358 | | - ":dd-java-agent:agent-profiling", |
359 | | - ":dd-java-agent:agent-debugger" |
360 | | -]) |
| 154 | +apply from: "$rootDir/gradle/ci_jobs.gradle" |
0 commit comments