diff --git a/.github/internal-cicd/deno-tasks/clear-screen.ts b/.github/internal-cicd/deno-tasks/clear-screen.ts deleted file mode 100644 index ac220cff..00000000 --- a/.github/internal-cicd/deno-tasks/clear-screen.ts +++ /dev/null @@ -1 +0,0 @@ -console.clear(); diff --git a/.github/internal-cicd/scripts/update-cicd-script-version.ts b/.github/internal-cicd/scripts/update-cicd-script-version.ts new file mode 100644 index 00000000..b87f16e2 --- /dev/null +++ b/.github/internal-cicd/scripts/update-cicd-script-version.ts @@ -0,0 +1,33 @@ +import { RepoClient } from "jsr:@kinsondigital/kd-clients@1.0.0-preview.14"; +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); +} diff --git a/.github/internal-cicd/scripts/update-workflow-versions.ts b/.github/internal-cicd/scripts/update-workflow-versions.ts index 3b9c33c2..153ddcb4 100644 --- a/.github/internal-cicd/scripts/update-workflow-versions.ts +++ b/.github/internal-cicd/scripts/update-workflow-versions.ts @@ -1,55 +1,35 @@ -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/fs@1.0.11"; +import { RepoClient } from "jsr:@kinsondigital/kd-clients@1.0.0-preview.14"; 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[] = []; @@ -57,7 +37,7 @@ 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,25 +66,25 @@ 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); } @@ -112,6 +92,5 @@ const scriptVersionVar = (await repoClient.getVariables()).find((v) => v.name == 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"); diff --git a/.github/internal-cicd/scripts/workflow-version-status-check.ts b/.github/internal-cicd/scripts/workflow-version-status-check.ts deleted file mode 100644 index 5c94c7eb..00000000 --- a/.github/internal-cicd/scripts/workflow-version-status-check.ts +++ /dev/null @@ -1 +0,0 @@ -import "../../../cicd/scripts/check-workflow-versions.ts"; diff --git a/.github/workflows/add-item-to-project.yml b/.github/workflows/add-item-to-project.yml index a7e61a70..4a1631b6 100644 --- a/.github/workflows/add-item-to-project.yml +++ b/.github/workflows/add-item-to-project.yml @@ -61,7 +61,7 @@ jobs: exit 1; } - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/build-csharp-project.yml b/.github/workflows/build-csharp-project.yml index 609c5f15..14bd15b8 100644 --- a/.github/workflows/build-csharp-project.yml +++ b/.github/workflows/build-csharp-project.yml @@ -108,8 +108,8 @@ jobs: repository: ${{ inputs.checkout-repository }} ref: ${{ inputs.checkout-ref }} - - name: Setup .NET SDK ${{ inputs.net-sdk-version }} - uses: actions/setup-dotnet@v3 + - name: Set Up .NET SDK (${{ inputs.net-sdk-version }}) + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ inputs.net-sdk-version }} diff --git a/.github/workflows/build-status-check.yml b/.github/workflows/build-status-check.yml index 56a61bc5..4d5a7b10 100644 --- a/.github/workflows/build-status-check.yml +++ b/.github/workflows/build-status-check.yml @@ -23,7 +23,7 @@ jobs: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} - - name: Setup Deno (${{ vars.DENO_VERSION }}) + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/docusaurus-release.yml b/.github/workflows/docusaurus-release.yml index 3116f6c7..4d6e6a71 100644 --- a/.github/workflows/docusaurus-release.yml +++ b/.github/workflows/docusaurus-release.yml @@ -116,31 +116,33 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Setup Node (v${{ inputs.node-version }}) - uses: actions/setup-node@v3 + - name: Set Up Node (v${{ inputs.node-version }}) + uses: actions/setup-node@v4 with: node-version: ${{ inputs.node-version }} - - name: Setup YARN - run: npm install --global yarn + - name: Setup PNPM (${{ vars.PNPM_VERSION }}) + uses: pnpm/action-setup@v4 + with: + version: ${{ vars.PNPM_VERSION }} - - name: Setup Docusaurus - run: yarn install + - name: Set Up Docusaurus + run: pnpm install - name: Build Site - run: yarn build + run: pnpm exec docusaurus build - - name: Setup Pages - uses: actions/configure-pages@v3 + - name: Set Up Pages + uses: actions/configure-pages@v5 - name: Upload Artifact - uses: actions/upload-pages-artifact@v2.0.0 + uses: actions/upload-pages-artifact@v3 with: path: '${{ inputs.artifact-dir-path }}' - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 - name: Create Release Tag (${{ inputs.release-version }}) run: | diff --git a/.github/workflows/dotnet-action-release.yml b/.github/workflows/dotnet-action-release.yml index 8efc41ab..92ce7e90 100644 --- a/.github/workflows/dotnet-action-release.yml +++ b/.github/workflows/dotnet-action-release.yml @@ -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/validate-sdk-versions.yml@v14.2.0 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("/"); diff --git a/.github/workflows/dotnet-lib-release.yml b/.github/workflows/dotnet-lib-release.yml index deb02de3..98b3b2e2 100644 --- a/.github/workflows/dotnet-lib-release.yml +++ b/.github/workflows/dotnet-lib-release.yml @@ -109,7 +109,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} @@ -309,15 +309,15 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Setup .NET SDK - uses: actions/setup-dotnet@v3 + - name: Set Up .NET SDK + uses: actions/setup-dotnet@v4 with: dotnet-version: "${{ inputs.net-sdk-version }}" - - name: Setup Nuget - uses: NuGet/setup-nuget@v1 + - name: Set Up Nuget + uses: NuGet/setup-nuget@v2 - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/initial-manual-sync.yml b/.github/workflows/initial-manual-sync.yml index ab997646..52d75064 100644 --- a/.github/workflows/initial-manual-sync.yml +++ b/.github/workflows/initial-manual-sync.yml @@ -78,7 +78,7 @@ jobs: "$stepOutput" >> $env:GITHUB_OUTPUT; - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) if: ${{ steps.skip-checking.outputs.skip == 'false' }} uses: denoland/setup-deno@v2 with: diff --git a/.github/workflows/lint-status-check.yml b/.github/workflows/lint-status-check.yml index 39d3b983..ae581a2c 100644 --- a/.github/workflows/lint-status-check.yml +++ b/.github/workflows/lint-status-check.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/nuget-package-does-not-exist.yml b/.github/workflows/nuget-package-does-not-exist.yml index f312ef44..af28da23 100644 --- a/.github/workflows/nuget-package-does-not-exist.yml +++ b/.github/workflows/nuget-package-does-not-exist.yml @@ -52,7 +52,7 @@ jobs: needs: print_validate_workflow runs-on: ubuntu-latest steps: - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff284d98..74d45567 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} @@ -72,15 +72,6 @@ jobs: "url=$scriptUrl" >> $env:GITHUB_OUTPUT; - - name: Branch Check - id: branch-check - continue-on-error: true - run: | - if ("${{ github.ref_name }}" -ne "main") { - Write-Host "::error::The branch '$branch' is invalid. Please only run on the 'main' branch."; - exit 1; - } - - name: Milestone Exists id: milestone-exists-check continue-on-error: true @@ -135,26 +126,12 @@ jobs: deno run -ERN "$scriptUrl"; - - name: Check Reusable Workflow Versions - id: workflow-versions-check - continue-on-error: true - env: - BASE_DIR_PATH: "${{ github.workspace }}/.github/workflows" - GITHUB_TOKEN: "${{ secrets.CICD_TOKEN }}" - run: deno run -ERN "${{ steps.build-script-base-url.outputs.url }}/check-workflow-versions.ts"; - - name: Should Fail Job run: | - $branchCheckFailed = "${{ steps.branch-check.outcome == 'failure' }}"; $milestoneExistsCheckFailed = "${{ steps.milestone-exists-check.outcome == 'failure' }}"; $milestoneCheckFailed = "${{ steps.milestone-check.outcome == 'failure' }}"; $releaseNotesCheckFailed = "${{ steps.release-notes-check.outcome == 'failure' }}"; $githubReleaseCheckFailed = "${{ steps.github-release-check.outcome == 'failure' }}"; - $workflowVersionsCheckCheckFailed = "${{ steps.workflow-versions-check.outcome == 'failure' }}"; - - if ($branchCheckFailed -eq "true") { - Write-Host "::error::The branch is invalid. Check the 'run-branch' workflow input."; - } if ($milestoneExistsCheckFailed -eq "true") { Write-Host "::error::The milestone '${{ needs.get_validate_version.outputs.version }}' does not exist."; @@ -173,15 +150,13 @@ jobs: } if ($workflowVersionsCheckCheckFailed -eq "true") { - Write-Host "::error::The one or more reusable workflow versions haver not been updated."; + Write-Host "::error::The one or more reusable workflow versions have not been updated."; } - if ($branchCheckFailed -eq "true" ` - -or $milestoneExistsCheckFailed -eq "true" ` + if ($milestoneExistsCheckFailed -eq "true" ` -or $milestoneCheckFailed -eq "true" ` -or $releaseNotesCheckFailed -eq "true" ` - -or $githubReleaseCheckFailed -eq "true" ` - -or $workflowVersionsCheckCheckFailed -eq "true") { + -or $githubReleaseCheckFailed -eq "true") { exit 1; } @@ -193,7 +168,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Setup Deno (${{ vars.DENO_VERSION }}) + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} @@ -209,7 +184,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Setup Deno (${{ vars.DENO_VERSION }}) + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} @@ -226,11 +201,15 @@ jobs: name: Perform ${{ inputs.release-type }} Release runs-on: ubuntu-latest needs: [get_validate_version, run_prerelease_validation, build, lint] + permissions: + contents: write steps: - name: Checkout Repo uses: actions/checkout@v4 + with: + token: ${{ secrets.CICD_TOKEN }} - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} @@ -252,6 +231,28 @@ jobs: $releaseType = "${{ inputs.release-type }}".ToLower(); "release-type=$releaseType" > "$env:GITHUB_OUTPUT"; + - name: Update Reusable Workflow Versions ${{ inputs.dry-run == true && '(Dry Run)' || '' }} + env: + BASE_DIR_PATH: "${{ github.workspace }}/.github/workflows" + NEW_VERSION: "${{ needs.get_validate_version.outputs.version }}" + GITHUB_TOKEN: "${{ secrets.CICD_TOKEN }}" + run: | + if ("${{ inputs.dry-run == true }}" -eq "true") { + Write-Host "::notice::Updating 'CICD_SCRIPTS_VERSION' repository variable ..."; + exit 0; + } + + deno run -ERWN "${{ github.workspace }}/.github/internal-cicd/scripts/update-workflow-versions.ts"; + + $releaseType = "${{ inputs.release-type }}"; + + git config --global user.email "${{ vars.GIT_CONFIG_EMAIL }}"; + git config --global user.name "CICD Release Script - (On behalf of Calvin Wilkinson)"; + + git add -A; + git commit -m "🚀$releaseType (${{ needs.get_validate_version.outputs.version }}) - Update reusable workflow versions"; + git push; + - name: Create GitHub Release ${{ inputs.dry-run == true && '(Dry Run)' || '' }} if: ${{ inputs.dry-run == false }} uses: ncipollo/release-action@v1 @@ -275,3 +276,16 @@ jobs: } deno run -ERN "${{ steps.script-url.outputs.url }}/close-milestone.ts"; + + - name: Update CICD Script Version Repo Var ${{ inputs.dry-run == true && '(Dry Run)' || '' }} + env: + CICD_SCRIPTS_VERSION_REPO_VAR_NAME: "CICD_SCRIPTS_VERSION" + VERSION: "${{ needs.get_validate_version.outputs.version }}" + GITHUB_TOKEN: "${{ secrets.CICD_TOKEN }}" + run: | + if ("${{ inputs.dry-run == true }}" -eq "true") { + Write-Host "::notice::Updating 'CICD_SCRIPTS_VERSION' repository variable ..."; + exit 0; + } + + deno run -EN "${{ github.workspace }}/.github/internal-cicd/scripts/update-cicd-script-version.ts"; diff --git a/.github/workflows/run-csharp-tests.yml b/.github/workflows/run-csharp-tests.yml index 74385411..dda33caa 100644 --- a/.github/workflows/run-csharp-tests.yml +++ b/.github/workflows/run-csharp-tests.yml @@ -110,7 +110,7 @@ jobs: repository: ${{ inputs.checkout-repository }} ref: ${{ inputs.checkout-ref }} - - uses: actions/setup-dotnet@v3 + - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ inputs.net-sdk-version }} diff --git a/.github/workflows/sync-bot.yml b/.github/workflows/sync-bot.yml index fe7b0c56..9c314b7d 100644 --- a/.github/workflows/sync-bot.yml +++ b/.github/workflows/sync-bot.yml @@ -17,7 +17,7 @@ jobs: if: ${{ !github.event.issue.pull_request }} runs-on: ubuntu-latest steps: - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/validate-csharp-version.yml b/.github/workflows/validate-csharp-version.yml index 5972835b..1e2d120f 100644 --- a/.github/workflows/validate-csharp-version.yml +++ b/.github/workflows/validate-csharp-version.yml @@ -62,7 +62,7 @@ jobs: steps: - name: Get Version From Project File id: get-version - uses: KinsonDigital/VersionMiner@v1.0.0-preview.5 + uses: KinsonDigital/VersionMiner@v1.0.0 with: repo-owner: ${{ vars.ORGANIZATION_NAME }} repo-name: ${{ inputs.project-name }} @@ -72,7 +72,7 @@ jobs: file-path: '${{ inputs.project-name }}/${{ inputs.project-name }}.csproj' version-keys: Version - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/validate-github-release.yml b/.github/workflows/validate-github-release.yml index c9786eab..b16b5edf 100644 --- a/.github/workflows/validate-github-release.yml +++ b/.github/workflows/validate-github-release.yml @@ -65,7 +65,7 @@ jobs: needs: print_validate_workflow runs-on: ubuntu-latest steps: - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/validate-milestone-status.yml b/.github/workflows/validate-milestone-status.yml index fd8caeb4..5b7e2ce2 100644 --- a/.github/workflows/validate-milestone-status.yml +++ b/.github/workflows/validate-milestone-status.yml @@ -68,7 +68,7 @@ jobs: needs: print_validate_workflow runs-on: ubuntu-latest steps: - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/validate-sdk-versions.yml b/.github/workflows/validate-sdk-versions.yml index a49e854c..d3c1c565 100644 --- a/.github/workflows/validate-sdk-versions.yml +++ b/.github/workflows/validate-sdk-versions.yml @@ -39,7 +39,7 @@ jobs: exit 1; } - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/validate-tag.yml b/.github/workflows/validate-tag.yml index 690c14e9..9cf7c6e6 100644 --- a/.github/workflows/validate-tag.yml +++ b/.github/workflows/validate-tag.yml @@ -77,7 +77,7 @@ jobs: name: Validate Tag runs-on: ubuntu-latest steps: - - name: Set Up Deno + - name: Set Up Deno (${{ vars.DENO_VERSION }}) uses: denoland/setup-deno@v2 with: deno-version: ${{ vars.DENO_VERSION }} diff --git a/.github/workflows/workflow-version-status-check.yml b/.github/workflows/workflow-version-status-check.yml deleted file mode 100644 index 0acb57a3..00000000 --- a/.github/workflows/workflow-version-status-check.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: ✅Workflow Version Status Check - - -defaults: - run: - shell: pwsh - - -on: - pull_request: - branches: [main, preview] - - -jobs: - workflow_version_status_check: - name: Workflow Version Status Check - runs-on: ubuntu-latest - if: ${{ github.event.pull_request.head.ref == vars.PREV_PREP_RELEASE_HEAD_BRANCH || - github.event.pull_request.head.ref == vars.PROD_PREP_RELEASE_HEAD_BRANCH }} - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set Up Deno - uses: denoland/setup-deno@v2 - with: - deno-version: ${{ vars.DENO_VERSION }} - - - name: Run Status Check Script - env: - OWNER_NAME: "${{ vars.ORGANIZATION_NAME }}" - REPO_NAME: "${{ vars.PROJECT_NAME }}" - BASE_DIR_PATH: "${{ github.workspace }}/.github/workflows" - GITHUB_TOKEN: "${{ secrets.CICD_TOKEN }}" - run: deno run -ERN "${{ github.workspace }}/.github/internal-cicd/scripts/workflow-version-status-check.ts"; diff --git a/.vscode/launch.json b/.vscode/launch.json index 19b9ecb0..68070a9e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -398,11 +398,14 @@ "cwd": "${workspaceFolder}", "runtimeArgs": [ "run", - "-ENRWS", + "-ERWN", "--inspect-wait", ], "env": { + "OWNER_NAME": "KinsonDigital", + "REPO_NAME": "Infrastructure", "BASE_DIR_PATH": "${workspaceFolder}/.github/workflows", + "NEW_VERSION": "v1.2.3", "GITHUB_TOKEN": "${env:CICD_TOKEN}", }, "attachSimplePort": 9229, @@ -585,21 +588,22 @@ "runtimeExecutable": "${userHome}/.deno/bin/deno" } }, - { // CHECK WORKFLOW VERSIONS - "name": "Check Workflow Versions", + { // UPDATE CICD SCRIPT VERSION + "name": "Update CICD Script Version", "request": "launch", "type": "node", - "program": "${workspaceFolder}/cicd/scripts/check-workflow-versions.ts", + "program": "${workspaceFolder}/.github/internal-cicd/scripts/update-cicd-script-version.ts", "cwd": "${workspaceFolder}", "runtimeArgs": [ "run", - "-ERN", + "-EN", "--inspect-wait", ], "env": { "OWNER_NAME": "KinsonDigital", "REPO_NAME": "Infrastructure", - "BASE_DIR_PATH": "${workspaceFolder}/.github/workflows", + "CICD_SCRIPTS_VERSION_REPO_VAR_NAME": "CICD_SCRIPTS_VERSION", + "VERSION": "v1.2.3", "GITHUB_TOKEN": "${env:CICD_TOKEN}", }, "attachSimplePort": 9229, diff --git a/.vscode/settings.json b/.vscode/settings.json index 33f885c9..0b793b7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,13 +6,20 @@ "cSpell.words": [ "cicd", "Creds", + "demilestoned", + "denoland", "endgroup", + "ERWN", "flatcontainer", "kdadmin", "Kinson", + "kinsondigital", "mediumseagreen", + "milestoned", "ncipollo", + "notmatch", "Nums", + "nupkg", "pwsh", "REPONAME", "snupkg", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 230a30d9..5bf6a724 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,25 +28,5 @@ "${workspaceFolder}/.github/cicd", ] }, - { // UPDATE WORKFLOW VERSIONS - "label": "Update Workflow Versions", - "detail": "Updates all of the reusuable workflow versions.", - "type": "shell", - "dependsOn": ["clear-terminal"], - "windows": { - "command": "deno", - "options": { - "env": { - "BASE_DIR_PATH": "${workspaceFolder}/.github/workflows", - "GITHUB_TOKEN": "${env:CICD_TOKEN}", - } - }, - "args": [ - "run", - "-ERWNS", - "${workspaceFolder}/.github/internal-cicd/scripts/update-workflow-versions.ts", - ] - } - } ] } diff --git a/cicd/scripts/check-workflow-versions.ts b/cicd/scripts/check-workflow-versions.ts deleted file mode 100644 index ec4d80e7..00000000 --- a/cicd/scripts/check-workflow-versions.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { walkSync } from "jsr:@std/fs@^1.0.4"; -import { exists } from "jsr:@std/fs@^1.0.4"; -import { basename } from "jsr:@std/path@^1.0.6"; -import { TagClient } from "../../deps.ts"; -import { Utils } from "../../cicd/core/Utils.ts"; -import getEnvVar from "../../cicd/core/GetEnvVar.ts"; -import { validateOrgExists, validateRepoExists } from "../../cicd/core/Validators.ts"; - -const scriptFileName = new URL(import.meta.url).pathname.split("/").pop(); - -const ownerName = getEnvVar("OWNER_NAME", scriptFileName); -const repoName = getEnvVar("REPO_NAME", scriptFileName); -let baseDirPath = getEnvVar("BASE_DIR_PATH", scriptFileName); -baseDirPath = Utils.normalizePath(baseDirPath); -const token = getEnvVar("GITHUB_TOKEN", scriptFileName); - -await validateOrgExists(scriptFileName); -await validateRepoExists(scriptFileName); - -if (!exists(baseDirPath)) { - Utils.printAsGitHubError(`Directory '${baseDirPath}' does not exist.`); - Deno.exit(1); -} - -const yamlFiles = [...walkSync(baseDirPath, { - includeDirs: false, - includeFiles: true, - exts: [".yaml", ".yml"], -})].map((e) => e.path); - -const tagClient: TagClient = new TagClient(ownerName, repoName, token); - -const existingReleaseTags = (await tagClient.getAllTags()).map((t) => t.name); - -const workflowsToUpdate: WorkflowToUpdate[] = []; - -const reusableWorkflowRegex = /uses: .+.(yml|yaml)@v([1-9]\d*|0)\.([1-9]\d*|0)\.([1-9]\d*|0)(-preview\.([1-9]\d*))?/gm; - -type WorkflowToUpdate = { - /** - * The file path to the workflow. - */ - filePath: string; - - /** - * The reusable workflow references that need to be updated. - */ - workflowRefs: string[]; -}; - -// Search for workflow references with a version that has not been updated -yamlFiles.forEach((yamlFile) => { - const workflowToUpdate: WorkflowToUpdate = { - filePath: yamlFile, - workflowRefs: [], - }; - - const fileContent = Deno.readTextFileSync(yamlFile); - - const possibleUpdates = fileContent.match(reusableWorkflowRegex)?.map((w) => w) ?? []; - - // Check each reusable workflow reference version - possibleUpdates.forEach((possibleUpdate) => { - const fullRef = possibleUpdate.split("uses:")[1].trim(); - const workflowRefVersion = possibleUpdate.split("@")[1]; - - // If the workflow version has not been updated - if (existingReleaseTags.includes(workflowRefVersion)) { - workflowToUpdate.workflowRefs.push(fullRef); - } - }); - - if (workflowToUpdate.workflowRefs.length > 0) { - workflowsToUpdate.push(workflowToUpdate); - } -}); - -// If there are no workflows to update, then exit -if (workflowsToUpdate.length === 0) { - Utils.printAsGitHubNotice("No workflows to update."); - Deno.exit(0); -} - -const errorMsgs: string[] = []; - -// Print out all of the workflows that need to be updated as an error -workflowsToUpdate.forEach((workflowToUpdate) => { - const filePath = basename(workflowToUpdate.filePath); - - const workflowErrors: string[] = workflowToUpdate.workflowRefs.map((workflowRef) => { - return `Workflow reference '${workflowRef}' in file '${filePath}' needs to be updated.`; - }); - - errorMsgs.push(...workflowErrors); -}); - -if (errorMsgs.length > 0) { - Utils.printAsGitHubErrors(errorMsgs); - Deno.exit(1); -} diff --git a/deno.lock b/deno.lock index 867208e9..a5f2ec6a 100644 --- a/deno.lock +++ b/deno.lock @@ -1,12 +1,34 @@ { "version": "4", "specifiers": { + "jsr:@cliffy/ansi@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/internal@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/keycode@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@cliffy/prompt@1.0.0-rc.7": "1.0.0-rc.7", + "jsr:@kinsondigital/kd-clients@1.0.0-preview.14": "1.0.0-preview.14", + "jsr:@nexterias/twitter-api-fetch@3.0.1": "3.0.1", + "jsr:@std/assert@0.224": "0.224.0", + "jsr:@std/assert@0.224.0": "0.224.0", + "jsr:@std/assert@~1.0.6": "1.0.11", + "jsr:@std/encoding@0.224.0": "0.224.0", + "jsr:@std/encoding@~0.219.1": "0.219.1", + "jsr:@std/encoding@~1.0.5": "1.0.7", + "jsr:@std/fmt@0.224": "0.224.0", + "jsr:@std/fmt@~1.0.2": "1.0.5", "jsr:@std/fs@*": "1.0.4", + "jsr:@std/fs@0.224.0": "0.224.0", + "jsr:@std/fs@1.0.11": "1.0.11", "jsr:@std/fs@1.0.4": "1.0.4", "jsr:@std/fs@1.0.8": "1.0.8", "jsr:@std/fs@^1.0.4": "1.0.8", + "jsr:@std/internal@0.224": "0.224.0", + "jsr:@std/path@0.224": "0.224.0", + "jsr:@std/path@0.224.0": "0.224.0", "jsr:@std/path@^1.0.6": "1.0.8", "jsr:@std/path@^1.0.8": "1.0.8", + "jsr:@std/path@~1.0.6": "1.0.8", + "jsr:@std/testing@0.224.0": "0.224.0", + "jsr:@std/text@~1.0.7": "1.0.10", "npm:@types/node@*": "18.16.19", "npm:chalk@4.1.1": "4.1.1", "npm:chalk@5.3.0": "5.3.0", @@ -14,6 +36,80 @@ "npm:twitter-api-v2@1.15.0": "1.15.0" }, "jsr": { + "@cliffy/ansi@1.0.0-rc.7": { + "integrity": "f71c921cce224c13d322e5cedba4f38e8f7354c7d855c9cb22729362a53f25aa", + "dependencies": [ + "jsr:@cliffy/internal", + "jsr:@std/encoding@~1.0.5" + ] + }, + "@cliffy/internal@1.0.0-rc.7": { + "integrity": "10412636ab3e67517d448be9eaab1b70c88eba9be22617b5d146257a11cc9b17" + }, + "@cliffy/keycode@1.0.0-rc.7": { + "integrity": "5b3f6c33994e81a76b79f108b1989642ac22705840da33781f7972d7dff05503" + }, + "@cliffy/prompt@1.0.0-rc.7": { + "integrity": "a9cbd13acd8073558447cae8ca4cf593c09d23bcbe429cc63346920c21187b83", + "dependencies": [ + "jsr:@cliffy/ansi", + "jsr:@cliffy/internal", + "jsr:@cliffy/keycode", + "jsr:@std/assert@~1.0.6", + "jsr:@std/fmt@~1.0.2", + "jsr:@std/path@~1.0.6", + "jsr:@std/text" + ] + }, + "@kinsondigital/kd-clients@1.0.0-preview.14": { + "integrity": "fd6f87a697715c9aecdf7c9f6e23e246f3929db9defb16f866c33fa784366e5f", + "dependencies": [ + "jsr:@nexterias/twitter-api-fetch", + "jsr:@std/assert@0.224.0", + "jsr:@std/encoding@0.224.0", + "jsr:@std/fs@0.224.0", + "jsr:@std/path@0.224.0", + "jsr:@std/testing" + ] + }, + "@nexterias/twitter-api-fetch@3.0.1": { + "integrity": "9fb5a6770ce659b46df02c3b93ed4ab13ce7b3dd9a84232e0bc921fe7bdd1dad", + "dependencies": [ + "jsr:@std/encoding@~0.219.1" + ] + }, + "@std/assert@0.224.0": { + "integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f", + "dependencies": [ + "jsr:@std/fmt@0.224", + "jsr:@std/internal" + ] + }, + "@std/assert@1.0.11": { + "integrity": "2461ef3c368fe88bc60e186e7744a93112f16fd110022e113a0849e94d1c83c1" + }, + "@std/encoding@0.219.1": { + "integrity": "77b30e481a596cfb2a8f2f38c3165e6035a4f76a7259bf89b6a622ceaf57d575" + }, + "@std/encoding@0.224.0": { + "integrity": "efb6dca97d3e9c31392bd5c8cfd9f9fc9decf5a1f4d1f78af7900a493bcf89b5" + }, + "@std/encoding@1.0.7": { + "integrity": "f631247c1698fef289f2de9e2a33d571e46133b38d042905e3eac3715030a82d" + }, + "@std/fmt@0.224.0": { + "integrity": "e20e9a2312a8b5393272c26191c0a68eda8d2c4b08b046bad1673148f1d69851" + }, + "@std/fmt@1.0.5": { + "integrity": "0cfab43364bc36650d83c425cd6d99910fc20c4576631149f0f987eddede1a4d" + }, + "@std/fs@0.224.0": { + "integrity": "52a5ec89731ac0ca8f971079339286f88c571a4d61686acf75833f03a89d8e69", + "dependencies": [ + "jsr:@std/assert@0.224", + "jsr:@std/path@0.224" + ] + }, "@std/fs@1.0.4": { "integrity": "2907d32d8d1d9e540588fd5fe0ec21ee638134bd51df327ad4e443aaef07123c", "dependencies": [ @@ -26,11 +122,38 @@ "jsr:@std/path@^1.0.8" ] }, + "@std/fs@1.0.11": { + "integrity": "ba674672693340c5ebdd018b4fe1af46cb08741f42b4c538154e97d217b55bdd", + "dependencies": [ + "jsr:@std/path@^1.0.8" + ] + }, + "@std/internal@0.224.0": { + "integrity": "afc50644f9cdf4495eeb80523a8f6d27226b4b36c45c7c195dfccad4b8509291", + "dependencies": [ + "jsr:@std/fmt@0.224" + ] + }, + "@std/path@0.224.0": { + "integrity": "55bca6361e5a6d158b9380e82d4981d82d338ec587de02951e2b7c3a24910ee6", + "dependencies": [ + "jsr:@std/assert@0.224" + ] + }, "@std/path@1.0.6": { "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" }, "@std/path@1.0.8": { "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" + }, + "@std/testing@0.224.0": { + "integrity": "371b8a929aa7132240d5dd766a439be8f780ef5c176ab194e0bcab72370c761e", + "dependencies": [ + "jsr:@std/assert@0.224" + ] + }, + "@std/text@1.0.10": { + "integrity": "9dcab377450253c0efa9a9a0c731040bfd4e1c03f8303b5934381467b7954338" } }, "npm": { diff --git a/deps.ts b/deps.ts index 7039a5bd..5d588e38 100644 --- a/deps.ts +++ b/deps.ts @@ -30,9 +30,6 @@ import { UserModel, } from "https://deno.land/x/kd_clients@v1.0.0-preview.8/core/Models/mod.ts"; -// CLIFFY -import { Input } from "https://deno.land/x/cliffy@v1.0.0-rc.3/prompt/input.ts"; - // NPM PACKAGES import chalk from "npm:chalk@5.3.0"; @@ -64,9 +61,6 @@ export { }; export type { GitHubVarModel, IssueModel, LabelModel, MilestoneModel, ProjectModel, PullRequestModel, UserModel }; -// CLIFFY -export { Input }; - // NPM PACKAGES export default chalk;