diff --git a/build.gradle b/build.gradle index 3dc9fba9..5d3c6e53 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ plugins { id 'base' id 'project-report' id 'idea' + id 'com.gradle.build-scan' version '2.4.2' id 'org.sonarqube' version '2.7.1' id 'org.asciidoctor.convert' version '1.6.1' id 'org.ajoberstar.grgit' version '3.1.1' @@ -21,6 +22,18 @@ plugins { id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply false } +if (System.getenv('GRADLE_ENTERPRISE_URL')) { + apply from: "$rootDir/gradle/build-scan-user-data.gradle" + buildScan { + captureTaskInputFiles = true + obfuscation { + ipAddresses { addresses -> addresses.collect { address -> '0.0.0.0'} } + } + publishAlways() + server = System.getenv('GRADLE_ENTERPRISE_URL') + } +} + apply plugin: 'io.spring.nohttp' description = 'Spring Kafka' diff --git a/gradle/build-scan-user-data.gradle b/gradle/build-scan-user-data.gradle new file mode 100644 index 00000000..d4f483d6 --- /dev/null +++ b/gradle/build-scan-user-data.gradle @@ -0,0 +1,90 @@ +tagOs() +tagIde() +tagCiOrLocal() +addCiMetadata() +addGitMetadata() +addTestTaskMetadata() + +void tagOs() { + buildScan.tag System.getProperty('os.name') +} + +void tagIde() { + if (System.getProperty('idea.version')) { + buildScan.tag 'IntelliJ IDEA' + } else if (System.getProperty('eclipse.buildId')) { + buildScan.tag 'Eclipse' + } +} + +void tagCiOrLocal() { + buildScan.tag(isCi() ? 'CI' : 'LOCAL') +} + +void addGitMetadata() { + buildScan.background { + def gitCommitId = execAndGetStdout('git', 'rev-parse', '--short=8', '--verify', 'HEAD') + def gitBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD') + def gitStatus = execAndGetStdout('git', 'status', '--porcelain') + + if(gitCommitId) { + def commitIdLabel = 'Git Commit ID' + value commitIdLabel, gitCommitId + link 'Git commit build scans', customValueSearchUrl([(commitIdLabel): gitCommitId]) + } + if (gitBranchName) { + tag gitBranchName + value 'Git branch', gitBranchName + } + if (gitStatus) { + tag 'dirty' + value 'Git status', gitStatus + } + } +} + +void addCiMetadata() { + def ciBuild = 'CI BUILD' + if (isBamboo()) { + buildScan.link ciBuild, System.getenv('bamboo_resultsUrl') + } +} + +void addTestTaskMetadata() { + allprojects { + tasks.withType(Test) { test -> + doFirst { + buildScan.value "Test#maxParallelForks[${test.path}]", test.maxParallelForks.toString() + } + } + } +} + +boolean isCi() { + isBamboo() +} + +boolean isBamboo() { + System.getenv('bamboo_resultsUrl') +} + +String execAndGetStdout(String... args) { + def stdout = new ByteArrayOutputStream() + exec { + commandLine(args) + standardOutput = stdout + } + return stdout.toString().trim() +} + +String customValueSearchUrl(Map search) { + def query = search.collect { name, value -> + "search.names=${encodeURL(name)}&search.values=${encodeURL(value)}" + }.join('&') + + "$buildScan.server/scans?$query" +} + +String encodeURL(String url) { + URLEncoder.encode(url, 'UTF-8') +}