Skip to content

Commit 6d3aa48

Browse files
Release: merge development into main
2 parents b694e75 + 74e6879 commit 6d3aa48

14 files changed

Lines changed: 925 additions & 1 deletion

File tree

.github/workflows/guides.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Notify Website of Guide Changes
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '**/guide.adoc'
8+
- 'docs-maven-plugin/**'
9+
10+
jobs:
11+
notify-website:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Trigger website rebuild
15+
run: |
16+
curl -X POST \
17+
-H "Accept: application/vnd.github+json" \
18+
-H "Authorization: Bearer ${{ secrets.WEBSITE_DISPATCH_TOKEN }}" \
19+
https://api.github.com/repos/infinispan/infinispan.github.io/dispatches \
20+
-d '{"event_type":"guides_updated"}'

.github/workflows/release-to-main.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Release to Main
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: 'Dry run (merge but do not push)'
8+
required: false
9+
default: 'false'
10+
type: boolean
511

612
jobs:
713
merge-to-main:
@@ -13,10 +19,47 @@ jobs:
1319
fetch-depth: 0
1420
token: ${{ secrets.GITHUB_TOKEN }}
1521

22+
- name: Extract main branch version
23+
id: main-version
24+
run: |
25+
git checkout main
26+
MAIN_VERSION=$(grep -m1 '<version>' pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
27+
MAIN_PARENT_VERSION=$(grep -A1 'infinispan-build-configuration-parent' pom.xml | grep '<version>' | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
28+
echo "project=$MAIN_VERSION" >> $GITHUB_OUTPUT
29+
echo "parent=$MAIN_PARENT_VERSION" >> $GITHUB_OUTPUT
30+
echo "Main project version: $MAIN_VERSION"
31+
echo "Main parent version: $MAIN_PARENT_VERSION"
32+
1633
- name: Merge development into main
1734
run: |
1835
git config user.name "github-actions[bot]"
1936
git config user.email "github-actions[bot]@users.noreply.github.com"
2037
git checkout main
2138
git merge origin/development -m "Release: merge development into main"
22-
git push origin main
39+
40+
- name: Restore main branch versions
41+
run: |
42+
MAIN_VERSION="${{ steps.main-version.outputs.project }}"
43+
MAIN_PARENT_VERSION="${{ steps.main-version.outputs.parent }}"
44+
DEV_VERSION=$(grep -m1 '<version>' pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
45+
DEV_PARENT_VERSION=$(grep -A1 'infinispan-build-configuration-parent' pom.xml | grep '<version>' | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
46+
47+
echo "Replacing project version: $DEV_VERSION -> $MAIN_VERSION"
48+
echo "Replacing parent version: $DEV_PARENT_VERSION -> $MAIN_PARENT_VERSION"
49+
50+
# Replace SNAPSHOT versions with main versions in all pom.xml files
51+
find . -name "pom.xml" -not -path "./.git/*" -exec sed -i "s|$DEV_VERSION|$MAIN_VERSION|g" {} +
52+
find . -name "pom.xml" -not -path "./.git/*" -exec sed -i "s|$DEV_PARENT_VERSION|$MAIN_PARENT_VERSION|g" {} +
53+
54+
git add -A
55+
git diff --cached --quiet || git commit -m "chore: restore main branch versions ($MAIN_VERSION)"
56+
57+
- name: Push to main
58+
if: ${{ inputs.dry_run != 'true' }}
59+
run: git push origin main
60+
61+
- name: Dry run summary
62+
if: ${{ inputs.dry_run == 'true' }}
63+
run: |
64+
echo "DRY RUN - not pushing. Merge result:"
65+
git log --oneline -5

deploy-guides-local.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
4+
TUTORIALS_DIR="${1:-$(pwd)}"
5+
WEBSITE_DIR="${2:-$(pwd)/../infinispan.github.io}"
6+
7+
echo "Building guides from: $TUTORIALS_DIR"
8+
echo "Deploying to website: $WEBSITE_DIR"
9+
10+
cd "$TUTORIALS_DIR"
11+
./mvnw -Pguides -pl docs-maven-plugin package -DskipTests -q
12+
13+
cp target/guides/index.yaml "$WEBSITE_DIR/_data/guides.yaml"
14+
mkdir -p "$WEBSITE_DIR/_guides"
15+
cp target/guides/guides/*.adoc "$WEBSITE_DIR/_guides/"
16+
17+
echo "Done. $(ls target/guides/guides/*.adoc | wc -l | tr -d ' ') guides deployed."

docs-maven-plugin/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<relativePath>../../pom.xml</relativePath>
8+
<version>16.2.0-SNAPSHOT</version>
9+
<groupId>org.infinispan.tutorial.simple</groupId>
10+
<artifactId>infinispan-simple-tutorials</artifactId>
11+
</parent>
12+
13+
<groupId>org.infinispan.tutorial.simple</groupId>
14+
<artifactId>docs-maven-plugin</artifactId>
15+
<version>16.2.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
17+
18+
<properties>
19+
<maven.compiler.source>17</maven.compiler.source>
20+
<maven.compiler.target>17</maven.compiler.target>
21+
<maven.compiler.release>17</maven.compiler.release>
22+
<asciidoctorj.version>3.0.1</asciidoctorj.version>
23+
<jackson.version>2.21.3</jackson.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.asciidoctor</groupId>
29+
<artifactId>asciidoctorj</artifactId>
30+
<version>${asciidoctorj.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.fasterxml.jackson.core</groupId>
34+
<artifactId>jackson-databind</artifactId>
35+
<version>${jackson.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.fasterxml.jackson.dataformat</groupId>
39+
<artifactId>jackson-dataformat-yaml</artifactId>
40+
<version>${jackson.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter</artifactId>
45+
<version>${version.junit6}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.codehaus.mojo</groupId>
54+
<artifactId>exec-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>generate-guide-metadata</id>
58+
<phase>package</phase>
59+
<goals>
60+
<goal>java</goal>
61+
</goals>
62+
<configuration>
63+
<mainClass>org.infinispan.tutorial.docs.GuideMetadataGenerator</mainClass>
64+
<arguments>
65+
<argument>${project.basedir}/..</argument>
66+
<argument>${project.basedir}/../target/guides</argument>
67+
</arguments>
68+
</configuration>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package org.infinispan.tutorial.docs;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.Comparator;
9+
import java.util.LinkedHashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Set;
13+
import java.util.stream.Stream;
14+
15+
import org.asciidoctor.Asciidoctor;
16+
import org.asciidoctor.Options;
17+
import org.asciidoctor.SafeMode;
18+
import org.asciidoctor.ast.Document;
19+
20+
import com.fasterxml.jackson.annotation.JsonInclude;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
23+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
24+
25+
public class GuideMetadataGenerator {
26+
27+
private static final Set<String> SKIP_DIRS = Set.of(
28+
"target", "docs", "documentation", "docs-maven-plugin", "non-java-clients", ".git", ".github");
29+
30+
private final Path srcDir;
31+
private final Path outputDir;
32+
33+
public GuideMetadataGenerator(Path srcDir, Path outputDir) {
34+
this.srcDir = srcDir;
35+
this.outputDir = outputDir;
36+
}
37+
38+
public static void main(String[] args) throws Exception {
39+
if (args.length < 2) {
40+
System.err.println("Usage: GuideMetadataGenerator <srcDir> <outputDir>");
41+
System.exit(1);
42+
}
43+
Path src = Path.of(args[0]);
44+
Path out = Path.of(args[1]);
45+
System.out.println("[INFO] Scanning for guides in: " + src);
46+
GuideMetadataGenerator generator = new GuideMetadataGenerator(src, out);
47+
generator.generate();
48+
System.out.println("[INFO] Guide metadata written to: " + out);
49+
}
50+
51+
public void generate() throws IOException {
52+
List<Map<String, Object>> guides = new ArrayList<>();
53+
Path guidesOutputDir = outputDir.resolve("guides");
54+
if (Files.exists(guidesOutputDir)) {
55+
try (Stream<Path> files = Files.list(guidesOutputDir)) {
56+
files.forEach(f -> {
57+
try { Files.delete(f); } catch (IOException ignored) {}
58+
});
59+
}
60+
}
61+
Files.createDirectories(guidesOutputDir);
62+
63+
Options options = Options.builder()
64+
.safe(SafeMode.UNSAFE)
65+
.build();
66+
67+
try (Asciidoctor asciidoctor = Asciidoctor.Factory.create()) {
68+
collectGuides(srcDir, "", asciidoctor, options, guides, guidesOutputDir);
69+
}
70+
71+
guides.sort(Comparator.comparing(g -> (String) g.get("id")));
72+
73+
Map<String, Object> index = new LinkedHashMap<>();
74+
index.put("guides", guides);
75+
76+
ObjectMapper om = new ObjectMapper(
77+
new YAMLFactory()
78+
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
79+
.disable(YAMLGenerator.Feature.SPLIT_LINES)
80+
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
81+
om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
82+
83+
Files.createDirectories(outputDir);
84+
om.writeValue(outputDir.resolve("index.yaml").toFile(), index);
85+
}
86+
87+
private void collectGuides(Path dir, String prefix, Asciidoctor asciidoctor,
88+
Options options, List<Map<String, Object>> guides, Path guidesOutputDir)
89+
throws IOException {
90+
try (Stream<Path> entries = Files.list(dir)) {
91+
List<Path> sorted = entries.sorted().toList();
92+
for (Path entry : sorted) {
93+
if (!Files.isDirectory(entry)) {
94+
continue;
95+
}
96+
String name = entry.getFileName().toString();
97+
if (name.startsWith(".") || SKIP_DIRS.contains(name)) {
98+
continue;
99+
}
100+
Path guideFile = entry.resolve("guide.adoc");
101+
String dirName = stripPrefix(entry.getFileName().toString());
102+
if (Files.exists(guideFile)) {
103+
String id = prefix.isEmpty() ? dirName : prefix + "-" + dirName;
104+
processGuide(guideFile, id, asciidoctor, options, guides, guidesOutputDir);
105+
}
106+
String subPrefix = prefix.isEmpty() ? dirName : prefix + "-" + dirName;
107+
collectGuides(entry, subPrefix, asciidoctor, options, guides, guidesOutputDir);
108+
}
109+
}
110+
}
111+
112+
private String stripPrefix(String dirName) {
113+
if (dirName.startsWith("infinispan-")) {
114+
return dirName.substring("infinispan-".length());
115+
}
116+
return dirName;
117+
}
118+
119+
private void processGuide(Path guideFile, String id, Asciidoctor asciidoctor,
120+
Options options, List<Map<String, Object>> guides, Path guidesOutputDir)
121+
throws IOException {
122+
String content = Files.readString(guideFile);
123+
Document doc = asciidoctor.load(content, options);
124+
125+
Map<String, Object> guide = new LinkedHashMap<>();
126+
guide.put("id", id);
127+
guide.put("title", doc.getDoctitle());
128+
guide.put("summary", attrString(doc, "summary"));
129+
guide.put("mode", attrString(doc, "mode"));
130+
guide.put("topics", splitComma(attrString(doc, "topics")));
131+
guide.put("keywords", splitComma(attrString(doc, "keywords")));
132+
guide.put("source-dir", attrString(doc, "source-dir"));
133+
guide.put("file", id + ".adoc");
134+
135+
String duration = attrString(doc, "duration");
136+
if (duration != null) {
137+
try {
138+
guide.put("duration", Integer.parseInt(duration));
139+
} catch (NumberFormatException e) {
140+
guide.put("duration", duration);
141+
}
142+
}
143+
144+
guides.add(guide);
145+
Files.copy(guideFile, guidesOutputDir.resolve(id + ".adoc"));
146+
}
147+
148+
private String attrString(Document doc, String name) {
149+
Object val = doc.getAttribute(name);
150+
return val != null ? val.toString() : null;
151+
}
152+
153+
private List<String> splitComma(String value) {
154+
if (value == null || value.isBlank()) {
155+
return List.of();
156+
}
157+
return Arrays.stream(value.split(","))
158+
.map(String::trim)
159+
.filter(s -> !s.isEmpty())
160+
.toList();
161+
}
162+
}

0 commit comments

Comments
 (0)