Skip to content

Commit 62aa1ac

Browse files
authored
Use buildkite branch for transport checks if not in PR CI (elastic#136647) (elastic#136719)
When testing intake and other periodic jobs, transport version build checks should use the branch being tested, not main. This commit falls back to the branch reported by buildkite.
1 parent 91c54b1 commit 62aa1ac

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/transport/TransportVersionValidationFuncTest.groovy

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ class TransportVersionValidationFuncTest extends AbstractTransportVersionFuncTes
312312
result.task(":myserver:validateTransportVersionResources").outcome == TaskOutcome.SUCCESS
313313
}
314314

315-
def "modification checks use PR base branch in CI"() {
316-
given:
315+
void baseBranchSetup() {
317316
// create 9.1 branch
318317
execute("git checkout -b 9.1")
319318
// setup 9.1 upper bound as if 9.2 was just branched, so no patches yet
@@ -342,10 +341,27 @@ class TransportVersionValidationFuncTest extends AbstractTransportVersionFuncTes
342341
currentUpperBoundName = '9.1'
343342
}
344343
"""
344+
}
345+
346+
def "modification checks use PR base branch in CI"() {
347+
given:
348+
baseBranchSetup()
349+
350+
when:
351+
def result = gradleRunner("validateTransportVersionResources")
352+
.withEnvironment(Map.of("BUILDKITE_PULL_REQUEST_BASE_BRANCH", "9.1", "BUILDKITE_BRANCH", "foobar")).build()
353+
354+
then:
355+
result.task(":myserver:validateTransportVersionResources").outcome == TaskOutcome.SUCCESS
356+
}
357+
358+
def "modification checks use buildkite base branch in CI if not in PR"() {
359+
given:
360+
baseBranchSetup()
345361

346362
when:
347363
def result = gradleRunner("validateTransportVersionResources")
348-
.withEnvironment(Map.of("BUILDKITE_PULL_REQUEST_BASE_BRANCH", "9.1")).build()
364+
.withEnvironment(Map.of("BUILDKITE_BRANCH", "9.1")).build()
349365

350366
then:
351367
result.task(":myserver:validateTransportVersionResources").outcome == TaskOutcome.SUCCESS

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ private String findUpstreamRef() {
287287
// default the branch name to look at to that which a PR in CI is targeting
288288
String branchName = System.getenv("BUILDKITE_PULL_REQUEST_BASE_BRANCH");
289289
if (branchName == null || branchName.strip().isEmpty()) {
290-
branchName = "main";
290+
// fallback to the local branch being tested in CI
291+
branchName = System.getenv("BUILDKITE_BRANCH");
292+
if (branchName == null || branchName.strip().isEmpty()) {
293+
// fallback to main if we aren't in CI
294+
branchName = "main";
295+
}
291296
}
292297
List<String> remoteNames = List.of(remotesOutput.split("\n"));
293298
if (remoteNames.contains(UPSTREAM_REMOTE_NAME) == false) {

0 commit comments

Comments
 (0)