Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull release notes from keycloak-client repository #548

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions add-version-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -e

VERSION=$1
if [ "$VERSION" == "" ]; then
echo "usage: add-version-client.sh VERSION"
exit 1
fi

VERSION_NAME=`echo $VERSION | sed 's/.Final//' | sed 's/.CR[[:digit:]]//'`
DATE=`date +%F`

if [[ "$VERSION" == *".0" ]]; then
TEMPLATE="version-template.json"
else
TEMPLATE="versions/keycloak-client/${VERSION%.*}.0.json"
fi

if [ ! -f "$TEMPLATE" ]; then
echo "$TEMPLATE not found"
exit
fi

cat $TEMPLATE | sed "s/\"version\":.*/\"version\": \"$VERSION\",/" | sed 's/"date": ".*"/"date": "DATE"/' | sed "s/DATE/$DATE/" > versions/keycloak-client/$VERSION_NAME.json

CURRENT=`cat pom.xml | grep '<version.keycloak.client>' | cut -d '>' -f 2 | cut -d '<' -f 1`
LATEST=`echo -e "$CURRENT\n$VERSION" | sort -V -r | head -n 1`

sed -i "s|<version.keycloak.client>$CURRENT</version.keycloak.client>|<version.keycloak.client>$LATEST</version.keycloak.client>|g" pom.xml

mvn install
6 changes: 3 additions & 3 deletions add-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ fi
VERSION_NAME=`echo $VERSION | sed 's/.Final//' | sed 's/.CR[[:digit:]]//'`
DATE=`date +%F`

if [[ "$VERSION" == *".0" ]]; then
if [[ "$VERSION" == *".0" ]]; then
TEMPLATE="version-template.json"
else
TEMPLATE="versions/${VERSION%.*}.0.json"
TEMPLATE="versions/keycloak/{VERSION%.*}.0.json"
fi

if [ ! -f "$TEMPLATE" ]; then
echo "$TEMPLATE not found"
exit
fi

cat $TEMPLATE | sed "s/\"version\":.*/\"version\": \"$VERSION\",/" | sed 's/"date": ".*"/"date": "DATE"/' | sed "s/DATE/$DATE/" > versions/$VERSION_NAME.json
cat $TEMPLATE | sed "s/\"version\":.*/\"version\": \"$VERSION\",/" | sed 's/"date": ".*"/"date": "DATE"/' | sed "s/DATE/$DATE/" > versions/keycloak/$VERSION_NAME.json

CURRENT=`cat pom.xml | grep '<version.keycloak>' | cut -d '>' -f 2 | cut -d '<' -f 1`
LATEST=`echo -e "$CURRENT\n$VERSION" | sort -V -r | head -n 1`
Expand Down
10 changes: 10 additions & 0 deletions releases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
- id: keycloak
repo: keycloak/keycloak
releaseNotes: release/${version.getVersionShorter()}/docs/documentation/release_notes/topics/${version.getVersion()?replace(".", "_")}.adoc
attributeSources:
- release/${version.getVersionShorter()}/docs/documentation/topics/templates/document-attributes.adoc
- ${version.getVersion()}/docs/documentation/topics/templates/document-attributes.adoc
- id: keycloak-client
repo: keycloak/keycloak-client
releaseNotes: main/docs/release-notes/${version.getVersion()?replace(".", "_")}.adoc
36 changes: 32 additions & 4 deletions src/main/java/org/keycloak/webbuilder/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.keycloak.webbuilder.utils.YamlParser;

import java.io.File;
import java.util.LinkedList;

public class Context {

Expand All @@ -16,6 +17,8 @@ public class Context {
private final File resourcesDir;
private final File staticDir;
private final File versionsDir;
private final File keycloakVersionsDir;
private final File keycloakClientVersionsDir;
private final File extensionsDir;
private final File newsDir;
private final File blogDir;
Expand All @@ -25,11 +28,13 @@ public class Context {
private final File cacheDir;

private Config config;
private Versions versions;
private Versions keycloakVersions;
private Versions keycloakClientVersions;
private Extensions extensions;
private Blogs blogs;
private Guides guides;
private GuidesMetadata guidesMetadata;
private ReleasesMetadata releasesMetadata;
private News news;

private FreeMarker freeMarker;
Expand All @@ -45,6 +50,8 @@ public Context(File rootDir) throws Exception {
resourcesDir = new File(webSrcDir, "resources");
staticDir = new File(webSrcDir, "static");
versionsDir = new File(webSrcDir, "versions");
keycloakVersionsDir = new File(versionsDir, "keycloak");
keycloakClientVersionsDir = new File(versionsDir, "keycloak-client");
extensionsDir = new File(webSrcDir, "extensions");
newsDir = new File(webSrcDir, "news");
blogDir = new File(webSrcDir, "blog");
Expand All @@ -60,10 +67,12 @@ public void init() throws Exception {
config = loadConfig();
links = new Links(config);

versions = new Versions(versionsDir);
keycloakVersions = new Versions(keycloakVersionsDir);
keycloakClientVersions = new Versions(keycloakClientVersionsDir);
extensions = new Extensions(extensionsDir);
blogs = new Blogs(blogDir, versions, config, freeMarker, asciiDoctor);
blogs = new Blogs(blogDir, keycloakVersions, config, freeMarker, asciiDoctor);
guidesMetadata = new YamlParser().read(new File(getWebSrcDir(),"/guides.yaml"), GuidesMetadata.class);
releasesMetadata = new YamlParser().read(new File(getWebSrcDir(),"/releases.yaml"), ReleasesMetadata.class);
guides = new Guides(guidesMetadata, tmpDir, getWebSrcDir(), asciiDoctor);
news = new News(newsDir, blogs, config);

Expand Down Expand Up @@ -92,7 +101,22 @@ public Config config() {
}

public Versions versions() {
return versions;
return keycloakVersions;
}

public LinkedList<Versions.Version> versionsFor(String id) throws Exception {
switch (id) {
case "keycloak":
return versions();
case "keycloak-client":
return clientVersions();
default:
throw new Exception(String.format("No versions available for %s", id));
}
}

public Versions clientVersions() {
return keycloakClientVersions;
}

public Extensions extensions() {
Expand Down Expand Up @@ -159,6 +183,10 @@ public GuidesMetadata getGuidesMetadata() {
return guidesMetadata;
}

public ReleasesMetadata getReleasesMetadata() {
return releasesMetadata;
}

public File getGuidesDir() {
return guidesDir;
}
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/org/keycloak/webbuilder/ReleasesMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.keycloak.webbuilder;

import java.util.List;

public class ReleasesMetadata {
public List<ReleaseSource> sources;

public List<ReleaseSource> getSources() {
return sources;
}

public void setSources(List<ReleaseSource> sources) {
this.sources = sources;
}

public static class ReleaseSource {
private String id;
private String repo;
private String releaseNotes;
private List<String> attributeSources;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getRepo() {
return repo;
}

public void setRepo(String repo) {
this.repo = repo;
}

public String getReleaseNotes() {
return releaseNotes;
}

public void setReleaseNotes(String releaseNotes) {
this.releaseNotes = releaseNotes;
}

public List<String> getAttributeSources() {
return attributeSources;
}

public void setAttributeSources(List<String> attributeSources) {
this.attributeSources = attributeSources;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,73 +1,98 @@
package org.keycloak.webbuilder.builders;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.keycloak.webbuilder.ReleasesMetadata;
import org.keycloak.webbuilder.Versions;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReleaseNotesBuilder extends AbstractBuilder {

private static final String DOCUMENT_ATTRIBUTES_TAG_URL = "https://raw.githubusercontent.com/keycloak/keycloak/%s/docs/documentation/topics/templates/document-attributes.adoc";
private static final String DOCUMENT_ATTRIBUTES_BRANCH_URL = "https://raw.githubusercontent.com/keycloak/keycloak/release/%s/docs/documentation/topics/templates/document-attributes.adoc";

private static final String RELEASE_NOTES_URL = "https://raw.githubusercontent.com/keycloak/keycloak/release/%s/docs/documentation/release_notes/topics/%s.adoc";

@Override
protected String getTitle() {
return "Release Notes";
}

public void build() throws IOException {
File releasesCache = new File(context.getCacheDir(), "releases");
@Override
protected void build() throws Exception {
ReleasesMetadata metadata = context.getReleasesMetadata();

for (ReleasesMetadata.ReleaseSource source : metadata.getSources()) {
buildRelease(source);
}
}

private void buildRelease(ReleasesMetadata.ReleaseSource source) throws Exception {
File releasesCache = new File(context.getCacheDir(), "releases/" + source.getId());
List<Versions.Version> versions = context.versionsFor(source.getId());

for (Versions.Version v : context.versions()) {
for (Versions.Version version : versions) {
try {
File releaseCacheDir = new File(releasesCache, v.getVersion());
File releaseCacheDir = new File(releasesCache, version.getVersion());
releaseCacheDir.mkdirs();

File releaseNotesFile = new File(releaseCacheDir, "release-notes.html");
File releaseNotesMissingFile = new File(releaseCacheDir, "release-notes.empty");

if (releaseNotesFile.isFile()) {
printStep("exists", v.getVersion());
printStep("exists", source.getId() + " " + version.getVersion());
} else if (releaseNotesMissingFile.isFile()) {
printStep("missing", v.getVersion());
printStep("missing", source.getId() + " " + version.getVersion());
} else {
Map<String, Object> attributes = new HashMap<>();

attributes.put("project_buildType", "latest");
attributes.put("leveloffset", "2");
attributes.put("fragment", "yes");

Map<String, Object> branchAttributes = context.asciiDoctor().parseAttributes(new URL(String.format(DOCUMENT_ATTRIBUTES_BRANCH_URL, v.getVersionShorter())), attributes);
Map<String, Object> tagAttributes = context.asciiDoctor().parseAttributes(new URL(String.format(DOCUMENT_ATTRIBUTES_TAG_URL, v.getVersion())), attributes);
List<String> attributeSources = source.getAttributeSources();

attributes.putAll(branchAttributes);
attributes.putAll(tagAttributes);
if (attributeSources != null) {
for (String attributeSource : source.getAttributeSources()) {
URL templateUrl = buildTemplateUrl(source, version, attributeSource);
Map<String, Object> templateAttributes = context.asciiDoctor().parseAttributes(templateUrl, attributes);
attributes.putAll(templateAttributes);
}
}

String releaseNotesUrl = String.format(RELEASE_NOTES_URL, v.getVersionShorter(), v.getVersion().replace(".", "_"));
URL url = new URL(releaseNotesUrl);
URL releaseNotesURL = buildTemplateUrl(source, version, source.getReleaseNotes());

try {
context.asciiDoctor().writeFile(attributes, url, releaseNotesFile.getParentFile(), releaseNotesFile.getName());
printStep("created", v.getVersion());
context.asciiDoctor().writeFile(attributes, releaseNotesURL, releaseNotesFile.getParentFile(), releaseNotesFile.getName());
printStep("created", source.getId() + " " + version.getVersion());
} catch (FileNotFoundException e) {
printStep("notfound", v.getVersion());
printStep("notfound", source.getId() + " " + version.getVersion());
releaseNotesMissingFile.createNewFile();
}
}

if (releaseNotesFile.isFile()) {
v.setReleaseNotes("cache/releases/" + v.getVersion() + "/release-notes.html");
version.setReleaseNotes("cache/releases/" + source.getId() + "/" + version.getVersion() + "/release-notes.html");
}
} catch (Exception e) {
printStep("error", v.getVersion() + " (" + e.getClass().getSimpleName() + ")");
printStep("error", source.getId() + " " + version.getVersion() + " (" + e.getClass().getSimpleName() + ")");
}
}
}

private URL buildTemplateUrl(ReleasesMetadata.ReleaseSource source, Versions.Version version, String pathTemplate) throws Exception {
Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
Template template = new Template("template", pathTemplate, configuration);
StringWriter writer = new StringWriter();
Map<String, Object> attributes = new HashMap<>();

attributes.put("version", version);
template.process(attributes, writer);

String path = writer.toString();

return new URL(String.format("https://raw.githubusercontent.com/%s/%s", source.getRepo(), path));
}
}
File renamed without changes.
7 changes: 7 additions & 0 deletions versions/keycloak-client/26.0.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "2024-10-22",
"version": "26.0.1",
"blogTemplate": 3,
"documentationTemplate": 12,
"downloadTemplate": 24
}
7 changes: 7 additions & 0 deletions versions/keycloak-client/26.0.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "2024-10-31",
"version": "26.0.2",
"blogTemplate": 3,
"documentationTemplate": 12,
"downloadTemplate": 24
}
7 changes: 7 additions & 0 deletions versions/keycloak-client/26.0.3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "2024-11-19",
"version": "26.0.3",
"blogTemplate": 3,
"documentationTemplate": 12,
"downloadTemplate": 24
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions versions/keycloak/26.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "2024-10-04",
"version": "26.0.0",
"blogTemplate": 3,
"documentationTemplate": 12,
"downloadTemplate": 24
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading