-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start work for issue #254 * cleanup: remove unused script * ci: create script to update repo variable * ci: add step to release workflow to update cicd scripts repo variable * ide: create launch config for update-cicd-script-version.ts script * deps: update deno lock * ci: convert vscode task script to cicd script * ci: add step to update reusable workflow versions * chore: remove unused exports * deps: update deno lock * ide: remove task * ci: update launch config * ide: add word to dictionary * ci: remove branch check step * ci: remove reusable workflow version check step * ci: fix spelling mistake * cleanup: remove unused imports * ci: add deno permissions * ci: fix spelling mistakes * ide: adjust deno permissions for launch config * ide: add words to dictionary * ci: update release workflow * ci: remove workflow version status check and associated scripts * ci: update step names * ci: update all action versions * ci: improve step names * ci: replace yarn with pnpm
- Loading branch information
1 parent
952904f
commit 25c3110
Showing
28 changed files
with
282 additions
and
284 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
.github/internal-cicd/scripts/update-cicd-script-version.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { RepoClient } from "jsr:@kinsondigital/[email protected]"; | ||
import getEnvVar from "../../../cicd/core/GetEnvVar.ts"; | ||
import { Utils } from "../../../cicd/core/Utils.ts"; | ||
|
||
const scriptFileName = new URL(import.meta.url).pathname.split("/").pop(); | ||
const ownerName = getEnvVar("OWNER_NAME", scriptFileName); | ||
const repoName = getEnvVar("REPO_NAME", scriptFileName); | ||
const token = getEnvVar("GITHUB_TOKEN", scriptFileName); | ||
const cicdScriptVersionRepoVarName = getEnvVar("CICD_SCRIPTS_VERSION_REPO_VAR_NAME", scriptFileName); | ||
const newVersion = getEnvVar("VERSION", scriptFileName); | ||
|
||
try { | ||
const client = new RepoClient(ownerName, repoName, token); | ||
const exists = await client.variableExists(cicdScriptVersionRepoVarName); | ||
|
||
if (!exists) { | ||
console.error(`The repository variable '${cicdScriptVersionRepoVarName}' does not exist.`); | ||
Deno.exit(1); | ||
} | ||
|
||
await client.updateVariable(cicdScriptVersionRepoVarName, newVersion); | ||
|
||
Utils.printAsGitHubNotice(`Updated the repository variable '${cicdScriptVersionRepoVarName}' value to '${newVersion}'.`); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
console.error(error.message); | ||
} else { | ||
console.error("An error occurred."); | ||
console.error(error); | ||
} | ||
|
||
Deno.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,43 @@ | ||
import { Directory, Input, RepoClient, TagClient } from "../../../deps.ts"; | ||
import chalk from "../../../deps.ts"; | ||
import { File } from "../../../cicd/core/File.ts"; | ||
import { Utils } from "../../../cicd/core/Utils.ts"; | ||
import { existsSync, walkSync } from "jsr:@std/[email protected]"; | ||
import { RepoClient } from "jsr:@kinsondigital/[email protected]"; | ||
import getEnvVar from "../../../cicd/core/GetEnvVar.ts"; | ||
|
||
const scriptFileName = new URL(import.meta.url).pathname.split("/").pop(); | ||
|
||
let baseDirPath = getEnvVar("BASE_DIR_PATH", scriptFileName); | ||
const ownerName = getEnvVar("OWNER_NAME", scriptFileName); | ||
const repoName = getEnvVar("REPO_NAME", scriptFileName); | ||
const baseDirPath = getEnvVar("BASE_DIR_PATH", scriptFileName); | ||
const token = getEnvVar("GITHUB_TOKEN", scriptFileName); | ||
const newVersion = getEnvVar("NEW_VERSION", scriptFileName); | ||
|
||
baseDirPath = Utils.normalizePath(baseDirPath.trim()); | ||
|
||
if (!Directory.Exists(baseDirPath)) { | ||
console.log(chalk.red(`Directory '${baseDirPath}' does not exist.`)); | ||
if (!existsSync(baseDirPath)) { | ||
console.log(`%cDirectory '${baseDirPath}' does not exist.`, "color: red"); | ||
Deno.exit(0); | ||
} | ||
|
||
// Clear the console so the token is not visible from the tasks.json file | ||
console.clear(); | ||
|
||
const tagRegex = /v([1-9]\d*|0)\.([1-9]\d*|0)\.([1-9]\d*|0)(-preview\.([1-9]\d*))?/gm; | ||
|
||
const newVersion = await Input.prompt({ | ||
message: chalk.blue("Enter version to upgrade workflows to:"), | ||
hint: "Use a tag with the syntax 'v#.#.#'.", | ||
minLength: 5, | ||
validate: (value) => { | ||
return tagRegex.test(value.trim().toLowerCase()); | ||
}, | ||
transform: (value) => { | ||
value = value.trim().toLowerCase(); | ||
|
||
return value.startsWith("v") ? value : `v${value}`; | ||
}, | ||
}); | ||
|
||
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(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)) { | ||
console.log(chalk.red(`Tag '${newVersion}' already exists.`)); | ||
if (!tagRegex.test(newVersion)) { | ||
console.log(`%cThe version '${newVersion}' is not a valid version number.`, "color: red"); | ||
Deno.exit(0); | ||
} | ||
|
||
|
||
const walkResult = walkSync(baseDirPath, { | ||
includeDirs: false, | ||
includeFiles: true, | ||
exts: [".yml", ".yaml"], | ||
}); | ||
|
||
const yamlFiles = Array.from(walkResult).map((e) => e.path); | ||
const reusableWorkflowRegex = /uses: .+.(yml|yaml)@v([1-9]\d*|0)\.([1-9]\d*|0)\.([1-9]\d*|0)(-preview\.([1-9]\d*))?/gm; | ||
|
||
const updateMsgs: string[] = []; | ||
let noFilesUpdated = true; | ||
|
||
// Search for workflow references with a version that has not been updated | ||
yamlFiles.forEach((yamlFile) => { | ||
let fileContent = File.LoadFile(yamlFile); | ||
let fileContent = Deno.readTextFileSync(yamlFile); | ||
|
||
const possibleUpdates = fileContent.match(reusableWorkflowRegex)?.map((w) => w) ?? []; | ||
|
||
|
@@ -86,32 +66,31 @@ yamlFiles.forEach((yamlFile) => { | |
// If anything has been updated, save the file | ||
if (fileUpdated) { | ||
// Save the changes to the file | ||
File.SaveFile(yamlFile, fileContent); | ||
Deno.writeTextFileSync(yamlFile, fileContent); | ||
} | ||
}); | ||
|
||
// If no files were updated | ||
if (noFilesUpdated) { | ||
console.log(chalk.cyan("No files needed updating.")); | ||
console.log("%cNo files needed updating.", "color: cyan"); | ||
} else { | ||
updateMsgs.sort(); | ||
updateMsgs.forEach((updateMsg) => { | ||
console.log(chalk.cyan(updateMsg)); | ||
console.log(`%c${updateMsg}`, "color: cyan"); | ||
}); | ||
} | ||
|
||
const repoVarName = "CICD_SCRIPTS_VERSION"; | ||
const repoClient = new RepoClient(ownerName, repoName, token); | ||
|
||
if (!(await repoClient.repoVariableExists(repoVarName))) { | ||
console.log(chalk.red(`The repository variable '${repoVarName}' does not exist.`)); | ||
if (!(await repoClient.variableExists(repoVarName))) { | ||
console.log(`%cThe repository variable '${repoVarName}' does not exist.`, "color: red"); | ||
Deno.exit(0); | ||
} | ||
|
||
const scriptVersionVar = (await repoClient.getVariables()).find((v) => v.name == repoVarName); | ||
|
||
await repoClient.updateVariable(repoVarName, newVersion); | ||
|
||
console.log( | ||
chalk.cyan(`Updated repository variable '${repoVarName}' from version '${scriptVersionVar?.value}' to '${newVersion}'.`), | ||
); | ||
const msg = `%cUpdated repository variable '${repoVarName}' from version '${scriptVersionVar?.value}' to '${newVersion}'.`; | ||
console.log(msg, "color: cyan"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,7 @@ jobs: | |
# Verify that the build config is only 'Debug' or 'Release' | ||
if ($buildConfig -ne "Debug" -and $buildConfig -ne "Release") { | ||
Write-Host "::error::The build configuration '$buildConfig' is invalid. Expsting a value of 'Debug' or 'Release'."; | ||
Write-Host "::error::The build configuration '$buildConfig' is invalid. Expecting a value of 'Debug' or 'Release'."; | ||
exit 1; | ||
} | ||
|
@@ -183,8 +183,7 @@ jobs: | |
uses: KinsonDigital/Infrastructure/.github/workflows/[email protected] | ||
with: | ||
repo-name: "${{ inputs.project-name }}" | ||
secrets: | ||
cicd-pat: "${{ secrets.cicd-pat }}" | ||
|
||
|
||
validate_release_notes_exist: | ||
name: Validate Release Notes Exist | ||
|
@@ -198,7 +197,7 @@ jobs: | |
run: | | ||
$relativeDirPath = "${{ inputs.relative-release-notes-dir-path }}"; | ||
# Remove all leading forwaard slashes until none are left | ||
# Remove all leading forward slashes until none are left | ||
$relativeDirPath = $relativeDirPath.Replace("\", "/"); | ||
$relativeDirPath = $relativeDirPath.TrimStart("/").TrimEnd("/"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.