diff --git a/.github/workflows/format-status-check.yml b/.github/workflows/format-status-check.yml index f4358bf..aa183bc 100644 --- a/.github/workflows/format-status-check.yml +++ b/.github/workflows/format-status-check.yml @@ -29,4 +29,4 @@ jobs: deno-version: ${{ vars.DENO_VERSION }} - name: Run Lint - run: deno fmt --check + run: deno fmt --check **/*/*.ts; diff --git a/.github/workflows/lint-status-check.yml b/.github/workflows/lint-status-check.yml index 699f0b9..0bd5c75 100644 --- a/.github/workflows/lint-status-check.yml +++ b/.github/workflows/lint-status-check.yml @@ -29,4 +29,4 @@ jobs: deno-version: ${{ vars.DENO_VERSION }} - name: Run Lint - run: deno lint + run: deno lint **/*/*.ts; diff --git a/deno.json b/deno.json index 4bc66a6..9cc9ee0 100644 --- a/deno.json +++ b/deno.json @@ -2,6 +2,7 @@ "version": "v1.0.0-preview.5", "tasks": { "check": "deno check **/*/*.ts", + "lint": "deno lint **/*/*.ts", "tests": "deno test ./Tests/*Tests.ts", "reload-cache": "deno cache --reload --lock=deno.lock \"*/**/*.ts\"" }, diff --git a/installation/install.ts b/installation/install.ts index 0755c56..9383420 100644 --- a/installation/install.ts +++ b/installation/install.ts @@ -37,7 +37,7 @@ if (existsSync(`./${createPrShellFileName}`, { isFile: true })) { }); if (confirmCreatePRShellScript) { - Deno.writeTextFileSync(`./${createPrShellFileName}`, "& \"dev-tools/bin/kd-admin\" create-pr;\n"); + Deno.writeTextFileSync(`./${createPrShellFileName}`, '& "dev-tools/bin/kd-admin" create-pr;\n'); console.log(`%c\tCreated '${createPrShellFileName}' file.`, "color: gray"); } } @@ -51,7 +51,7 @@ if (existsSync(`./${prepareReleaseShellFileName}`, { isFile: true })) { }); if (confirmCreatePrepareReleaseShellScript) { - Deno.writeTextFileSync(`./${prepareReleaseShellFileName}`, "& \"dev-tools/bin/kd-admin\" prepare-for-release;\n"); + Deno.writeTextFileSync(`./${prepareReleaseShellFileName}`, '& "dev-tools/bin/kd-admin" prepare-for-release;\n'); console.log(`%c\tCreated '${prepareReleaseShellFileName}' file.`, "color: gray"); } } @@ -69,12 +69,12 @@ if (existsSync(`./dev-tools/${createPrSettingsFileName}`, { isFile: true })) { ownerName: "", repoName: "", githubTokenEnvVarName: "", - baseBranches: [] + baseBranches: [], }; const settingsObj = { $schema: "https://raw.githubusercontent.com/KinsonDigital/kd-admin/preview/schemas/create-pr-schema.json", - ...prSettings + ...prSettings, }; Deno.writeTextFileSync(`./dev-tools/${createPrSettingsFileName}`, `${JSON.stringify(settingsObj, null, 4)}\n`); @@ -89,7 +89,7 @@ if (existsSync(`./dev-tools/${prepareReleaseSettingsFileName}`, { isFile: true } message: "Do you want to add a the prepare for release setting files?", default: true, }); - + if (confirmCreatePrepareReleaseSettingFiles) { const prepareReleaseSettings: PrepareReleaseSettings = { ownerName: "", diff --git a/installation/update.ts b/installation/update.ts index 61d30cf..870ad18 100644 --- a/installation/update.ts +++ b/installation/update.ts @@ -3,19 +3,19 @@ import { walkSync } from "https://deno.land/std@0.224.0/fs/walk.ts"; import { TagClient } from "https://deno.land/x/kd_clients@v1.0.0-preview.13/GitHubClients/TagClient.ts"; const baseDirPath = "./dev-tools/bin"; -const filesToUpdate = [...walkSync(baseDirPath, { includeFiles: true, match: [/kd-admin/]})].map((f) => f.path); +const filesToUpdate = [...walkSync(baseDirPath, { includeFiles: true, match: [/kd-admin/] })].map((f) => f.path); const tagClient = new TagClient("KinsonDigital", "kd-admin"); const tags: string[] = (await tagClient.getAllTags()).map((t) => t.name); const latestVersion = tags[0]; -filesToUpdate.forEach(async file => { - await updateFile(file); +filesToUpdate.forEach((file) => { + updateFile(file); }); console.log(`%ckd-admin has been updated to version '${latestVersion}'.`, "color: green"); -async function updateFile (filePath: string) { +function updateFile(filePath: string) { const isInstalled = existsSync(filePath, { isFile: true }); if (!isInstalled) { @@ -28,7 +28,7 @@ async function updateFile (filePath: string) { const urlLine = fileLines.find((line) => line.includes("deno") && line.includes("https://")); - const corruptErrorMsg = `%cThe file '${filePath}' is corrupted. Please reinstall the script.`; + const corruptErrorMsg = `%cThe file '${filePath}' is corrupted. Please reinstall the script.`; if (urlLine === undefined) { console.log(corruptErrorMsg, "color: red"); @@ -70,10 +70,9 @@ async function updateFile (filePath: string) { return section; }); - const newUrlLine = newSections.join(" "); - const newFileLines = fileLines.map((line) => { + const newFileLines = fileLines.map((line) => { if (line.includes("deno") && line.includes("https://")) { return newUrlLine; } @@ -84,4 +83,4 @@ async function updateFile (filePath: string) { const newFileContent = newFileLines.join("\n"); Deno.writeTextFileSync(filePath, newFileContent); -}; +} diff --git a/schemas/prepare-release-schema.json b/schemas/prepare-release-schema.json index e3bd043..cdba962 100644 --- a/schemas/prepare-release-schema.json +++ b/schemas/prepare-release-schema.json @@ -37,6 +37,10 @@ "releaseNotesFilePrefix": { "type": "string", "description": "The path to the version number in the JSON file. Only used if the file is a JSON file. (Optional)" + }, + "trimFromStartOfVersion": { + "type": "array", + "description": "The list of strings to trim from the start of the version number. (Optional)" } }, "required": ["ownerName", "repoName", "releaseTypes", "githubTokenEnvVarName"] diff --git a/src/prepare-release-settings.ts b/src/prepare-release-settings.ts index ac5e249..a811824 100644 --- a/src/prepare-release-settings.ts +++ b/src/prepare-release-settings.ts @@ -44,4 +44,9 @@ export interface PrepareReleaseSettings { * Gets the value to prefix the release notes file name with. */ releaseNotesFilePrefix?: string; + + /** + * Gets the list of strings to trim from the start of the version. + */ + trimFromStartOfVersion?: string[]; } diff --git a/src/release-prepper.ts b/src/release-prepper.ts index 9f439f0..ea31612 100644 --- a/src/release-prepper.ts +++ b/src/release-prepper.ts @@ -80,7 +80,7 @@ export class ReleasePrepper { Deno.exit(1); } - const chosenVersion = await this.getAndValidateVersion(); + const chosenVersion = await this.getAndValidateVersion(settings); const repoDoesNotExist = !(await this.repoClient.exists()); @@ -199,12 +199,13 @@ export class ReleasePrepper { } // Assignee milestone to the pr - const milestone = await this.milestoneClient.getMilestoneByName(chosenVersion); + const milestoneTitle = chosenVersion.startsWith("v") ? chosenVersion : `v${chosenVersion}`; + const milestone = await this.milestoneClient.getMilestoneByName(milestoneTitle); const prData: IssueOrPRRequestData = { milestone: milestone.number, }; - ConsoleLogColor.gray(` ⏳Assigning pr to milestone '${chosenVersion}'.`); + ConsoleLogColor.gray(` ⏳Assigning pr to milestone '${milestoneTitle}'.`); await this.prClient.updatePullRequest(prNumber, prData); const prUrl = `https://github.com/${ownerName}/${repoName}/pull/${prNumber}`; @@ -409,7 +410,12 @@ export class ReleasePrepper { return true; } - private async getAndValidateVersion(): Promise { + /** + * Gets the version from the user and trims and validates the version. + * @param settings The prepare release settings. + * @returns The validated and trimmed version. + */ + private async getAndValidateVersion(settings: PrepareReleaseSettings): Promise { let chosenVersion = ""; let versionExists = true; @@ -440,9 +446,24 @@ export class ReleasePrepper { } } + // Trim the starting section of the version if trim values exist + if (!Guards.isNothing(settings.trimFromStartOfVersion)) { + for (let i = 0; i < settings.trimFromStartOfVersion.length; i++) { + const trimValue = settings.trimFromStartOfVersion[i]; + + if (chosenVersion.startsWith(trimValue)) { + chosenVersion = chosenVersion.slice(trimValue.length); + } + } + } + return chosenVersion; } + /** + * Creates a release branch based on the given {@link releaseType}. + * @param releaseType The type of release. + */ private async createReleaseBranch(releaseType: ReleaseType): Promise { const createBranchResult = await runAsync("git", ["checkout", "-B", releaseType.headBranch]); @@ -472,6 +493,7 @@ export class ReleasePrepper { let notesDirPath = releaseType.releaseNotesDirPath.trim().replace(/\\/g, "/"); notesDirPath = notesDirPath.endsWith("/") ? notesDirPath.slice(0, -1) : notesDirPath; + chosenVersion = chosenVersion.startsWith("v") ? chosenVersion : `v${chosenVersion}`; const settings = this.loadGenNotesSettings(releaseType, chosenVersion, tokenEnvVarName); @@ -742,9 +764,11 @@ export class ReleasePrepper { } private async milestoneExists(chosenVersion: string): Promise { - ConsoleLogColor.gray(` ⏳Validating milestone '${chosenVersion}'.`); + const title = chosenVersion.startsWith("v") ? chosenVersion : `v${chosenVersion}`; + + ConsoleLogColor.gray(` ⏳Validating milestone '${title}'.`); - return await this.milestoneClient.milestoneExists(chosenVersion); + return await this.milestoneClient.milestoneExists(title); } /**