Skip to content

Commit 8c11853

Browse files
committed
Add generateChangelog
Closes gh-9704
1 parent 985ae98 commit 8c11853

File tree

4 files changed

+113
-21
lines changed

4 files changed

+113
-21
lines changed

RELEASE.adoc

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,19 @@ $ ./gradlew saganCreateRelease saganDeleteRelease -PgitHubAccessToken=<github-pe
138138

139139
== 9. Update Release Notes on GitHub
140140

141-
* Download
142-
https://github.com/spring-io/github-changelog-generator/releases/latest[the
143-
GitHub release notes generator]
141+
Generate the Release Notes replacing:
144142

145-
....
146-
wget https://github.com/spring-io/github-changelog-generator/releases/download/v0.0.6/github-changelog-generator.jar
147-
....
148-
149-
* Generate the release notes
150-
151-
....
152-
java -jar github-changelog-generator.jar \
153-
--changelog.repository=spring-projects/spring-security
154-
--spring.config.location=scripts/release/release-notes-sections.yml \
155-
$MILESTONE release-notes
156-
....
143+
* <next-version> - Replace with the milestone you are releasing now (i.e. 5.5.0-RC1)
157144

158-
Note 1: `+$MILESTONE+` is something like `+5.2.1+` or `+5.3.0-M1+`. +
159-
Note 2: The location `+scripts/release/release-notes-sections.yml+` is
160-
relative to the `+spring-security+` repo. +
161-
Note 3: This will create a file on your filesystem
162-
called `+release-notes+`.
145+
----
146+
$ ./gradlew generateChangelog -P<next-version>
147+
----
163148

164149
* Copy the release notes to your clipboard (your mileage may vary with
165150
the following command)
166151

167152
....
168-
cat release-notes | xclip -selection clipboard
153+
cat build/changelog/release-notes.md | xclip -selection clipboard
169154
....
170155

171156
* Create the

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ apply plugin: 'org.jetbrains.kotlin.jvm'
1818
apply plugin: 'org.springframework.security.update-dependencies'
1919
apply plugin: 'org.springframework.security.sagan'
2020
apply plugin: 'org.springframework.github.milestone'
21+
apply plugin: 'org.springframework.github.changelog'
2122

2223
group = 'org.springframework.security'
2324
description = 'Spring Security'

buildSrc/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ gradlePlugin {
5252
id = "org.springframework.github.milestone"
5353
implementationClass = "org.springframework.gradle.github.milestones.GitHubMilestonePlugin"
5454
}
55+
githubChangelog {
56+
id = "org.springframework.github.changelog"
57+
implementationClass = "org.springframework.gradle.github.changelog.GitHubChangelogPlugin"
58+
}
5559
}
5660
}
5761

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2019-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.gradle.github.changelog;
18+
19+
import org.gradle.api.Action;
20+
import org.gradle.api.Plugin;
21+
import org.gradle.api.Project;
22+
import org.gradle.api.Task;
23+
import org.gradle.api.artifacts.Configuration;
24+
import org.gradle.api.artifacts.DependencySet;
25+
import org.gradle.api.artifacts.repositories.ExclusiveContentRepository;
26+
import org.gradle.api.artifacts.repositories.InclusiveRepositoryContentDescriptor;
27+
import org.gradle.api.artifacts.repositories.IvyArtifactRepository;
28+
import org.gradle.api.artifacts.repositories.IvyPatternRepositoryLayout;
29+
import org.gradle.api.tasks.JavaExec;
30+
31+
import java.io.File;
32+
import java.nio.file.Paths;
33+
34+
public class GitHubChangelogPlugin implements Plugin<Project> {
35+
36+
public static final String CHANGELOG_GENERATOR_CONFIGURATION_NAME = "changelogGenerator";
37+
38+
@Override
39+
public void apply(Project project) {
40+
createRepository(project);
41+
createChangelogGeneratorConfiguration(project);
42+
project.getTasks().register("generateChangelog", JavaExec.class, new Action<JavaExec>() {
43+
@Override
44+
public void execute(JavaExec generateChangelog) {
45+
File outputFile = project.file(Paths.get(project.getBuildDir().getPath(), "changelog/release-notes.md"));
46+
outputFile.getParentFile().mkdirs();
47+
generateChangelog.setGroup("Release");
48+
generateChangelog.setDescription("Generates the changelog");
49+
generateChangelog.setWorkingDir(project.getRootDir());
50+
generateChangelog.classpath(project.getConfigurations().getAt(CHANGELOG_GENERATOR_CONFIGURATION_NAME));
51+
generateChangelog.doFirst(new Action<Task>() {
52+
@Override
53+
public void execute(Task task) {
54+
generateChangelog.args("--spring.config.location=scripts/release/release-notes-sections.yml", project.property("nextVersion"), outputFile.toString());
55+
}
56+
});
57+
}
58+
});
59+
}
60+
61+
private void createChangelogGeneratorConfiguration(Project project) {
62+
project.getConfigurations().create(CHANGELOG_GENERATOR_CONFIGURATION_NAME, new Action<Configuration>() {
63+
@Override
64+
public void execute(Configuration configuration) {
65+
configuration.defaultDependencies(new Action<DependencySet>() {
66+
@Override
67+
public void execute(DependencySet dependencies) {
68+
dependencies.add(project.getDependencies().create("spring-io:github-changelog-generator:0.0.6"));
69+
}
70+
});
71+
}
72+
});
73+
}
74+
75+
private void createRepository(Project project) {
76+
IvyArtifactRepository repository = project.getRepositories().ivy(new Action<IvyArtifactRepository>() {
77+
@Override
78+
public void execute(IvyArtifactRepository repository) {
79+
repository.setUrl("https://github.com/");
80+
repository.patternLayout(new Action<IvyPatternRepositoryLayout>() {
81+
@Override
82+
public void execute(IvyPatternRepositoryLayout layout) {
83+
layout.artifact("[organization]/[artifact]/releases/download/v[revision]/[artifact].[ext]");
84+
}
85+
});
86+
repository.getMetadataSources().artifact();
87+
}
88+
});
89+
project.getRepositories().exclusiveContent(new Action<ExclusiveContentRepository>() {
90+
@Override
91+
public void execute(ExclusiveContentRepository exclusiveContentRepository) {
92+
exclusiveContentRepository.forRepositories(repository);
93+
exclusiveContentRepository.filter(new Action<InclusiveRepositoryContentDescriptor>() {
94+
@Override
95+
public void execute(InclusiveRepositoryContentDescriptor descriptor) {
96+
descriptor.includeGroup("spring-io");
97+
}
98+
});
99+
}
100+
});
101+
}
102+
}

0 commit comments

Comments
 (0)