-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.gradle
More file actions
162 lines (143 loc) · 4.76 KB
/
Copy pathbuild.gradle
File metadata and controls
162 lines (143 loc) · 4.76 KB
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
plugins {
id 'idea'
id 'eclipse'
id 'com.diffplug.spotless' version '6.25.0' apply false
id 'io.freefair.lombok' version '9.2.0' apply false
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}
version = generateVersion()
group = 'dev.braintrust'
ext {
otelVersion = '1.66.0'
otelSemConvVersion = '1.44.0'
jacksonVersion = '2.21.7'
jacksonDatabindNullableVersion = '0.2.11'
junitVersion = '5.11.4'
slf4jVersion = '2.0.20'
byteBuddyVersion = '1.18.14'
}
/**
* Use git to compute the sdk version
*
* This is written into braintrust.properties at build time and shipped into the distributed sdk jar
*
* - if we are on a tag (i.e. v0.0.3), use the tag WITHOUT the 'v' prefix (0.0.3)
* - otherwise, use $mostRecentTag-$currentCommitSha (without 'v' prefix)
*
* Additionally, if the git workspace is not clean, append -DIRTY to the version
*
* Examples
* - 0.0.3 (from tag v0.0.3)
* - 0.0.3-c4af682 (from tag v0.0.3)
* - 0.0.3-c4af682-DIRTY
*/
def runGit(List<String> arguments) {
def stdout = new StringBuilder()
def stderr = new StringBuilder()
def process = (['git'] + arguments).execute()
process.waitForProcessOutput(stdout, stderr)
return [exitValue: process.exitValue(), output: stdout.toString().trim()]
}
def generateVersion() {
// Check if workspace is clean
def gitStatus = runGit(['status', '--porcelain']).output
def isDirty = !gitStatus.isEmpty()
// Get current commit SHA (short version)
def gitSha = runGit(['rev-parse', '--short', 'HEAD']).output
// Check if we're currently on a tag
def currentTag = null
try {
def currentTagResult = runGit(['describe', '--exact-match', '--tags', 'HEAD'])
if (currentTagResult.exitValue == 0) {
currentTag = currentTagResult.output
}
} catch (Exception e) {
// Not on a tag, that's fine
}
def version
if (currentTag != null) {
// We're on a tag, use the tag name (strip 'v' prefix if present)
version = currentTag.startsWith('v') ? currentTag.substring(1) : currentTag
} else {
// Not on a tag, find the most recent tag
def mostRecentTag = null
try {
def mostRecentTagResult = runGit(['describe', '--tags', '--abbrev=0'])
if (mostRecentTagResult.exitValue == 0) {
mostRecentTag = mostRecentTagResult.output
}
} catch (Exception e) {
// No tags found, use just the SHA
mostRecentTag = null
}
if (mostRecentTag != null) {
// Strip 'v' prefix if present
def cleanTag = mostRecentTag.startsWith('v') ? mostRecentTag.substring(1) : mostRecentTag
version = "${cleanTag}-${gitSha}"
} else {
version = gitSha
}
}
// Append -DIRTY if workspace is not clean
if (isDirty) {
version = "${version}-DIRTY"
}
return version
}
subprojects {
pluginManager.withPlugin('java') {
apply plugin: 'com.diffplug.spotless'
apply plugin: 'io.freefair.lombok'
dependencies {
compileOnly 'com.google.auto.service:auto-service-annotations:1.1.1'
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
}
spotless {
java {
target 'src/*/java/**/*.java'
googleJavaFormat('1.19.2').aosp().reflowLongStrings()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
}
}
// Task to install git hooks
task installGitHooks(type: Exec) {
description = 'Install git hooks for code formatting'
group = 'Build Setup'
commandLine 'bash', 'scripts/install-hooks.sh'
}
// Shipped dependency filters are shared with the dependency-submission workflow.
def shippedFilters = new groovy.json.JsonSlurper().parse(file('.github/dependency-graph.json'))
def shippedProjects = subprojects.findAll { it.path ==~ shippedFilters.DEPENDENCY_GRAPH_INCLUDE_PROJECTS }
shippedProjects.each { shipped ->
// Resolve each graph in its own project; cross-project resolution is an error in Gradle 9.
shipped.tasks.register('shippedDependencies', dev.braintrust.gradle.ShippedDependenciesTask) { task ->
shipped.configurations
.findAll { it.canBeResolved && it.name ==~ shippedFilters.DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS }
.each { task.rootComponents.put(it.name, it.incoming.resolutionResult.rootComponent) }
task.outputFile = shipped.layout.buildDirectory.file('shipped-dependencies.txt')
}
}
tasks.register('checkDependencies', dev.braintrust.gradle.CheckDependenciesTask) {
shippedDependencies.from(shippedProjects.collect { it.tasks.named('shippedDependencies') })
}
tasks.register('checkCodeQL', Exec) {
group = 'verification'
description = 'Runs the local CodeQL scan using the mise-pinned toolchain'
workingDir rootDir
commandLine 'mise', 'exec', '--', './scripts/check-codeql.sh'
}