Skip to content

Commit 3ccb2f9

Browse files
committed
WIP changelog bundles for release notes
1 parent 1828db6 commit 3ccb2f9

File tree

11 files changed

+2628
-155
lines changed

11 files changed

+2628
-155
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.release;
11+
12+
import com.fasterxml.jackson.annotation.JsonInclude;
13+
14+
import com.fasterxml.jackson.databind.ObjectMapper;
15+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
16+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
17+
import org.gradle.api.DefaultTask;
18+
import org.gradle.api.file.ConfigurableFileCollection;
19+
import org.gradle.api.file.Directory;
20+
import org.gradle.api.file.DirectoryProperty;
21+
import org.gradle.api.file.FileCollection;
22+
import org.gradle.api.file.RegularFile;
23+
import org.gradle.api.file.RegularFileProperty;
24+
import org.gradle.api.logging.Logger;
25+
import org.gradle.api.logging.Logging;
26+
import org.gradle.api.model.ObjectFactory;
27+
import org.gradle.api.tasks.InputDirectory;
28+
import org.gradle.api.tasks.InputFiles;
29+
import org.gradle.api.tasks.OutputFile;
30+
import org.gradle.api.tasks.TaskAction;
31+
import org.gradle.process.ExecOperations;
32+
33+
import java.io.File;
34+
import java.io.IOException;
35+
import java.io.StringReader;
36+
import java.time.Instant;
37+
import java.util.Comparator;
38+
import java.util.List;
39+
import java.util.Properties;
40+
41+
import javax.inject.Inject;
42+
43+
import static java.util.stream.Collectors.toList;
44+
45+
public class BundleChangelogsTask extends DefaultTask {
46+
private static final Logger LOGGER = Logging.getLogger(BundleChangelogsTask.class);
47+
48+
private final ConfigurableFileCollection changelogs;
49+
50+
private final RegularFileProperty bundleFile;
51+
private final DirectoryProperty changelogDirectory;
52+
53+
private final GitWrapper gitWrapper;
54+
55+
private static final ObjectMapper yamlMapper = new ObjectMapper(
56+
new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
57+
.disable(YAMLGenerator.Feature.SPLIT_LINES)
58+
.enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)
59+
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
60+
.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
61+
).setSerializationInclusion(JsonInclude.Include.NON_NULL);
62+
63+
@Inject
64+
public BundleChangelogsTask(ObjectFactory objectFactory, ExecOperations execOperations) {
65+
changelogs = objectFactory.fileCollection();
66+
67+
bundleFile = objectFactory.fileProperty();
68+
changelogDirectory = objectFactory.directoryProperty();
69+
70+
gitWrapper = new GitWrapper(execOperations);
71+
}
72+
73+
@TaskAction
74+
public void executeTask() throws IOException {
75+
final String upstreamRemote = gitWrapper.getUpstream();
76+
77+
String ref = "main";
78+
try {
79+
checkoutChangelogs(gitWrapper, upstreamRemote, ref);
80+
Properties props = new Properties();
81+
props.load(new StringReader(gitWrapper.runCommand("git", "show", ref + ":build-tools-internal/version.properties")));
82+
String version = props.getProperty("elasticsearch");
83+
84+
LOGGER.info("Finding changelog files...");
85+
86+
List<ChangelogEntry> entries = this.changelogDirectory.getAsFileTree()
87+
.getFiles()
88+
.stream()
89+
.map(ChangelogEntry::parse)
90+
.sorted(Comparator.comparing(ChangelogEntry::getPr))
91+
.collect(toList());
92+
93+
ChangelogBundle bundle = new ChangelogBundle(version, Instant.now().toString(), entries);
94+
95+
yamlMapper.writeValue(new File("docs/release-notes/changelog-bundles/" + version + ".yml"), bundle);
96+
} finally {
97+
gitWrapper.runCommand("git", "restore", "-s@", "-SW", "--", "docs/changelog");
98+
}
99+
}
100+
101+
private static void checkoutChangelogs(GitWrapper gitWrapper, String upstream, String ref) {
102+
gitWrapper.updateRemote(upstream);
103+
// TODO check for changes first
104+
gitWrapper.runCommand("git", "checkout", ref, "--", "docs/changelog");
105+
}
106+
107+
@InputDirectory
108+
public DirectoryProperty getChangelogDirectory() {
109+
return changelogDirectory;
110+
}
111+
112+
public void setChangelogDirectory(Directory dir) {
113+
this.changelogDirectory.set(dir);
114+
}
115+
116+
@InputFiles
117+
public FileCollection getChangelogs() {
118+
return changelogs;
119+
}
120+
121+
public void setChangelogs(FileCollection files) {
122+
this.changelogs.setFrom(files);
123+
}
124+
125+
@OutputFile
126+
public RegularFileProperty getBundleFile() {
127+
return bundleFile;
128+
}
129+
130+
public void setBundleFile(RegularFile file) {
131+
this.bundleFile.set(file);
132+
}
133+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.release;
11+
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
14+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
15+
16+
import org.gradle.api.logging.Logger;
17+
import org.gradle.api.logging.Logging;
18+
19+
import java.io.File;
20+
import java.io.IOException;
21+
import java.io.UncheckedIOException;
22+
import java.util.List;
23+
24+
public record ChangelogBundle(String version, String generated, List<ChangelogEntry> changelogs) {
25+
26+
private static final Logger LOGGER = Logging.getLogger(GenerateReleaseNotesTask.class);
27+
private static final ObjectMapper yamlMapper = new ObjectMapper(
28+
new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES).disable(YAMLGenerator.Feature.SPLIT_LINES)
29+
);
30+
31+
public static ChangelogBundle parse(File file) {
32+
try {
33+
return yamlMapper.readValue(file, ChangelogBundle.class);
34+
} catch (IOException e) {
35+
LOGGER.error("Failed to parse changelog bundle from " + file.getAbsolutePath(), e);
36+
throw new UncheckedIOException(e);
37+
}
38+
}
39+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.gradle.internal.release;
1111

12+
import com.fasterxml.jackson.annotation.JsonIgnore;
1213
import com.fasterxml.jackson.databind.ObjectMapper;
1314
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
1415

@@ -35,12 +36,12 @@ public class ChangelogEntry {
3536
private static final Logger LOGGER = Logging.getLogger(GenerateReleaseNotesTask.class);
3637

3738
private Integer pr;
38-
private List<Integer> issues;
39+
private String summary;
3940
private String area;
4041
private String type;
41-
private String summary;
42-
private Highlight highlight;
42+
private List<Integer> issues;
4343
private Breaking breaking;
44+
private Highlight highlight;
4445
private Deprecation deprecation;
4546

4647
private static final ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
@@ -193,6 +194,7 @@ public void setBody(String body) {
193194
this.body = body;
194195
}
195196

197+
@JsonIgnore
196198
public String getAnchor() {
197199
return generatedAnchor(this.title);
198200
}
@@ -278,6 +280,7 @@ public void setNotable(boolean notable) {
278280
this.notable = notable;
279281
}
280282

283+
@JsonIgnore
281284
public String getAnchor() {
282285
return generatedAnchor(this.title);
283286
}

0 commit comments

Comments
 (0)