Skip to content

Commit 5bde1d3

Browse files
committed
Main branch TV verifier
1 parent 2bc6284 commit 5bde1d3

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
config:
2+
skip-target-branches: "main"
3+
steps:
4+
- label: check-transport-versions
5+
command: .ci/scripts/run-gradle.sh -Dignore.tests.seed ensureTransportVersionsInMain
6+
timeout_in_minutes: 5
7+
agents:
8+
provider: gcp
9+
image: family/elasticsearch-ubuntu-2404
10+
machineType: custom-32-98304
11+
buildDirectory: /dev/shm/bk

build.gradle

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
*/
99

1010

11-
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
1211
import com.avast.gradle.dockercompose.tasks.ComposePull
1312
import com.fasterxml.jackson.databind.JsonNode
1413
import com.fasterxml.jackson.databind.ObjectMapper
15-
14+
import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
1615
import org.elasticsearch.gradle.DistributionDownloadPlugin
1716
import org.elasticsearch.gradle.Version
1817
import org.elasticsearch.gradle.VersionProperties
@@ -22,6 +21,7 @@ import org.elasticsearch.gradle.util.GradleUtils
2221
import org.gradle.plugins.ide.eclipse.model.AccessRule
2322

2423
import java.nio.file.Files
24+
import java.util.regex.Matcher
2525

2626
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
2727
import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure
@@ -203,6 +203,37 @@ tasks.register("updateCIBwcVersions") {
203203
}
204204
}
205205

206+
// Create a task to ensure that the transport versions exist in the main branch prior to allowing them to be added
207+
// in minor or bugfix branches. All transport versions must be added to the main branch first, before they can be
208+
// added elsewhere. This task will download the TransportVersions.java file from github using the url
209+
// https://raw.githubusercontent.com/elastic/elasticsearch/main/server/src/main/java/org/elasticsearch/transport/TransportVersions.java,
210+
// parse out the versions, and ensure that all TransportVersions on this branch are also present in the main branch.
211+
tasks.register("ensureTransportVersionsInMain") {
212+
def mainTransportVersionsUrl = 'https://raw.githubusercontent.com/elastic/elasticsearch/refs/heads/main/server/src/main/java/org/elasticsearch/TransportVersions.java'
213+
214+
doLast {
215+
if (gradle.startParameter.isOffline()) {
216+
throw new GradleException("Must run in online mode to verify transport versions")
217+
}
218+
def mainTransportVersions = new URI(mainTransportVersionsUrl).toURL().text
219+
def currentTransportVersions = file('server/src/main/java/org/elasticsearch/TransportVersions.java').text
220+
221+
def transportVersionRegex = /public static final TransportVersion (\w+) = def\((\w+)\);/
222+
223+
Matcher mainVersionMatcher = mainTransportVersions =~ transportVersionRegex
224+
Matcher currentVersionMatcher = currentTransportVersions =~ transportVersionRegex
225+
226+
def mainVersionsMap = mainVersionMatcher.iterator().collectEntries { [(it[1]): it[2]] }
227+
def currentVersionsMap = currentVersionMatcher.iterator().collectEntries { [(it[1]): it[2]] }
228+
229+
currentVersionsMap.each { versionName, versionValue ->
230+
if (mainVersionsMap[versionName] != versionValue) {
231+
throw new GradleException("Transport version ${versionName} with value ${versionValue} is not present in the main branch.")
232+
}
233+
}
234+
}
235+
}
236+
206237
tasks.register("verifyVersions") {
207238
def verifyCiYaml = { File file, List<Version> versions ->
208239
String ciYml = file.text

0 commit comments

Comments
 (0)