Skip to content

Commit

Permalink
🚧Replace client code with library (#183)
Browse files Browse the repository at this point in the history
* config: add import maps

* refactor: update imports to use import maps

* ide: remove extension recommendation

* deps: setup deps.ts file with imports and exports

* refactor: update add item to project runner to use kd_clients

* ci: update cicd script to use kd_clients

* refactor: update prepare release runner to use kd clients

* chore: improve and move Directory class

* ci: create class to simplify cli command execution

* ci: set up deno build status check with local task setup

* ci: move script to different folder

* ci: move script to different folder

* ci,deps: improve core deps and fix imports

* refactor: update cs proj resolve runner to use kd_clients

* refactor: update sync bot status check runner to use kd_clients

* refactor: update sync pr to issue runner to use kd_clients

* refactor: update imports for transpile readme runner

* refactor: update imports for resolve cs proj runner

* refactor: update the lose milestone script to use kd_clients

* refactor: update validate github release script to use kd_clients

* refactor: update label if head branch script to use kd_clients

* refactor: update nuget pkg does not exist script to use kd_clients

* refactor: update validate tag script to use kd_clients

* refactor: update release tweet builder to use kd_clients

* refactor: update csharp version service script to use kd_client

* refactor: update the milestone-exists script to use kd_clients

* refactor: update the github var service to use kd_clients

* refactor: update prepare release runner to use kd_clients

* fix: fix other build issues

* cleanup: remove all of the old used clients

* cleanup: remove unused types

* chore: pull in models to replace locally deleted ones

* cleanup: remove unused types

* ide: remove config files for unused vscode extension

* chore: update add item to project runner

* refactor: change name of utils function

* refactor: refactor scripts to be imported into a single module

* ci: improve deno check process by running checks async

* cleanup: refactor code to meet deno formatting rules

* deps: update deno lock

* ci: update reusable workflow versions

* deps: update kd_clients from v1.0.0-preview.4 to v1.0.0-preview.5

* fix: update imports to use deps.ts instead of import maps

* ci: add deno permission to sync workflow

* fix: fix issue with missing arg with org client

* ci: add allow -read permission to workflow

* ide: update tasks file
  • Loading branch information
CalvinWilkinson authored Dec 7, 2023
1 parent 9af4e2b commit bdf6ff6
Show file tree
Hide file tree
Showing 121 changed files with 1,703 additions and 5,704 deletions.
96 changes: 96 additions & 0 deletions .github/internal-cicd/scripts/deno-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Directory, CLI } from "../../../deps.ts";

const ignoreDirectories = [
"./vendor/",
"./node_modules/"
];

const files: string[] = Directory
.getFiles("/", true)
.filter(f => {
const isTypeScriptFile = f.endsWith(".ts");

const shouldNotIgnore = ignoreDirectories.every(ignoreDir => !f.startsWith(ignoreDir))

return isTypeScriptFile && shouldNotIgnore;
});

const cli: CLI = new CLI();
let failed = false;

console.clear();
console.log(`Checking ${files.length} files . . .`);

/**
* Represents the result of checking a file.
*/
interface CheckResult {
file: string;
result: string;
hasPassed: boolean;
}

/**
* Checks a file using deno check.
* @param file The file to check.
* @returns A promise that resolves to a CheckResult.
*/
const checkFile = async (file: string): Promise<CheckResult> => {
let checkResult: CheckResult = {
file: file,
result: "",
hasPassed: true // Default to passed
};

checkResult.result += `Checking ${file}`;

const result = await cli.runAsync(`deno check ${file}`);

let commandResult = "";

// If the result is an error type
if (result instanceof Error)
{
checkResult.hasPassed = false;
commandResult = "❌\n";

const lines = result.message.split("\n");

// Prefix each command output line with 3 spaces
lines.forEach(line => {
commandResult += ` ${line}\n`;
});
} else {
commandResult = "✅\n";
}

checkResult.result += commandResult;

return checkResult;
}

const filesToCheck: Promise<CheckResult>[] = [];

// Perform a deno check on all of the files
for await (let file of files) {
filesToCheck.push(checkFile(file));
};

// Wait for all of the checks to complete
const allCheckResults = await Promise.all(filesToCheck);

// Print all of the results
allCheckResults.forEach(checkResult => {
Deno.stdout.writeSync(new TextEncoder().encode(checkResult.result));
});

// Collect the total number of passed and failed checks
const totalPassed = allCheckResults.filter(r => r.hasPassed).length;
const totalFailed = allCheckResults.filter(r => !r.hasPassed).length;

const resultsMsg = new TextEncoder().encode(`\nTotal Checks Passed✅: ${totalPassed}\nTotal Checks Failed❌: ${totalFailed}\n`);
Deno.stdout.writeSync(resultsMsg);

if (failed) {
Deno.exit(1);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Input } from "https://deno.land/x/[email protected]/prompt/input.ts";
import chalk from "npm:[email protected]";
import { TagClient } from "../../cicd/clients/TagClient.ts";
import { Directory } from "../../cicd/core/Directory.ts";
import { File } from "../../cicd/core/File.ts";
import { Utils } from "../../cicd/core/Utils.ts";
import { RepoClient } from "../../cicd/clients/RepoClient.ts";
import {
TagClient, RepoClient, Directory, Input
} from "../../../deps.ts";
import chalk from "../../../deps.ts";
import { File } from "../../../cicd/core/File.ts";
import { Utils } from "../../../cicd/core/Utils.ts";

if (Deno.args.length != 2) {
let errorMsg = "Invalid number of arguments.";
Expand Down Expand Up @@ -43,12 +42,14 @@ const newVersion = await Input.prompt({
}
});

const ownerName = "KinsonDigital";
const repoName = "Infrastructure";
const allFiles = Directory.getFiles(baseDirPath, true);

const yamlFiles = allFiles.filter((file) => file.toLowerCase().endsWith(".yaml") || file.toLowerCase().endsWith(".yml"));
const tagClient: TagClient = new TagClient(token);
const allTags = (await tagClient.getAllTags(repoName)).map((t) => t.name);
const tagClient: TagClient = new TagClient(ownerName, repoName, token);

const allTags = (await tagClient.getAllTags()).map((t) => t.name);

// If the new tag already exists, throw an error
if (allTags.includes(newVersion)) {
Expand Down Expand Up @@ -106,15 +107,15 @@ if (noFilesUpdated) {
}

const repoVarName = "CICD_SCRIPTS_VERSION";
const repoClient = new RepoClient(token);
const repoClient = new RepoClient(ownerName, repoName, token);

if (!(await repoClient.repoVariableExists(repoName, repoVarName))) {
if (!(await repoClient.repoVariableExists(repoVarName))) {
console.log(chalk.red(`The repository variable '${repoVarName}' does not exist.`));
Deno.exit(0);
}

const scriptVersionVar = (await repoClient.getVariables(repoName)).find((v) => v.name == repoVarName);
const scriptVersionVar = (await repoClient.getVariables()).find((v) => v.name == repoVarName);

await repoClient.updateVariable(repoName, repoVarName, newVersion);
await repoClient.updateVariable(repoVarName, newVersion);

console.log(chalk.cyan(`Updated repository variable '${repoVarName}' from version '${scriptVersionVar?.value}' to '${newVersion}'.`));
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { RepoClient } from "../../cicd/clients/RepoClient.ts";
import { TagClient } from "../../cicd/clients/TagClient.ts";
import { Directory } from "../../cicd/core/Directory.ts";
import { File } from "../../cicd/core/File.ts";
import { Path } from "../../cicd/core/Path.ts";
import { Utils } from "../../cicd/core/Utils.ts";
import { RepoClient, TagClient } from "../../../deps.ts";
import { Directory } from "../../../deps.ts";
import { File } from "../../../cicd/core/File.ts";
import { Path } from "../../../cicd/core/Path.ts";
import { Utils } from "../../../cicd/core/Utils.ts";

if (Deno.args.length != 2) {
let errorMsg = "Invalid number of arguments.";
Expand All @@ -23,13 +22,14 @@ if (!Directory.Exists(baseDirPath)) {
Deno.exit(1);
}

const ownerName = "KinsonDigital";
const repoName = "Infrastructure";
const allFiles = Directory.getFiles(baseDirPath, true);

const yamlFiles = allFiles.filter((file) => file.toLowerCase().endsWith(".yaml") || file.toLowerCase().endsWith(".yml"));
const tagClient: TagClient = new TagClient(token);
const tagClient: TagClient = new TagClient(ownerName, repoName, token);

const latestTag = (await tagClient.getAllTags(repoName))[0].name;
const latestTag = (await tagClient.getAllTags())[0].name;

const workflowsToUpdate: WorkflowToUpdate[] = [];

Expand Down Expand Up @@ -94,12 +94,12 @@ workflowsToUpdate.forEach(workflowToUpdate => {
});

const repoVarName = "CICD_SCRIPTS_VERSION";
const repoClient = new RepoClient(token);
const repoClient = new RepoClient(ownerName, repoName, token);

if (!(await repoClient.repoVariableExists(repoName, repoVarName))) {
if (!(await repoClient.repoVariableExists(repoVarName))) {
errorMsgs.push(`The repository variable '${repoVarName}' does not exist.`);
} else {
const scriptVersionVar = (await repoClient.getVariables(repoName)).find((v) => v.name == repoVarName);
const scriptVersionVar = (await repoClient.getVariables()).find((v) => v.name == repoVarName);

if (scriptVersionVar?.value === latestTag) {
let errorMsg = `The repository variable '${repoVarName}' version value `;
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/add-item-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
5. PAT
#>
deno run `
--allow-net `
--allow-net --allow-read `
"$scriptUrl" `
"${{ inputs.org-name }}" `
"${{ inputs.org-project-name }}" `
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/add-new-item-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
add_new_item_to_project:
name: Add New Issue
needs: item_number
uses: KinsonDigital/Infrastructure/.github/workflows/add-item-to-project.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/add-item-to-project.yml@v13.4.0-preview
with:
org-name: "${{ vars.ORGANIZATION_NAME }}"
org-project-name: "${{ vars.ORG_PROJECT_NAME }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-csharp-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
resolve_proj_file_path:
name: Resolving ${{ inputs.project-name }} Project File Path
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/resolve-csharp-proj-file.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/resolve-csharp-proj-file.yml@v13.4.0-preview
with:
project-name: ${{ inputs.project-name }}
base-path: ${{ inputs.base-path }}
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/build-status-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ✅Build Status Check
run-name: ✅Build Status Check (${{ github.base_ref }} branch)


defaults:
run:
shell: pwsh


on:
pull_request_target:
branches: main


jobs:
build_status_check:
name: Build Status Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.ref }}

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: ${{ vars.DENO_VERSION }}

- name: Run Build
run: |
deno run --allow-read --allow-run "./.github/internal-cicd/scripts/deno-check.ts";
10 changes: 5 additions & 5 deletions .github/workflows/dotnet-action-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
validate_version:
name: Validate Version
needs: [print_validate_workflow, validate_branch]
uses: KinsonDigital/Infrastructure/.github/workflows/validate-csharp-version.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-csharp-version.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
release-type: "${{ inputs.release-type }}"
Expand All @@ -168,7 +168,7 @@ jobs:
validate_tag:
name: Validate Tag
needs: validate_version
uses: KinsonDigital/Infrastructure/.github/workflows/validate-tag.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-tag.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
release-type: "${{ inputs.release-type }}"
Expand Down Expand Up @@ -207,7 +207,7 @@ jobs:
validate_github_release:
name: GitHub Release Does Not Exist
needs: validate_version
uses: KinsonDigital/Infrastructure/.github/workflows/validate-github-release.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-github-release.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
version: "${{ needs.validate_version.outputs.version }}"
Expand All @@ -218,7 +218,7 @@ jobs:
build_project:
name: Build Main Project (${{ inputs.project-name }})
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
runs-on: "${{ inputs.runs-on }}"
Expand All @@ -231,7 +231,7 @@ jobs:
run_tests:
name: Run Tests
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}Tests"
runs-on: "${{ inputs.runs-on }}"
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/dotnet-lib-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
validate_version:
name: Validate Version
uses: KinsonDigital/Infrastructure/.github/workflows/validate-csharp-version.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-csharp-version.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
release-type: "${{ inputs.release-type }}"
Expand All @@ -193,7 +193,7 @@ jobs:
validate_tag:
name: Validate Tag
needs: validate_version
uses: KinsonDigital/Infrastructure/.github/workflows/validate-tag.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-tag.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
release-type: "${{ inputs.release-type }}"
Expand All @@ -205,7 +205,7 @@ jobs:
nuget_pkg_does_not_exist:
name: Validate NuGet Package Does Not Exist
needs: validate_version
uses: KinsonDigital/Infrastructure/.github/workflows/nuget-package-does-not-exist.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/nuget-package-does-not-exist.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
version: "${{ needs.validate_version.outputs.version }}"
Expand All @@ -214,7 +214,7 @@ jobs:
validate_milestone_status:
name: Validate Milestone Status
needs: validate_version
uses: KinsonDigital/Infrastructure/.github/workflows/validate-milestone-status.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-milestone-status.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
version: "${{ needs.validate_version.outputs.version }}"
Expand All @@ -225,7 +225,7 @@ jobs:
validate_github_release:
name: GitHub Release Does Not Exist
needs: [validate_version]
uses: KinsonDigital/Infrastructure/.github/workflows/validate-github-release.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/validate-github-release.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
version: "${{ needs.validate_version.outputs.version }}"
Expand All @@ -236,7 +236,7 @@ jobs:
build_project:
name: Build Main Project
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/build-csharp-project.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}"
runs-on: "${{ inputs.runs-on }}"
Expand All @@ -249,7 +249,7 @@ jobs:
run_tests:
name: Run Tests
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/run-csharp-tests.yml@v13.4.0-preview
with:
project-name: "${{ inputs.project-name }}Tests"
runs-on: "${{ inputs.runs-on }}"
Expand Down Expand Up @@ -358,6 +358,7 @@ jobs:
deno run `
--allow-read --allow-net `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ inputs.project-name }}" `
"${{ needs.validate_version.outputs.version }}" `
"${{ secrets.cicd-pat }}";
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/initial-manual-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
5. PAT
#>
deno run `
--allow-net `
--allow-net --allow-read `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ vars.PROJECT_NAME }}" `
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-csharp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
resolve_proj_file_path:
name: Resolving ${{ inputs.project-name }} Project File Path
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/resolve-csharp-proj-file.yml@v13.3.1
uses: KinsonDigital/Infrastructure/.github/workflows/resolve-csharp-proj-file.yml@v13.4.0-preview
with:
project-name: ${{ inputs.project-name }}
base-path: ${{ inputs.base-path }}
Expand Down
Loading

0 comments on commit bdf6ff6

Please sign in to comment.