Skip to content

Commit

Permalink
Replace (all) reference docs URLs for Antora
Browse files Browse the repository at this point in the history
Closes gh-34
  • Loading branch information
sjohnr committed Apr 16, 2024
1 parent bb39599 commit e8f7d37
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
8 changes: 4 additions & 4 deletions release-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ springRelease {
dayOfWeek = 4
referenceDocUrl = "https://docs.spring.io/spring-framework/reference/{version}/index.html"
apiDocUrl = "https://docs.spring.io/spring-framework/docs/{version}/api/"
replaceSnapshotVersionInReferenceDocUrl = true
replaceVersionInReferenceDocUrl = true
releaseVersionPrefix = "v"
}
----
Expand All @@ -36,7 +36,7 @@ springRelease {
* `dayOfWeek`: The day of the week when releases for this project are scheduled; valid values are 1 - 5 where 1 is Monday and 5 is Friday (required)
* `referenceDocUrl`: The template URL for a version of the reference documentation; can contain the variable `{version}` which is automatically substituted based on the current version (required)
* `apiDocUrl`: The template URL for a version of the API documentation; can contain the variable `{version}` which is automatically substituted based on the current version (required)
* `replaceSnapshotVersionInReferenceDocUrl`: Flag controlling whether `{version}` should be replaced (`true`) or left as-is (`false`) in the `referenceDocUrl`; Useful for working with Antora (optional, defaults to `false`)
* `replaceVersionInReferenceDocUrl`: Flag controlling whether `{version}` should be replaced (`true`) or left as-is (`false`) in the `referenceDocUrl`; Useful for working with Antora (optional, defaults to `false`)
* `releaseVersionPrefix`: The prefix used to tag the release version; typically used to prefix with `v`, e.g. `v1.0.1` (optional, defaults to an empty string)

== Tasks
Expand Down Expand Up @@ -197,7 +197,7 @@ The following command will close a release milestone (based on the current versi
=== `createRelease`

Create a GitHub release with release notes using the GitHub API and a new release version for the current project on spring.io using the Sagan API.
This task uses <<generateChangelog>> to generate the release notes and the configured `referenceDocUrl`, `apiDocUrl` and `replaceSnapshotVersionInReferenceDocUrl` values from the DSL.
This task uses <<generateChangelog>> to generate the release notes and the configured `referenceDocUrl`, `apiDocUrl` and `replaceVersionInReferenceDocUrl` values from the DSL.

NOTE: This task is a combination of <<createGitHubRelease>> and <<createSaganRelease>>, with the added benefit that the `createRelease` parameter (see *Task properties* below) determines whether both APIs are actually called.

Expand Down Expand Up @@ -253,7 +253,7 @@ The following command will perform a dry-run and provide output of what creating
=== `createSaganRelease`

Create a new release version for the current project on spring.io using the Sagan API.
This task uses the configured `referenceDocUrl`, `apiDocUrl` and `replaceSnapshotVersionInReferenceDocUrl` values from the DSL.
This task uses the configured `referenceDocUrl`, `apiDocUrl` and `replaceVersionInReferenceDocUrl` values from the DSL.

The following command will create a new release version:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public abstract class CreateReleaseTask extends DefaultTask {
public abstract Property<Boolean> getCreateRelease();

@Input
@Optional
@Deprecated
public abstract Property<Boolean> getReplaceSnapshotVersionInReferenceDocUrl();

@Input
public abstract Property<Boolean> getReplaceVersionInReferenceDocUrl();

@Input
@Optional
public abstract Property<String> getGitHubAccessToken();
Expand All @@ -79,19 +84,32 @@ public void createRelease() {
throw new MissingPropertyException("Please provide an access token with -PgitHubAccessToken=...");
}

// replace "-SNAPSHOT" in version numbers in referenceDocUrl for Antora
var replaceSnapshotVersion = getReplaceSnapshotVersionInReferenceDocUrl().get();
if (replaceSnapshotVersion && version.endsWith("-SNAPSHOT")) {
// replace version numbers in referenceDocUrl for Antora
var replaceVersion = getReplaceVersionInReferenceDocUrl().get();
var replaceSnapshotVersion = getReplaceSnapshotVersionInReferenceDocUrl().getOrNull();
if (replaceSnapshotVersion != null) {
replaceVersion = replaceSnapshotVersion;
}

if (replaceVersion) {
var versionMatcher = SpringReleases.versionMatcher(version);
var majorVersion = versionMatcher.group(1);
var minorVersion = versionMatcher.group(2);
var majorMinorVersion = "%s.%s-SNAPSHOT".formatted(majorVersion, minorVersion);
String majorMinorVersion;
if (version.endsWith("-SNAPSHOT")) {
majorMinorVersion = "%s.%s-SNAPSHOT".formatted(majorVersion, minorVersion);
}
else {
majorMinorVersion = "%s.%s".formatted(majorVersion, minorVersion);
}

referenceDocUrl = referenceDocUrl.replace("{version}", majorMinorVersion);
}

System.out.printf("%sCreating release for %s/%s@%s%n", createRelease ? "" : "[DRY RUN] ", repository.owner(),
repository.name(), version);
System.out.printf("%nRelease Notes:%n%n----%n%s%n----%n%n", body.trim());
System.out.printf("%nreferenceDocUrl=%s%napiDocUrl=%s%n", referenceDocUrl, apiDocUrl);

if (createRelease) {
var springReleases = new SpringReleases(gitHubAccessToken);
Expand Down Expand Up @@ -131,6 +149,7 @@ public static void register(Project project) {
task.getApiDocUrl().set(springRelease.getApiDocUrl());
task.getReplaceSnapshotVersionInReferenceDocUrl()
.set(springRelease.getReplaceSnapshotVersionInReferenceDocUrl());
task.getReplaceVersionInReferenceDocUrl().set(springRelease.getReplaceVersionInReferenceDocUrl());
task.getCreateRelease().set(createReleaseProvider.orElse(false));
task.getGitHubAccessToken()
.set(ProjectUtils.getProperty(project, SpringReleasePlugin.GITHUB_ACCESS_TOKEN_PROPERTY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.gradle.api.Project;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction;

/**
Expand All @@ -50,8 +51,13 @@ public abstract class CreateSaganReleaseTask extends DefaultTask {
public abstract Property<String> getApiDocUrl();

@Input
@Optional
@Deprecated
public abstract Property<Boolean> getReplaceSnapshotVersionInReferenceDocUrl();

@Input
public abstract Property<Boolean> getReplaceVersionInReferenceDocUrl();

@TaskAction
public void createSaganRelease() {
var gitHubAccessToken = getGitHubAccessToken().get();
Expand All @@ -60,13 +66,25 @@ public void createSaganRelease() {
var referenceDocUrl = getReferenceDocUrl().get();
var apiDocUrl = getApiDocUrl().get();

// replace "-SNAPSHOT" in version numbers in referenceDocUrl for Antora
var replaceSnapshotVersion = getReplaceSnapshotVersionInReferenceDocUrl().get();
if (replaceSnapshotVersion && version.endsWith("-SNAPSHOT")) {
// replace version numbers in referenceDocUrl for Antora
var replaceVersion = getReplaceVersionInReferenceDocUrl().get();
var replaceSnapshotVersion = getReplaceSnapshotVersionInReferenceDocUrl().getOrNull();
if (replaceSnapshotVersion != null) {
replaceVersion = replaceSnapshotVersion;
}

if (replaceVersion) {
var versionMatcher = SpringReleases.versionMatcher(version);
var majorVersion = versionMatcher.group(1);
var minorVersion = versionMatcher.group(2);
var majorMinorVersion = "%s.%s-SNAPSHOT".formatted(majorVersion, minorVersion);
String majorMinorVersion;
if (version.endsWith("-SNAPSHOT")) {
majorMinorVersion = "%s.%s-SNAPSHOT".formatted(majorVersion, minorVersion);
}
else {
majorMinorVersion = "%s.%s".formatted(majorVersion, minorVersion);
}

referenceDocUrl = referenceDocUrl.replace("{version}", majorMinorVersion);
}

Expand Down Expand Up @@ -98,6 +116,7 @@ public static void register(Project project) {
task.getApiDocUrl().set(springRelease.getApiDocUrl());
task.getReplaceSnapshotVersionInReferenceDocUrl()
.set(springRelease.getReplaceSnapshotVersionInReferenceDocUrl());
task.getReplaceVersionInReferenceDocUrl().set(springRelease.getReplaceVersionInReferenceDocUrl());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void apply(Project project) {
var springRelease = project.getExtensions().create(EXTENSION_NAME, SpringReleasePluginExtension.class);
springRelease.getRepositoryOwner().convention("spring-projects");
springRelease.getRepositoryName().convention(project.getRootProject().getName());
springRelease.getReplaceSnapshotVersionInReferenceDocUrl().convention(false);
springRelease.getReplaceVersionInReferenceDocUrl().convention(false);
springRelease.getReleaseVersionPrefix().convention("");

// Calculate the GitHub username for the provided access token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public interface SpringReleasePluginExtension {

Property<String> getApiDocUrl();

@Deprecated
Property<Boolean> getReplaceSnapshotVersionInReferenceDocUrl();

Property<Boolean> getReplaceVersionInReferenceDocUrl();

Property<String> getReleaseVersionPrefix();

}

0 comments on commit e8f7d37

Please sign in to comment.