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

⚙️Various improvements #290

Merged
merged 19 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7b0b6b5
Start work for issue #287
CalvinWilkinson Sep 5, 2024
ad913de
deps: update deno versions to v0.224.0
CalvinWilkinson Sep 5, 2024
1121c16
deps: update kd_clients to version v1.0.0-preview.13
CalvinWilkinson Sep 5, 2024
7fb4c56
refactor: replace crayon lib and usage with built in deno coloring
CalvinWilkinson Sep 5, 2024
f5dd2c1
cleanup: remove unused code
CalvinWilkinson Sep 5, 2024
9d3a9c9
config: improve deno tasks
CalvinWilkinson Sep 5, 2024
084af1c
deps: update deno lock
CalvinWilkinson Sep 5, 2024
5b3c102
ide: add word to dictionary
CalvinWilkinson Sep 5, 2024
b109838
refactor: move run cli command function to default doc tool class
CalvinWilkinson Sep 5, 2024
9d80548
config: create deno tasks to format and lint deno code
CalvinWilkinson Sep 5, 2024
c308911
ci: convert delete old api docs script from args to env vars
CalvinWilkinson Sep 5, 2024
62a9bfc
ci,cleanup: remove unused script
CalvinWilkinson Sep 5, 2024
a344292
ci: convert api doc generation script from args to env vars
CalvinWilkinson Sep 5, 2024
993a33a
cleanup: remove unneeded code and config
CalvinWilkinson Sep 5, 2024
f9500d6
docs: update guide link tag names
CalvinWilkinson Sep 5, 2024
19ebf9a
ci: convert velaptor nuget update script from args to env vars
CalvinWilkinson Sep 5, 2024
1e939f4
ci: convert velaptor version check script from args to env vars
CalvinWilkinson Sep 5, 2024
45b250f
ci: improve branch status check
CalvinWilkinson Sep 5, 2024
54d0425
chore: convert playground script args to env vars
CalvinWilkinson Sep 5, 2024
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
1 change: 1 addition & 0 deletions .github/cicd/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"cSpell.words": [
"CICD",
"indianred",
"Kinson",
"Velaptor"
],
Expand Down
38 changes: 0 additions & 38 deletions .github/cicd/core/CLI.ts

This file was deleted.

52 changes: 44 additions & 8 deletions .github/cicd/core/DefaultDocTool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { existsSync, RepoClient } from "../deps.ts";
import { DotNetToolService } from "./services/DotNetToolService.ts";
import { Utils } from "./Utils.ts";
import { CLI } from "./CLI.ts";

/**
* Provides ability to generate documentation.
Expand Down Expand Up @@ -39,9 +38,11 @@ export class DefaultDocTool {
Utils.isNothing(outputDirPath);
Utils.isNothing(configFilePath);

const defaultDocToolRepoVar = (await this.repoClient.getVariables()).find((repoVar) => {
return repoVar.name === this.DEFAULT_DOC_DOTNET_TOOL_VERSION;
});
const defaultDocToolRepoVar = (await this.repoClient.getVariables()).find(
(repoVar) => {
return repoVar.name === this.DEFAULT_DOC_DOTNET_TOOL_VERSION;
},
);

if (defaultDocToolRepoVar === undefined) {
let errorMsg = `The required repo variable '${this.DEFAULT_DOC_DOTNET_TOOL_VERSION}' was not found.`;
Expand All @@ -55,16 +56,17 @@ export class DefaultDocTool {
? defaultDocToolRepoVar.value.substring(1)
: defaultDocToolRepoVar.value;

await this.dotNetToolService.setupDotNetTools(this.defaultDocToolName, defaultDocToolVersion);
await this.dotNetToolService.setupDotNetTools(
this.defaultDocToolName,
defaultDocToolVersion,
);

if (existsSync(outputDirPath, { isDirectory: true })) {
Deno.removeSync(outputDirPath, { recursive: true });
}

Deno.mkdirSync(outputDirPath, { recursive: true });

const cli = new CLI();

const args = [
"--AssemblyFilePath",
`${assemblyPath}`,
Expand All @@ -75,7 +77,7 @@ export class DefaultDocTool {
];

const command = `defaultdocumentation ${args.join(" ")}`;
const commandResult = await cli.runAsync(command);
const commandResult = await this.runAsync(command);

if (commandResult instanceof Error) {
Utils.printGitHubError(commandResult.message);
Expand All @@ -84,4 +86,38 @@ export class DefaultDocTool {

console.log(commandResult);
}

/**
* Runs the following CLI {@link command}.
* @param command The command to run.
* @returns The output of the command if successful, otherwise an error.
*/
public async runAsync(command: string): Promise<string | Error> {
if (command === undefined || command === null || command === "") {
const errorMsg = "The command parameter cannot be null or empty.";
console.log(errorMsg);
Deno.exit(1);
}

if (!command.includes(" ")) {
const errorMsg = "The command parameter must include a space.";
console.log(errorMsg);
Deno.exit(1);
}

const sections: string[] = command.split(" ");

const app = sections[0];
const args = sections.slice(1);

const cmd = new Deno.Command(app, { args: args });

const { code, stdout, stderr } = await cmd.output();

if (code === 0) {
return new TextDecoder().decode(stdout);
} else {
return new Error(new TextDecoder().decode(stderr));
}
}
}
25 changes: 11 additions & 14 deletions .github/cicd/core/DocProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { ValidateReleaseService } from "./services/ValidateReleaseService.ts";
import { MarkdownService } from "./services/MarkdownService.ts";
import { DefaultDocTool } from "./DefaultDocTool.ts";
import { Utils } from "./Utils.ts";
import { Yarn } from "./Yarn.ts";
import { crayon, existsSync, walkSync } from "../deps.ts";
import { existsSync, walkSync } from "../deps.ts";

/**
* Generates and performs post-processing on Velaptor API documentation.
Expand All @@ -14,7 +13,6 @@ export class DocProcessor {
private readonly cloneService: CloneRepoService;
private readonly validateReleaseService: ValidateReleaseService;
private readonly defaultDocTool: DefaultDocTool;
private readonly yarn: Yarn;

/**
* Initializes a new instance of the DocProcessor class.
Expand All @@ -24,7 +22,6 @@ export class DocProcessor {
this.cloneService = new CloneRepoService();
this.validateReleaseService = new ValidateReleaseService();
this.defaultDocTool = new DefaultDocTool(token);
this.yarn = new Yarn();
}

/**
Expand All @@ -34,24 +31,24 @@ export class DocProcessor {
*/
public async generateFromTag(apiDocsDirPath: string, releaseTag: string): Promise<void> {
if (Utils.isNothing(apiDocsDirPath)) {
console.log(crayon.red("The API doc dir path is required."));
console.log("%cThe API doc dir path is required.", "color: indianred");
Deno.exit(1);
}

if (Utils.isNothing(releaseTag)) {
console.log(crayon.red("The release tag is required."));
console.log("%cThe release tag is required.", "color: indianred");
Deno.exit(1);
}

console.log(crayon.cyan(`Validating Release '${releaseTag}'. . .`));
console.log(`%cValidating Release '${releaseTag}'. . .`, "color: cyan");
const isValid = await this.validateReleaseService.releaseExists(releaseTag);

if (!isValid) {
console.log(crayon.red(`The release '${releaseTag}' is not valid.`));
console.log(`%cThe release '${releaseTag}' is not valid.`, "color: indianred");
Deno.exit(1);
}

console.log(crayon.cyan(`Release '${releaseTag}' Valid.`));
console.log(`%cRelease '${releaseTag}' Valid.`, "color: cyan");

await this.run(apiDocsDirPath, releaseTag);
}
Expand All @@ -63,16 +60,16 @@ export class DocProcessor {
*/
public async generateFromBranch(apiDocDirPath: string, branchName: string): Promise<void> {
if (Utils.isNothing(apiDocDirPath)) {
console.log(crayon.red("The API doc dir path is required."));
console.log("%cThe API doc dir path is required.", "color: indianred");
Deno.exit(1);
}

if (Utils.isNothing(branchName)) {
console.log(crayon.red("The branch name is required."));
console.log("%cThe branch name is required.", "color: indianred");
Deno.exit(1);
}

console.log(crayon.cyan(`Branch Name '${branchName}' Valid.`));
console.log(`%cBranch Name '${branchName}' Valid.`, "color: cyan");

await this.run(apiDocDirPath, branchName);
}
Expand Down Expand Up @@ -141,11 +138,11 @@ export class DocProcessor {
*/
private async runProcess(startMsg: string, process: () => void | Promise<void>, endMsg: string): Promise<void> {
console.log("\n-----------------------------------------------------------------\n");
console.log(crayon.cyan(startMsg));
console.log(`%c${startMsg}`, "color: indianred");

await process();

console.log(crayon.cyan(`\n\n${endMsg}`));
console.log(`%c\n\n${endMsg}`, "color: indianred");
}

/**
Expand Down
64 changes: 0 additions & 64 deletions .github/cicd/core/Yarn.ts

This file was deleted.

10 changes: 4 additions & 6 deletions .github/cicd/deps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// THIRD PARTY MODULE IMPORTS
import { copySync, emptyDirSync, ensureDirSync, existsSync, walkSync } from "https://deno.land/std@0.207.0/fs/mod.ts";
import { basename, dirname, extname, parse, resolve } from "https://deno.land/std@0.207.0/path/mod.ts";
import { copySync, emptyDirSync, ensureDirSync, existsSync, walkSync } from "https://deno.land/std@0.224.0/fs/mod.ts";
import { basename, dirname, extname, parse, resolve } from "https://deno.land/std@0.224.0/path/mod.ts";
import { Input, Select } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/mod.ts";
import { RepoClient, TagClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.5/GitHubClients/mod.ts";
import { NuGetClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.5/PackageClients/NuGetClient.ts";
import { crayon } from "https://deno.land/x/crayon@3.3.3/mod.ts";
import { RepoClient, TagClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.13/GitHubClients/mod.ts";
import { NuGetClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.13/PackageClients/NuGetClient.ts";

// RAW GITHUB IMPORTS
import { Utils } from "https://raw.githubusercontent.com/KinsonDigital/Infrastructure/v13.6.3/cicd/core/Utils.ts";
Expand All @@ -16,7 +15,6 @@ export { copySync, emptyDirSync, ensureDirSync, existsSync, walkSync };
export { basename, dirname, extname, parse, resolve };
export { Input, Select };
export { NuGetClient, RepoClient, TagClient };
export { crayon };

// RAW GITHUB IMPORTS
export { Utils };
4 changes: 2 additions & 2 deletions .github/cicd/playground.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const _rootRepoDirPath = Deno.args[0];
const _token = Deno.args[1];
const _rootRepoDirPath = (Deno.env.get("ROOT_REPO_DIR_PATH") ?? "").trim().replaceAll("\\", "/");
const _token = (Deno.env.get("GITHUB_TOKEN") ?? "");
13 changes: 6 additions & 7 deletions .github/cicd/scripts/delete-oldest-api-docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { crayon } from "../deps.ts";
import { Utils } from "../core/Utils.ts";
import { DeleteAPIVersionService } from "../core/services/DeleteAPIVersionService.ts";
import { VersionsFileService } from "../core/services/VersionsFileService.ts";
Expand All @@ -8,21 +7,21 @@ import { VersionsFileService } from "../core/services/VersionsFileService.ts";
* to delete the oldest api docs version from the repo.
*/

if (Deno.args.length <= 0) {
const errorMsg = "The script requires a single argument of where to start searching for the versions file.";
const versionsFileSearchDirPath = (Deno.env.get("SEARCH_DIR_PATH") ?? "").trim();

if (versionsFileSearchDirPath === "") {
const errorMsg = "The environment variable 'SEARCH_DIR_PATH' does not exist.";
Utils.printGitHubError(errorMsg);
Deno.exit(1);
}

const versionsFileSearchDirPath = Deno.args[0].trim();

const allVersions = new VersionsFileService(versionsFileSearchDirPath).getVersions();
const oldestVersion = Utils.getOldestVersion(allVersions);

const versionsFileService: DeleteAPIVersionService = new DeleteAPIVersionService(versionsFileSearchDirPath);

console.log(crayon.cyan(`Deleting '${oldestVersion}' API docs. . .`));
console.log(`%cDeleting '${oldestVersion}' API docs. . .`, "color: cyan");

versionsFileService.deleteOldestDocs();

console.log(crayon.cyan(`API docs for version '${oldestVersion}' fully removed.`));
console.log(`%cAPI docs for version '${oldestVersion}' fully removed.`, "color: cyan");
Loading
Loading