Skip to content

Commit ac803f0

Browse files
authored
Drop version field from changelog YAML (#76985)
The changelog generation process currently relies on version information being present in the changelog YAML descriptors. However, this makes them difficult to update in some scenarios. For example, if a PR is merged and subsequently labelled for backporting, our automation won't update the versions in the changelog YAML. We can make the process more flexible by removing version data from the changelog YAML files, and instead inferring the versions from each changelog YAML file's existence in the git tree at each tag in the minor series. This change makes the process more ergonomic for developers, but harder to test, since I can't simply concoct YAML data for a range of versions. Instead, I've added a number of unit tests, and tried to exercise all the relevant parts. It is now an error to include `versions` the YAML file.
1 parent 0771543 commit ac803f0

26 files changed

+1510
-235
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/BreakingChangesGenerator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
import com.google.common.annotations.VisibleForTesting;
1414

15-
import org.elasticsearch.gradle.Version;
1615
import org.elasticsearch.gradle.VersionProperties;
1716

1817
import java.io.File;
1918
import java.io.FileWriter;
2019
import java.io.IOException;
20+
import java.io.Writer;
2121
import java.nio.file.Files;
2222
import java.util.HashMap;
2323
import java.util.List;
@@ -26,40 +26,50 @@
2626
import java.util.TreeMap;
2727
import java.util.stream.Collectors;
2828

29+
import static java.util.Comparator.comparing;
30+
import static java.util.stream.Collectors.groupingBy;
31+
2932
/**
3033
* Generates the page that lists the breaking changes and deprecations for a minor version release.
3134
*/
3235
public class BreakingChangesGenerator {
3336

3437
static void update(File templateFile, File outputFile, List<ChangelogEntry> entries) throws IOException {
3538
try (FileWriter output = new FileWriter(outputFile)) {
36-
generateFile(Files.readString(templateFile.toPath()), output, entries);
39+
generateFile(
40+
QualifiedVersion.of(VersionProperties.getElasticsearch()),
41+
Files.readString(templateFile.toPath()),
42+
output,
43+
entries
44+
);
3745
}
3846
}
3947

4048
@VisibleForTesting
41-
private static void generateFile(String template, FileWriter outputWriter, List<ChangelogEntry> entries) throws IOException {
42-
final Version version = VersionProperties.getElasticsearchVersion();
49+
static void generateFile(QualifiedVersion version, String template, Writer outputWriter, List<ChangelogEntry> entries)
50+
throws IOException {
4351

4452
final Map<Boolean, Map<String, List<ChangelogEntry.Breaking>>> breakingChangesByNotabilityByArea = entries.stream()
4553
.map(ChangelogEntry::getBreaking)
4654
.filter(Objects::nonNull)
55+
.sorted(comparing(ChangelogEntry.Breaking::getTitle))
4756
.collect(
48-
Collectors.groupingBy(
57+
groupingBy(
4958
ChangelogEntry.Breaking::isNotable,
50-
Collectors.groupingBy(ChangelogEntry.Breaking::getArea, TreeMap::new, Collectors.toList())
59+
groupingBy(ChangelogEntry.Breaking::getArea, TreeMap::new, Collectors.toList())
5160
)
5261
);
5362

5463
final Map<String, List<ChangelogEntry.Deprecation>> deprecationsByArea = entries.stream()
5564
.map(ChangelogEntry::getDeprecation)
5665
.filter(Objects::nonNull)
57-
.collect(Collectors.groupingBy(ChangelogEntry.Deprecation::getArea, TreeMap::new, Collectors.toList()));
66+
.sorted(comparing(ChangelogEntry.Deprecation::getTitle))
67+
.collect(groupingBy(ChangelogEntry.Deprecation::getArea, TreeMap::new, Collectors.toList()));
5868

5969
final Map<String, Object> bindings = new HashMap<>();
6070
bindings.put("breakingChangesByNotabilityByArea", breakingChangesByNotabilityByArea);
6171
bindings.put("deprecationsByArea", deprecationsByArea);
62-
bindings.put("isElasticsearchSnapshot", VersionProperties.isElasticsearchSnapshot());
72+
bindings.put("isElasticsearchSnapshot", version.isSnapshot());
6373
bindings.put("majorDotMinor", version.getMajor() + "." + version.getMinor());
6474
bindings.put("majorMinor", String.valueOf(version.getMajor()) + version.getMinor());
6575
bindings.put("nextMajor", (version.getMajor() + 1) + ".0");

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/ChangelogEntry.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class ChangelogEntry {
3737
private Highlight highlight;
3838
private Breaking breaking;
3939
private Deprecation deprecation;
40-
private List<String> versions;
4140

4241
private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
4342

@@ -113,14 +112,6 @@ public void setDeprecation(Deprecation deprecation) {
113112
this.deprecation = deprecation;
114113
}
115114

116-
public List<String> getVersions() {
117-
return versions;
118-
}
119-
120-
public void setVersions(List<String> versions) {
121-
this.versions = versions;
122-
}
123-
124115
@Override
125116
public boolean equals(Object o) {
126117
if (this == o) {
@@ -136,29 +127,27 @@ public boolean equals(Object o) {
136127
&& Objects.equals(type, that.type)
137128
&& Objects.equals(summary, that.summary)
138129
&& Objects.equals(highlight, that.highlight)
139-
&& Objects.equals(breaking, that.breaking)
140-
&& Objects.equals(versions, that.versions);
130+
&& Objects.equals(breaking, that.breaking);
141131
}
142132

143133
@Override
144134
public int hashCode() {
145-
return Objects.hash(pr, issues, area, type, summary, highlight, breaking, versions);
135+
return Objects.hash(pr, issues, area, type, summary, highlight, breaking);
146136
}
147137

148138
@Override
149139
public String toString() {
150140
return String.format(
151141
Locale.ROOT,
152-
"ChangelogEntry{pr=%d, issues=%s, area='%s', type='%s', summary='%s', highlight=%s, breaking=%s, deprecation=%s versions=%s}",
142+
"ChangelogEntry{pr=%d, issues=%s, area='%s', type='%s', summary='%s', highlight=%s, breaking=%s, deprecation=%s}",
153143
pr,
154144
issues,
155145
area,
156146
type,
157147
summary,
158148
highlight,
159149
breaking,
160-
deprecation,
161-
versions
150+
deprecation
162151
);
163152
}
164153

0 commit comments

Comments
 (0)