Skip to content

Commit

Permalink
updated cdk to 2.99.0. doc cleanup and improvements. fixed issue with…
Browse files Browse the repository at this point in the history
… --profile on commands
  • Loading branch information
cwensel committed Sep 29, 2023
1 parent 839f957 commit dfb0442
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scenario.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/setup-node@v3

- name: Install CDK
run: npm install -g aws-cdk@2.96.2
run: npm install -g aws-cdk@2.99.0

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/wip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- '**.hbs'
jobs:
run-all-tests-and-release:
concurrency: scenarios-us-east-2
concurrency: scenarios-us-west-2
runs-on: ubuntu-latest

steps:
Expand All @@ -29,13 +29,13 @@ jobs:
uses: actions/setup-node@v3

- name: Install CDK
run: npm install -g aws-cdk@2.96.2
run: npm install -g aws-cdk@2.99.0

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Setup Env
run: echo "${{ vars.GRADLE_PROPERTIES_EAST }}" > gradle.properties
run: echo "${{ vars.GRADLE_PROPERTIES }}" > gradle.properties

- name: Run Tests
env:
Expand All @@ -47,7 +47,7 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-2
AWS_DEFAULT_REGION: us-west-2
run: |
./gradlew --no-daemon --info --stacktrace scenarios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ public class ExecCommandOptions extends CommonCommandOptions {
)
private boolean dryRun = false;

@CommandLine.Option(names = "--profile", description = "aws profile")
private String profile = System.getenv("AWS_PROFILE");

public boolean dryRun() {
return dryRun;
}

public String profile() {
return profile;
}
}
98 changes: 88 additions & 10 deletions clusterless-main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.jreleaser.model.Active
import org.jreleaser.model.Distribution
import org.jreleaser.model.Stereotype
import java.nio.file.Files

plugins {
id("clusterless.java-application-conventions")
Expand Down Expand Up @@ -100,6 +99,34 @@ tasks.register("release") {
dependsOn("jreleaserRelease")
}

tasks.register<Exec>("generateComponentModels") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"component",
"--model-all",
"--output-path",
"${buildDir}/generated-docs/modules/components"
)
}

tasks.register<Exec>("generateModelModels") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"model",
"--model-all",
"--output-path",
"${buildDir}/generated-docs/modules/models"
)
}

tasks.register<Exec>("generateComponentDocs") {
dependsOn("installDist")

Expand All @@ -114,20 +141,69 @@ tasks.register<Exec>("generateComponentDocs") {
)
}

tasks.register<Exec>("generateComponentIndex") {
tasks.register<Exec>("generateResourceIndex") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"component",
"resource",
"--list",
"--output-path",
"${buildDir}/generated-docs/modules/components/"
"${buildDir}/generated-docs/modules/components/",
"--append=false"
)
}

tasks.register<Exec>("generateArcIndex") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"arc",
"--list",
"--output-path",
"${buildDir}/generated-docs/modules/components/",
"--append=true"
)
mustRunAfter("generateBoundariesIndex")
}

tasks.register<Exec>("generateBarriersIndex") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"barrier",
"--list",
"--output-path",
"${buildDir}/generated-docs/modules/components/",
"--append=true"
)
mustRunAfter("generateArcIndex")
}

tasks.register<Exec>("generateBoundariesIndex") {
dependsOn("installDist")

workingDir = file("build/install/clusterless/bin")
commandLine = listOf(
"./cls",
"show",
"boundary",
"--list",
"--output-path",
"${buildDir}/generated-docs/modules/components/",
"--append=true"
)
mustRunAfter("generateResourceIndex")
}

tasks.register<Exec>("generateComponentPartial") {
dependsOn("installDist")

Expand Down Expand Up @@ -193,9 +269,14 @@ tasks.register<Exec>("generateModelPartial") {
}

tasks.register<Copy>("generateDocs") {
dependsOn("generateComponentModels")
dependsOn("generateComponentDocs")
dependsOn("generateComponentIndex")
dependsOn("generateResourceIndex")
dependsOn("generateArcIndex")
dependsOn("generateBarriersIndex")
dependsOn("generateBoundariesIndex")
dependsOn("generateComponentPartial")
dependsOn("generateModelModels")
dependsOn("generateModelDocs")
dependsOn("generateModelIndex")
dependsOn("generateModelPartial")
Expand Down Expand Up @@ -246,13 +327,10 @@ tasks.register("generateCLIIndex") {
dependsOn("generateCLIDocs")

doLast {
// remove cls-*-help.adoc files are they are redundant
fileTree("build/generated-docs/modules/commands/pages")
.filter { it.name.endsWith("-help.adoc") && it.name != "cls-help.adoc" }
.forEach { Files.delete(it.toPath()) }

// remove cls-*-help.adoc files from the index as they are redundant
val names = fileTree("build/generated-docs/modules/commands/pages")
.map { it.name }
.filter { it == "cls-help.adoc" || !it.endsWith("-help.adoc") }
.sortedBy { it.substringBefore(".") }
.toList()
println(names)
Expand Down
108 changes: 78 additions & 30 deletions clusterless-main/src/main/java/clusterless/BaseShowElements.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import clusterless.json.JSONUtil;
import clusterless.model.Struct;
import clusterless.naming.Label;
import clusterless.util.OrderedSafeMaps;
import org.jetbrains.annotations.NotNull;
import picocli.CommandLine;

Expand Down Expand Up @@ -44,6 +45,14 @@ public abstract class BaseShowElements extends ShowCommand.BaseShow {
)
Optional<String> name;

@CommandLine.Option(
names = "--append",
arity = "1",
description = "Append to the file",
hidden = true
)
boolean append = false;

interface Handler {
int handle(String name, Class<?> documentedClass, Class<? extends Struct> structClass);
}
Expand All @@ -57,60 +66,68 @@ private static String createFileName(String name) {
}

protected static String getModel(Class<? extends Struct> modelClass) {
String model;
try {
// todo: have provider return a model instance with default values for use as a template
model = JSONUtil.writeAsPrettyStringSafe(modelClass.getConstructor().newInstance());
return JSONUtil.writeAsPrettyStringSafe(modelClass.getConstructor().newInstance());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
throw new RuntimeException(e);
}
return model;
}

@NotNull
protected abstract String elementType();

protected String elementSubType() {
return elementType();
}

protected abstract Collection<String> getNames();

protected Integer handleList() {
Collection<String> ordered = getNames();

if (output.isPresent()) {
try {
Path path = Paths.get(output.get());
path.toFile().mkdirs();
writeFromTemplate(ordered);
} else {
showCommand.main.printer().println(ordered);
}

File file = path
.resolve(name.orElse("nav.adoc"))
.toFile();
return 0;
}

Writer writer = new FileWriter(file);
protected void writeFromTemplate(Collection<String> ordered) {
try {
Path path = Paths.get(output.get());
path.toFile().mkdirs();

List<Map<String, String>> elements = new ArrayList<>();
File file = path
.resolve(name.orElse("nav.adoc"))
.toFile();

ordered.forEach(c -> elements.add(Map.of(
"name", c,
"filename", BaseShowElements.createFileName(c)
)));
Writer writer = new FileWriter(file, append);

Map<String, Object> params = Map.of(
"title", elementType(),
"type", elementType().toLowerCase(),
"elements", elements
);
List<Map<String, String>> elements = new ArrayList<>();

String partial = template.orElse("elements-list-adoc"); // a generic template
showCommand.main.printer().writeWithTemplate("/templates/" + partial, params, writer);
ordered.forEach(c -> elements.add(Map.of(
"name", c,
"filename", BaseShowElements.createFileName(c)
)));

} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
showCommand.main.printer().println(ordered);
}
Map<String, Object> params = OrderedSafeMaps.of(
"title", !append ? elementType() : null,
"component", elementSubType(),
"type", elementType().toLowerCase(),
"elements", elements
);

return 0;
String template = elementType().equals(elementSubType()) ? "elements-list-adoc" : "elements-sublist-adoc";
String partial = this.template.orElse(template); // a generic template
showCommand.main.printer().writeWithTemplate("/templates/" + partial, params, writer);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
Expand All @@ -121,6 +138,14 @@ protected Integer handleDescribeAll() {
return 0;
}

@Override
protected Integer handleModelAll() throws Exception {
for (String component : getNames()) {
handle(component, this::printModel);
}
return 0;
}

protected Integer handleModel() {
return handle(exclusive.model.orElseThrow(), this::printModel);
}
Expand All @@ -133,7 +158,30 @@ protected Integer handleDescribe() {
protected abstract int handle(String name, Handler func);

protected int printModel(String name, Class<?> documentedClass, Class<? extends Struct> modelClass) {
showCommand.main.printer().println(getModel(modelClass));
try {
Writer writer = showCommand.main.printer().writer();

if (output.isPresent()) {
Path path = Paths.get(output.get()).resolve("examples");
path.toFile().mkdirs();

File file = path
.resolve(BaseShowElements.createFileName(name))
.toFile();

writer = new FileWriter(file);
}

writer.append(getModel(modelClass));
writer.append("\n");

writer.flush();
writer.close();

} catch (IOException e) {
throw new UncheckedIOException(e);
}

return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*/
@CommandLine.Command(
name = "config",
description = "Manage local and global configuration settings."
description = "Manage local and global configuration settings.",
subcommands = {CommandLine.HelpCommand.class}
)
public class ConfigCommand {
@CommandLine.ParentCommand
Expand Down
Loading

0 comments on commit dfb0442

Please sign in to comment.