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

📋Move default doc tool version to repo variable #135

Merged
merged 17 commits into from
Nov 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/cicd/core/CloneRepoService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from "std/path/mod.ts";
import { resolve } from "../deps.ts";
import { Utils } from "./Utils.ts";

/**
Expand Down
5 changes: 2 additions & 3 deletions .github/cicd/core/Console.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { writeAllSync } from "std/streams/write_all.ts";

/**
* Provides the ability read from and write to the console.
*/
Expand All @@ -10,7 +8,8 @@ export class Console {
*/
public writeLine(text: string): void {
const encodedText = new TextEncoder().encode(text);
writeAllSync(Deno.stdout, encodedText);

Deno.stdout.writeSync(encodedText);
}

/**
Expand Down
29 changes: 26 additions & 3 deletions .github/cicd/core/DefaultDocTool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RepoClient } from "../deps.ts";
import { Directory } from "./Directory.ts";
import { DotNetToolService } from "./DotNetToolService.ts";
import { Utils } from "./Utils.ts";
Expand All @@ -7,14 +8,20 @@ import { Utils } from "./Utils.ts";
*/
export class DefaultDocTool {
private readonly dotNetToolService: DotNetToolService;
private readonly defaultDocToolVersion = "0.8.2";
private readonly repoClient: RepoClient;
private readonly defaultDocToolName = "defaultdocumentation.console";
private readonly DEFAULT_DOC_DOTNET_TOOL_VERSION = "DEFAULT_DOC_DOTNET_TOOL_VERSION";

/**
* Initializes a new instance of the DefaultDocTool class.
* @param token The GitHub token to use for accessing the GitHub API.
*/
constructor() {
constructor(token: string) {
const ownerName = "KinsonDigital";
const repoName = "VelaptorDocs";

this.dotNetToolService = new DotNetToolService();
this.repoClient = new RepoClient(ownerName, repoName, token);
}

/**
Expand All @@ -32,7 +39,23 @@ export class DefaultDocTool {
Utils.isNothing(outputDirPath);
Utils.isNothing(configFilePath);

await this.dotNetToolService.setupDotNetTools(this.defaultDocToolName, this.defaultDocToolVersion);
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.`;
errorMsg += "\nPlease create the variable in the repo settings and try again.";
errorMsg += "\nThe required variable is used to specify the version of the ";
errorMsg += `dotnet tool '${this.defaultDocToolName}' to use.`;
Deno.exit(1);
}

const defaultDocToolVersion = defaultDocToolRepoVar.value.toLowerCase().startsWith("v")
? defaultDocToolRepoVar.value.substring(1)
: defaultDocToolRepoVar.value;

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

if (Directory.exists(outputDirPath)) {
Deno.removeSync(outputDirPath, { recursive: true });
Expand Down
5 changes: 3 additions & 2 deletions .github/cicd/core/DocProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export class DocProcessor {

/**
* Initializes a new instance of the DocProcessor class.
* @param token The GitHub token to use for accessing the GitHub API.
*/
constructor() {
constructor(token: string) {
this.cloneService = new CloneRepoService();
this.validateReleaseService = new ValidateReleaseService();
this.defaultDocTool = new DefaultDocTool();
this.defaultDocTool = new DefaultDocTool(token);
this.yarn = new Yarn();
}

Expand Down
6 changes: 1 addition & 5 deletions .github/cicd/core/Path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Utils } from "./Utils.ts";
import { dirname, extname } from "std/path/mod.ts";
import { dirname, extname } from "../deps.ts";

/**
* Provides path related operations.
Expand Down Expand Up @@ -189,10 +189,6 @@ export class Path {

path = path.replaceAll("\\", "/");

if (this.isFilePath(path)) {
return path;
}

return path.endsWith("/") ? path : `${path}/`;
}

Expand Down
10 changes: 6 additions & 4 deletions .github/cicd/core/ValidateReleaseService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { TagClient } from "clients/TagClient.ts";
import { NuGetClient } from "clients/NuGetClient.ts";
import { TagClient, NuGetClient } from "../deps.ts";
import { Utils } from "./Utils.ts";

/**
* Validates that a Velaptor release exists.
*/
export class ValidateReleaseService {
private readonly ownerName = "KinsonDigital";
private readonly repoName = "Velaptor";

/**
* Returns a value indicating whether or not the release exists.
* @param version The release version to check.
Expand All @@ -32,9 +34,9 @@ export class ValidateReleaseService {
throw Error("The tag to check is required.");
}

const tagClient: TagClient = new TagClient();
const tagClient: TagClient = new TagClient(this.ownerName, this.repoName);

return await tagClient.tagExists("Velaptor", tagToCheck);
return await tagClient.tagExists(tagToCheck);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion .github/cicd/core/VersionsFileService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extname } from "std/path/mod.ts";
import { extname } from "../deps.ts";
import { Guard } from "./Guard.ts";
import { Utils } from "./Utils.ts";

Expand Down
10 changes: 10 additions & 0 deletions .github/cicd/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { emptyDirSync, copySync, ensureDirSync } from "https://deno.land/std@0.205.0/fs/mod.ts";
import { resolve, dirname, extname } from "https://deno.land/std@0.205.0/path/mod.ts";
import { Input, Select } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/mod.ts";
import { TagClient, RepoClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.3/GitHubClients/mod.ts";
import { NuGetClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.3/PackageClients/NuGetClient.ts";

export { emptyDirSync, copySync, ensureDirSync };
export { resolve, dirname, extname };
export { Input, Select };
export { TagClient, RepoClient, NuGetClient };
6 changes: 3 additions & 3 deletions .github/cicd/manual-testing/reset-docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { emptyDirSync } from "std/fs/empty_dir.ts";
import { copySync } from "std/fs/copy.ts";
import { ensureDirSync } from "std/fs/ensure_dir.ts";
import { emptyDirSync } from "../deps.ts";
import { copySync } from "../deps.ts";
import { ensureDirSync } from "../deps.ts";

const blueText = "\u001b[1;34m";
const white = "\u001b[0m";
Expand Down
2 changes: 1 addition & 1 deletion .github/cicd/scripts/create-docusaurus-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Input } from "cliffy/prompt/input.ts";
import { Input } from "../deps.ts";

console.clear();

Expand Down
2 changes: 1 addition & 1 deletion .github/cicd/scripts/delete-api-docs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directory } from "../core/Directory.ts";
import { Path } from "../core/Path.ts";
import { Select } from "cliffy/prompt/select.ts";
import { Select } from "../deps.ts";
import { DeleteAPIVersionService } from "../core/DeleteAPIVersionService.ts";
import { chalk } from "../core/chalk.ts";

Expand Down
33 changes: 21 additions & 12 deletions .github/cicd/scripts/generate-new-api-docs.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { Input, Select } from "cliffy/prompt/mod.ts";
import { Input, Select } from "../deps.ts";
import { DocProcessor } from "../core/DocProcessor.ts";

if (Deno.args.length < 2) {
const errorMsg = `The required number of arguments is 2 but only '${Deno.args.length}' were given.`;
console.clear();

if (Deno.args.length < 3) {
let errorMsg = `The required number of arguments is 3 but only '${Deno.args.length}' were given.`;
errorMsg += "\nThe required arguments are:";
errorMsg += "\n\t1. The path to the directory to generate the API documentation.";
errorMsg += "\n\t2. The tag or branch name to generate the API documentation from.";
errorMsg += "\n\t3. The GitHub token to use for accessing the GitHub API.";

console.error(`::error::${errorMsg}`);
Deno.exit(1);
}

const generateOutputDirPath: string = Deno.args[0];
let tagOrBranch = Deno.args[1].trim().toLowerCase();

const isInteractive = Deno.args.length >= 3 &&
Deno.args.length === 3 &&
Deno.args[2].trim().toLowerCase() === "true";
const token = Deno.args[2].trim();

// Optional argument
const isInteractive = Deno.args.length >= 4 && Deno.args[3].trim().toLowerCase() === "true";

console.log(`Generate Output Dir Path: ${generateOutputDirPath}`);

/*NOTE:
This script is executed by the 'api-release.yml' workflow. The workflow
will always execute this script as being non-interactive, and will also
always pass in a tag/version value.
*/
This script is executed by the 'api-release.yml' workflow. The workflow
will always execute this script as being non-interactive, and will also
always pass in a tag/version value.
*/

// Set to a default value of 'api version' for non-interactive mode
let generateSrcType = "api version";
Expand All @@ -34,7 +43,7 @@ if (isInteractive) {
const message = generateSrcType === "api version"
? "Enter the release version"
: "Enter the branch name";

const minLength = generateSrcType === "api version" ? 5 : 0;

tagOrBranch = await Input.prompt({
Expand All @@ -53,7 +62,7 @@ if (isInteractive) {
tagOrBranch = tagOrBranch.startsWith("v") ? tagOrBranch : `v${tagOrBranch}`;
}

const docProcessor = new DocProcessor();
const docProcessor = new DocProcessor(token);

if (generateSrcType === "branch") {
await docProcessor.generateFromBranch(generateOutputDirPath, tagOrBranch);
Expand Down
9 changes: 6 additions & 3 deletions .github/cicd/scripts/velaptor-version-exists.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagClient } from "clients/TagClient.ts";
import { TagClient } from "../deps.ts";

if (Deno.args.length < 2) {
const errorMsg = `The required number of arguments is 2 but received ${Deno.args.length}.`;
Expand Down Expand Up @@ -35,9 +35,12 @@ if (!versionRegex.test(version)) {
Deno.exit(1);
}

const tagClient: TagClient = new TagClient(token);
const ownerName = "KinsonDigital";
const repoName = "Velaptor";

const versionDoesNotExist = !(await tagClient.tagExists("Velaptor", version));
const tagClient: TagClient = new TagClient(ownerName, repoName, token);

const versionDoesNotExist = !(await tagClient.tagExists(version));

if (versionDoesNotExist) {
const errorMsg = `The Velaptor version '${version}' does not exist.`;
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/api-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,25 @@ jobs:
# Move the 'next-versioning.ts' to scripts folder
- name: Disable Next Version Feature
run: |
deno run `
--allow-read `
--allow-write `
deno run --allow-read --allow-write `
"${{ github.workspace }}/.github/cicd/manual-testing/next-versioning.ts" `
"${{ github.workspace }}/docusaurus.config.js" `
"next-version" `
"enable";

- name: Remove Oldest API Version
run: |
deno run `
--allow-read `
--allow-write `
deno run --allow-read --allow-write `
"${{ github.workspace }}/.github/cicd/scripts/delete-oldest-api-docs.ts";

- name: Generate API Docs (${{ inputs.api-version }})
run: |
deno run `
--allow-read `
--allow-write `
--allow-run `
--allow-net `
--allow-read --allow-write --allow-run --allow-net `
"${{ github.workspace }}/.github/cicd/scripts/generate-new-api-docs.ts" `
"${{ github.workspace }}/docs/api" `
"${{ inputs.api-version }}";
"${{ inputs.api-version }}" `
"${{ secrets.CICD_TOKEN }}";

- name: Install Dependencies (YARN)
run: yarn install;
Expand All @@ -148,10 +142,7 @@ jobs:

# NOTE: The script executed below sets the step output. This is why the output file
# path is passed in as an argument using the '$outputFilePath' variable.
deno run `
--allow-read `
--allow-write `
--allow-env `
deno run --allow-read --allow-write --allow-env `
"${{ github.workspace }}/.github/cicd/scripts/update-website-version.ts" `
"$outputFilePath";

Expand Down
15 changes: 12 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"--inspect-wait",
"--allow-all"
],
"args": ["${workspaceFolder}"],
"args": [
"${workspaceFolder}",
"${env:CICD_TOKEN}",
],
"attachSimplePort": 9229,
"windows": {
"runtimeExecutable": "${userHome}/.deno/bin/deno.exe"
Expand Down Expand Up @@ -110,12 +113,17 @@
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-all",
"--allow-read",
"--allow-write",
"--allow-sys",
"--allow-net",
"--allow-run",
],
"args": [
"${workspaceFolder}/docs/api",
"v1.0.0-preview.24",
"false" // Is Interactive
"${env:CICD_TOKEN}",
"true" // Is Interactive
],
"console": "integratedTerminal",
"attachSimplePort": 9229
Expand Down Expand Up @@ -165,6 +173,7 @@
"--inspect-wait",
"--allow-read",
"--allow-run",
"--allow-sys",
],
"attachSimplePort": 9229,
"console": "integratedTerminal"
Expand Down
8 changes: 7 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
"command": "deno",
"args": [
"run",
"-A",
"--allow-read",
"--allow-write",
"--allow-sys",
"--allow-net",
"--allow-run",
"${workspaceFolder}/.github/cicd/scripts/generate-new-api-docs.ts",
"${workspaceFolder}/docs/api",
"no-value",
"${env:CICD_TOKEN}",
"true", // Is Interactive
]
},
Expand Down Expand Up @@ -140,6 +145,7 @@
"run",
"--allow-read",
"--allow-run",
"--allow-sys",
"${workspaceFolder}/.github/cicd/scripts/deno-check.ts",
]
}
Expand Down
5 changes: 0 additions & 5 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"imports": {
"std/": "https://deno.land/std@0.203.0/",
"clients/": "https://raw.githubusercontent.com/kinsondigital/Infrastructure/v12.1.0/cicd/clients/",
"cliffy/": "https://deno.land/x/cliffy@v1.0.0-rc.3/"
},
"fmt": {
"include": ["**/.github/cicd/*\\.ts$"],
"exclude": [
Expand Down
Loading
Loading