Skip to content

Commit 32de70e

Browse files
andrrossshayush622
authored andcommitted
Tolerate BWC branch patch version bump (opensearch-project#20871)
When a patch release (e.g., 2.19.5) is published and the release branch is bumped to the next patch (2.19.6), BWC tests on main fail because Version.java still references the old patch version. This causes all in-flight PRs to fail until Version.java is updated. This change relaxes the logic so that BWC tests will still pass if the checked out code uses a patch version one greater than expected. This prevents CI failures every time a release branch increments its patch version, but still prevents the main branch from drifting by more than one patch version. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent 098e9b6 commit 32de70e

File tree

1 file changed

+86
-23
lines changed

1 file changed

+86
-23
lines changed

buildSrc/src/main/java/org/opensearch/gradle/internal/InternalDistributionBwcSetupPlugin.java

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void configureBwcProject(Project project, BwcVersions.UnreleasedVersionI
106106
bwcVersion,
107107
distributionProject.name,
108108
distributionProject.getProjectPath(),
109-
distributionProject.getDistFile(),
109+
distributionProject,
110110
buildBwcTaskProvider
111111
);
112112

@@ -131,14 +131,24 @@ private void registerBwcArtifacts(Project bwcProject, DistributionProject distri
131131
}
132132

133133
private void registerDistributionArchiveArtifact(Project bwcProject, DistributionProject distributionProject, String buildBwcTask) {
134-
String artifactFileName = distributionProject.getDistFile().getName();
134+
String artifactFileName = distributionProject.getExpectedDistFile().getName();
135135
String artifactName = "opensearch";
136136

137137
String suffix = artifactFileName.endsWith("tar.gz") ? "tar.gz" : artifactFileName.substring(artifactFileName.length() - 3);
138138
int archIndex = artifactFileName.indexOf("x64");
139139

140+
Provider<File> artifactFileProvider = providerFactory.provider(() -> {
141+
if (distributionProject.getExpectedDistFile().exists()) {
142+
return distributionProject.getExpectedDistFile();
143+
} else if (distributionProject.getFallbackDistFile().exists()) {
144+
return distributionProject.getFallbackDistFile();
145+
}
146+
// File doesn't exist, validation will fail elsewhere but we must return a File here
147+
return distributionProject.getExpectedDistFile();
148+
});
149+
140150
bwcProject.getConfigurations().create(distributionProject.name);
141-
bwcProject.getArtifacts().add(distributionProject.name, distributionProject.getDistFile(), artifact -> {
151+
bwcProject.getArtifacts().add(distributionProject.name, artifactFileProvider, artifact -> {
142152
artifact.setName(artifactName);
143153
artifact.builtBy(buildBwcTask);
144154
artifact.setType(suffix);
@@ -152,6 +162,10 @@ private void registerDistributionArchiveArtifact(Project bwcProject, Distributio
152162
});
153163
}
154164

165+
static Version nextPatchVersion(Version version) {
166+
return new Version(version.getMajor(), version.getMinor(), version.getRevision() + 1);
167+
}
168+
155169
private static List<DistributionProject> resolveArchiveProjects(File checkoutDir, Version bwcVersion) {
156170
List<String> projects = new ArrayList<>();
157171
// All active BWC branches publish rpm and deb packages
@@ -174,6 +188,8 @@ private static List<DistributionProject> resolveArchiveProjects(File checkoutDir
174188
projects.addAll(asList("zip", "tar"));
175189
}
176190

191+
Version fallbackVersion = nextPatchVersion(bwcVersion);
192+
177193
return projects.stream().map(name -> {
178194
String baseDir = "distribution" + (name.endsWith("zip") || name.endsWith("tar") ? "/archives" : "/packages");
179195
String classifier = "";
@@ -199,7 +215,7 @@ private static List<DistributionProject> resolveArchiveProjects(File checkoutDir
199215
} else {
200216
extension = name.substring(4);
201217
}
202-
return new DistributionProject(name, baseDir, bwcVersion, classifier, extension, checkoutDir);
218+
return new DistributionProject(name, baseDir, bwcVersion, fallbackVersion, classifier, extension, checkoutDir);
203219
}).collect(Collectors.toList());
204220
}
205221

@@ -215,15 +231,15 @@ static void createBuildBwcTask(
215231
Provider<Version> bwcVersion,
216232
String projectName,
217233
String projectPath,
218-
File projectArtifact,
234+
DistributionProject distributionProject,
219235
TaskProvider<Task> bwcTaskProvider
220236
) {
221237
String bwcTaskName = buildBwcTaskName(projectName);
222238
bwcSetupExtension.bwcTask(bwcTaskName, new Action<LoggedExec>() {
223239
@Override
224240
public void execute(LoggedExec c) {
225241
c.getInputs().file(new File(project.getBuildDir(), "refspec"));
226-
c.getOutputs().files(projectArtifact);
242+
c.getOutputs().files(distributionProject.getExpectedDistFile(), distributionProject.getFallbackDistFile());
227243
c.getOutputs().cacheIf("BWC distribution caching is disabled on 'master' branch", task -> {
228244
String gitBranch = System.getenv("GIT_BRANCH");
229245
return BuildParams.isCi() && (gitBranch == null || gitBranch.endsWith("master") == false);
@@ -235,9 +251,24 @@ public void execute(LoggedExec c) {
235251
c.doLast(new Action<Task>() {
236252
@Override
237253
public void execute(Task task) {
238-
if (projectArtifact.exists() == false) {
254+
if (distributionProject.getExpectedDistFile().exists() == false
255+
&& distributionProject.getFallbackDistFile().exists()) {
256+
project.getLogger()
257+
.warn(
258+
"BWC branch produced {} instead of {}. "
259+
+ "Version.java on main may need updating to include version {}.",
260+
distributionProject.getFallbackDistFile().getName(),
261+
distributionProject.getExpectedDistFile().getName(),
262+
distributionProject.getFallbackVersion()
263+
);
264+
} else if (distributionProject.getExpectedDistFile().exists() == false) {
239265
throw new InvalidUserDataException(
240-
"Building " + bwcVersion.get() + " didn't generate expected file " + projectArtifact
266+
"Building "
267+
+ bwcVersion.get()
268+
+ " didn't generate expected file "
269+
+ distributionProject.getExpectedDistFile()
270+
+ " or fallback "
271+
+ distributionProject.getFallbackDistFile()
241272
);
242273
}
243274
}
@@ -251,20 +282,48 @@ public void execute(Task task) {
251282
* Represents an archive project (distribution/archives/*)
252283
* we build from a bwc Version in a cloned repository
253284
*/
254-
private static class DistributionProject {
255-
private final String name;
256-
private String projectPath;
257-
private File distFile;
258-
private File expandedDistDir;
259-
260-
DistributionProject(String name, String baseDir, Version version, String classifier, String extension, File checkoutDir) {
285+
static class DistributionProject {
286+
final String name;
287+
private final String projectPath;
288+
private final File expectedDistFile;
289+
private final File fallbackDistFile;
290+
private final Version fallbackVersion;
291+
private final File expandedDistDir;
292+
293+
DistributionProject(
294+
String name,
295+
String baseDir,
296+
Version expectedVersion,
297+
Version fallbackVersion,
298+
String classifier,
299+
String extension,
300+
File checkoutDir
301+
) {
261302
this.name = name;
262303
this.projectPath = baseDir + "/" + name;
304+
this.expectedDistFile = buildDistFile(name, baseDir, expectedVersion, classifier, extension, checkoutDir);
305+
this.fallbackDistFile = buildDistFile(name, baseDir, fallbackVersion, classifier, extension, checkoutDir);
306+
this.fallbackVersion = fallbackVersion;
307+
if (name.endsWith("zip") || name.endsWith("tar")) {
308+
this.expandedDistDir = new File(checkoutDir, baseDir + "/" + name + "/build/install");
309+
} else {
310+
this.expandedDistDir = null;
311+
}
312+
}
313+
314+
private static File buildDistFile(
315+
String name,
316+
String baseDir,
317+
Version version,
318+
String classifier,
319+
String extension,
320+
File checkoutDir
321+
) {
263322
if (version.onOrAfter("1.1.0")) {
264323
// Deb uses underscores (I don't know why...):
265324
// https://github.com/opensearch-project/OpenSearch/blob/f6d9a86f0e2e8241fd58b7e8b6cdeaf931b5108f/distribution/packages/build.gradle#L139
266325
final String separator = name.equals("deb") ? "_" : "-";
267-
this.distFile = new File(
326+
return new File(
268327
checkoutDir,
269328
baseDir
270329
+ "/"
@@ -278,23 +337,27 @@ private static class DistributionProject {
278337
+ extension
279338
);
280339
} else {
281-
this.distFile = new File(
340+
return new File(
282341
checkoutDir,
283342
baseDir + "/" + name + "/build/distributions/opensearch-" + version + "-SNAPSHOT" + classifier + "." + extension
284343
);
285344
}
286-
// we only ported this down to the 7.x branch.
287-
if (version.onOrAfter("7.10.0") && (name.endsWith("zip") || name.endsWith("tar"))) {
288-
this.expandedDistDir = new File(checkoutDir, baseDir + "/" + name + "/build/install");
289-
}
290345
}
291346

292347
public String getProjectPath() {
293348
return projectPath;
294349
}
295350

296-
public File getDistFile() {
297-
return distFile;
351+
public File getExpectedDistFile() {
352+
return expectedDistFile;
353+
}
354+
355+
public File getFallbackDistFile() {
356+
return fallbackDistFile;
357+
}
358+
359+
public Version getFallbackVersion() {
360+
return fallbackVersion;
298361
}
299362

300363
public File getExpandedDistDirectory() {

0 commit comments

Comments
 (0)