Skip to content

Commit

Permalink
🚧Fix import issue in mod files (#7)
Browse files Browse the repository at this point in the history
* Start work for issue #6

* refactor: update the import paths to relative paths

* config: remove import maps

* refactor: update all import paths to relative paths

* config: setup external dependencies file

* cleanup: cleanup code using deno fmt

* ci: update deno check script to ignore certain directories

* ide: setup launch config for deno check script

* config: update deno lock file

* config: remove vendored dependencies

* config: update deno lock

* config: add git ignore for node_modules folder

* refactor: update deps imports

* ide: ignore node_modules folder

* ci: update unit test status check with permission

* deps: add dependency to npm chalk library

* ci: add ignore folder to deno check script

* chore: change what kind of message print error util func does

* refactor: improve error handling code in OrgClient

* refactor: improve error handling code in GitClient

* refactor: improve error handling in GraphQlClient

* refactor: improve error handling in IssueClient

* refactor: improve error handling in LabelClient

* refactor: improve error handling in RepoClient

* chore: fix error in utils function

* fix: add missing arguments

* ide: add permission to task

* refactor: improve error handling in GitHubClient

* config: improve dependencies

* config: update deno lock

* config: remove include and exclude for tests

* ci: update test status check to be explicit with tests

* chore: make functions public

* test: create tests for RepoClient

* refactor: improve error handling in MilestoneClient

* cleanup: remove unused protected funcs

* chore: setup launch config and playground with default args

* refactor: improve error handling in ProjectClient

* ci: improve deno check process

* refactor: improve error handling with PullRequestClient

* refactor: refactor param names across code base

* refactor: improve error handling with the ReleaseClient

* refactor: improve error handling of the TagClient

* refactor: improve error handling of the UsersClient

* fix: fix guards

* refactor: improve error handling in WorkflowClient

* ide: remove recommended extension

* refactor: improve error handling in XClient

* refactor: improve error handling of the NuGetClient

* refactor: further improve error handling of clients

* refactor: force ctor params to be required

* refactor: adjust not equals operators

* chore: remove utils function

* refactor: remove deno exit func from error handling code

* refactor: convert Guard functions to throw errors instead of exiting

* config: update version from v1.0.0-preview.2 to v1.0.0-preview.3
  • Loading branch information
CalvinWilkinson committed Nov 4, 2023
1 parent 277443c commit 4425e63
Show file tree
Hide file tree
Showing 84 changed files with 1,512 additions and 1,199 deletions.
2 changes: 1 addition & 1 deletion .github/cicd/core/Directory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from "std/fs/exists.ts";
import { existsSync } from "../../../deps.ts";

/**
* Provides directory functionality.
Expand Down
2 changes: 1 addition & 1 deletion .github/cicd/core/File.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from "std/fs/exists.ts";
import { existsSync } from "../../../deps.ts";

/**
* Provides file functionality.
Expand Down
8 changes: 4 additions & 4 deletions .github/cicd/core/VersionPuller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Utils } from "core/Utils.ts";
import { Directory } from "cicd-core/Directory.ts";
import { Utils } from "../../../core/Utils.ts";
import { Directory } from "../core/Directory.ts";

/**
* Pulls the version from a json file.
Expand All @@ -16,7 +16,7 @@ export class VersionPuller {

if (denoJsonFilePath === undefined) {
const errorMsg = `The file '${fileName}' could not be found when pulling the version number.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

Expand All @@ -26,7 +26,7 @@ export class VersionPuller {
// If the object contains a property with the name version
if (jsonObj.version === undefined) {
const errorMsg = `The file '${fileName}' does not contain a version property.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

Expand Down
2 changes: 2 additions & 0 deletions .github/cicd/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const _token = Deno.args[0]; // NOTE: This is coming from the launch.config json file as an environment variable
const _rootRepoDirPath = Deno.args[1];
14 changes: 7 additions & 7 deletions .github/cicd/scripts/check-release-notes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Utils } from "core/Utils.ts";
import { File } from "cicd-core/File.ts";
import { Utils } from "../../../core/Utils.ts";
import { File } from "../core/File.ts";

if (Deno.args.length != 2) {
let errorMsg = `The required number of arguments is 2 but received ${Deno.args.length}.`;
errorMsg += `\nPlease provide the following arguments: version type, version.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(100);
}

const versionType = Deno.args[0].trim().toLowerCase();
let version = Deno.args[1].trim().toLowerCase();

if (Utils.invalidReleaseType(versionType)) {
Utils.printAsGitHubError(`The version type must be either 'preview' or 'release' but received '${versionType}'.`);
Utils.printError(`The version type must be either 'preview' or 'release' but received '${versionType}'.`);
Deno.exit(200);
}

Expand All @@ -22,14 +22,14 @@ let releaseNotesDirName = "";

if (Utils.isPreviewRelease(versionType)) {
if (Utils.isNotValidPreviewVersion(version)) {
Utils.printAsGitHubError(`The preview version '${version}' is not valid.`);
Utils.printError(`The preview version '${version}' is not valid.`);
Deno.exit(300);
}

releaseNotesDirName = "PreviewReleases";
} else if (Utils.isProductionRelease(versionType)) {
if (Utils.isNotValidProdVersion(version)) {
Utils.printAsGitHubError(`The production version '${version}' is not valid.`);
Utils.printError(`The production version '${version}' is not valid.`);
Deno.exit(400);
}

Expand All @@ -39,6 +39,6 @@ if (Utils.isPreviewRelease(versionType)) {
const releaseNotesDirPath = `./ReleaseNotes/${releaseNotesDirName}/Release-Notes-${version}.md`;

if (File.DoesNotExist(releaseNotesDirPath)) {
Utils.printAsGitHubError(`The release notes '${releaseNotesDirPath}' does not exist.`);
Utils.printError(`The release notes '${releaseNotesDirPath}' does not exist.`);
Deno.exit(500);
}
25 changes: 23 additions & 2 deletions .github/cicd/scripts/deno-check.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import { CLI } from "../core/CLI.ts";
import { Directory } from "cicd-core/Directory.ts";
import { Directory } from "../core/Directory.ts";

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

const files: string[] = Directory
.getFiles("/", true)
.filter(f => f.endsWith(".ts"));
.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 . . .`);

let totalPassed = 0;
let totalFailed = 0;

// Perform a deno check on all of the files
for await (let file of files) {
const logStart = new TextEncoder().encode(`Checking ${file}`);
Expand All @@ -29,14 +44,20 @@ for await (let file of files) {
lines.forEach(line => {
logEndValue += ` ${line}\n`;
});

totalFailed++;
} else {
logEndValue = "✅\n";
totalPassed++;
}

const logEnd = new TextEncoder().encode(logEndValue);
Deno.stdout.writeSync(logEnd);
};

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

if (failed) {
Deno.exit(1);
}
6 changes: 3 additions & 3 deletions .github/cicd/scripts/get-version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utils } from "core/Utils.ts";
import { Utils } from "../../../core/Utils.ts";
import { VersionPuller } from "../core/VersionPuller.ts";

const versionPuller: VersionPuller = new VersionPuller();
Expand All @@ -9,10 +9,10 @@ const outputFilePath = Deno.env.get("GITHUB_OUTPUT") ?? "";

if (outputFilePath === "") {
const errorMsg = `The environment variable 'GITHUB_OUTPUT' does not exist or is not set.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

Deno.writeTextFileSync(outputFilePath, `version=${version}`);

Utils.printAsGitHubNotice(`The output 'version' has been set to '${version}'.`)
console.log(`The output 'version' has been set to '${version}'.`)
24 changes: 12 additions & 12 deletions .github/cicd/scripts/version-checker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RepoClient, TagClient, UsersClient } from "github/mod.ts";
import { Utils } from "core/Utils.ts";
import { RepoClient, TagClient, UsersClient } from "../../../GitHubClients/mod.ts";
import { Utils } from "../../../core/Utils.ts";

if (Deno.args.length !== 5) {
if (Deno.args.length != 5) {
let errorMsg = `The required number of arguments is 5 but only ${Deno.args.length}.`;
errorMsg += `\nPlease provide the following arguments: version, owner name, repo name, and token.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

Expand All @@ -17,48 +17,48 @@ version = version.startsWith("v") ? version : `v${version}`;

const token = Deno.args[4].trim();

const userCLient: UsersClient = new UsersClient(token);
const userCLient: UsersClient = new UsersClient(ownerName, repoName, token);

if (!await userCLient.userExists(ownerName)) {
const errorMsg = `The user '${ownerName}' does not exist.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

const repoClient: RepoClient = new RepoClient(ownerName, repoName, token);

if (!await repoClient.exists()) {
const errorMsg = `The repository '${repoName}' does not exist.`;
Utils.printAsGitHubError(errorMsg);
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

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

if (await tagClient.tagExists(version)) {
const errorMsg = `The tag '${version}' already exists.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

if (versionType != "preview" && versionType != "production") {
const errorMsg = `The version type '${versionType}' is not valid. Valid values are 'preview' or 'production' version type.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}

// Verify that the version is a valid preview or production version
if (versionType === "preview") {
if (Utils.isNotValidPreviewVersion(version)) {
const errorMsg = `The version '${version}' is not valid. Please provide a valid preview version.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}
} else if (versionType === "production") {
if (Utils.isNotValidProdVersion(version)) {
const errorMsg = `The version '${version}' is not valid. Please provide a valid production version.`;
Utils.printAsGitHubError(errorMsg);
Utils.printError(errorMsg);
Deno.exit(1);
}
}
5 changes: 1 addition & 4 deletions .github/workflows/build-status-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ jobs:

- name: Run Build
run: |
deno run --allow-read --allow-run `
--no-remote `
--import-map=${{ github.workspace }}/vendor/import_map.json `
./.github/cicd/scripts/deno-check.ts;
deno run --allow-read --allow-run "./.github/cicd/scripts/deno-check.ts";
15 changes: 6 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
default: false
type: boolean


jobs:
get_version:
name: Get Version
Expand All @@ -39,10 +40,8 @@ jobs:
id: get_version
run: |
$scriptPath = "${{ github.workspace }}/.github/cicd/scripts/get-version.ts";
deno run --allow-read --allow-write --allow-env `
--no-remote `
--import-map=${{ github.workspace }}/vendor/import_map.json `
"$scriptPath";
deno run --allow-read --allow-write --allow-env "$scriptPath";
validate_release:
Expand Down Expand Up @@ -73,8 +72,7 @@ jobs:
deno run `
--allow-net `
--no-remote `
--import-map=${{ github.workspace }}/vendor/import_map.json `
--allow-read `
"$scriptPath" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ vars.PROJECT_NAME }}" `
Expand All @@ -88,12 +86,11 @@ jobs:
deno run `
--allow-read `
--no-remote `
--import-map=${{ github.workspace }}/vendor/import_map.json `
"$scriptPath" `
"${{ inputs.release-type }}" `
"${{ needs.get_version.outputs.version }}";
release:
name: Run ${{ inputs.release-type }} Release
runs-on: ubuntu-latest
Expand Down Expand Up @@ -126,7 +123,7 @@ jobs:
prerelease: ${{ inputs.release-type == 'Preview' }}
draft: false

- name: Close Milestone
- name: Close Milestone ${{ needs.get_version.outputs.version }}
if: ${{ inputs.dry-run == false }}
run: |
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH }}";
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-status-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
deno-version: ${{ vars.DENO_VERSION }}

- name: Run Tests
run: deno test
run: deno test --allow-read ./tests/*Tests.ts;
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"denoland.vscode-deno",
"humao.rest-client",
"github.vscode-github-actions",
"redhat.vscode-yaml"
]
Expand Down
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"--inspect-wait",
"--allow-all",
],
"args": [
"${env:CICD_TOKEN}",
"${workspaceFolder}",
],
"attachSimplePort": 9229,
"runtimeExecutable": "npm",
"outputCapture": "std",
Expand Down Expand Up @@ -129,6 +133,31 @@
"windows": {
"runtimeExecutable": "${userHome}\\.deno\\bin\\deno.exe"
},
"linux": {
"runtimeExecutable": "${userHome}/.deno/bin/deno"
},
},
{
"name": "Deno Check",
"request": "launch",
"type": "node",
"program": "${workspaceFolder}/.github/cicd/scripts/deno-check.ts",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-read",
"--allow-run",
],
"attachSimplePort": 9229,
"runtimeExecutable": "npm",
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**"
],
"windows": {
"runtimeExecutable": "${userHome}\\.deno\\bin\\deno.exe"
},
"linux": {
"runtimeExecutable": "${userHome}/.deno/bin/deno"
},
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"cSpell.words": [
"cicd",
"Creds"
"Creds",
"flatcontainer"
],
"files.exclude": {
"**/.git": true,
Expand All @@ -10,6 +11,7 @@
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": true,
},
"deno.enable": true,
"deno.lint": true,
Expand Down
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"run",
"--allow-read",
"--allow-run",
"--allow-sys",
"${workspaceFolder}/.github/cicd/scripts/deno-check.ts"
],
"problemMatcher": [
Expand Down
9 changes: 9 additions & 0 deletions GitHubClients/Errors/BadCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Error thrown when there is a bad credentials error.
*/
export class BadCredentialsError extends Error {
constructor(message: string) {
super(message);
this.name = "BadCredentialsError";
}
}
Loading

0 comments on commit 4425e63

Please sign in to comment.