Skip to content

Commit

Permalink
🚧Remove all code related to printing out arg values (#232)
Browse files Browse the repository at this point in the history
* Start work for issue #213

* chore: create function to validate and get env vars

* chore: create functions for validation

* security: printing of arguments removed

* ci: refactor add item to project script to use env vars

* ci: refactor milestone exists script to use env vars

* config: adjust dir separators

* ci: refactor resolve cs proj script to use env vars

* config: reformat deno config json

* ci: refactor release tweet script to use env vars

* ci: refactor transpile readme script to use env vars

* refactor: change how workspace dir path is extracted

* chore: improve version check

* refactor: change validate sdk setup script to use env vars

* chore: add todo comments

* refactor: update close milestone script to use env vars

* refactor: update nuget package check script to use env vars

* refactor: update validate version script to use env vars

* refactor: update validate github release script to use env vars

* refactor: update validate tag script to use env vars

* refactor: update workflow version status check script to use env vars

* fix: fix error log message

* config: set vscode title and workbench color

* refactor: update playground and launch config to use env vars
  • Loading branch information
CalvinWilkinson authored Oct 8, 2024
1 parent 584da20 commit 828d873
Show file tree
Hide file tree
Showing 43 changed files with 796 additions and 1,396 deletions.
41 changes: 21 additions & 20 deletions .github/internal-cicd/scripts/workflow-version-status-check.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { walkSync } from "@std/fs/walk";
import { exists } from "@std/fs/exists";
import { basename } from "@std/path/basename";
import { 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";
import getEnvVar from "../../../cicd/core/GetEnvVar.ts";
import { validateOrgExists, validateRepoExists } from "../../../cicd/core/Validators.ts";

if (Deno.args.length != 2) {
let errorMsg = "Invalid number of arguments.";
errorMsg += "\nArg 1: Fully qualified directory path of where to search for YAML files.";
errorMsg += "\nArg 2: GitHub token.";
Utils.printAsGitHubError(errorMsg);
Deno.exit(1);
}
const scriptFileName = new URL(import.meta.url).pathname.split("/").pop();

let baseDirPath = Deno.args[0];
const token = Deno.args[1];
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);

baseDirPath = Utils.normalizePath(baseDirPath.trim());
await validateOrgExists(scriptFileName);
await validateRepoExists(scriptFileName);

if (!Directory.Exists(baseDirPath)) {
if (!exists(baseDirPath)) {
Utils.printAsGitHubError(`Directory '${baseDirPath}' does not exist.`);
Deno.exit(1);
}

const ownerName = "KinsonDigital";
const repoName = "Infrastructure";
const allFiles = Directory.getFiles(baseDirPath, true);
const yamlFiles = [...walkSync(baseDirPath, {
includeDirs: false,
includeFiles: true,
exts: [".yaml", ".yml"],
})].map((e) => e.path);

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

const existingReleaseTags = (await tagClient.getAllTags()).map((t) => t.name);
Expand Down Expand Up @@ -54,7 +55,7 @@ yamlFiles.forEach(yamlFile => {
workflowRefs: []
};

const fileContent = File.LoadFile(yamlFile);
const fileContent = Deno.readTextFileSync(yamlFile);

const possibleUpdates = fileContent.match(reusableWorkflowRegex)?.map((w) => w) ?? [];

Expand Down Expand Up @@ -84,7 +85,7 @@ const errorMsgs: string[] = [];

// Print out all of the workflows that need to be updated as an error
workflowsToUpdate.forEach(workflowToUpdate => {
const filePath = Path.getFileName(workflowToUpdate.filePath);
const filePath = basename(workflowToUpdate.filePath);

const workflowErrors: string[] = workflowToUpdate.workflowRefs.map((workflowRef) => {
return `Workflow reference '${workflowRef}' in file '${filePath}' needs to be updated.`;
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/add-item-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ jobs:
exit 1;
}
if ("${{ inputs.org-project-name }}" -eq "") {
Write-Host ":error::The 'org-project-name' workflow input cannot be empty.";
exit 1;
}
if ("${{ inputs.repo-name }}" -eq "") {
Write-Host ":error::The 'repo-name' workflow input cannot be empty.";
exit 1;
Expand All @@ -69,6 +67,12 @@ jobs:
deno-version: ${{ vars.DENO_VERSION }}

- name: Add To Project
env:
REPO_OWNER: "${{ inputs.org-name }}"
REPO_NAME: "${{ inputs.org-project-name }}"
PROJECT_NAME: "${{ inputs.repo-name }}"
ISSUE_OR_PR_NUMBER: "${{ inputs.item-number }}"
GITHUB_TOKEN: "${{ secrets.cicd-pat }}"
run: |
# Construct the URL to the organizations CICD scripts
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH }}";
Expand All @@ -78,18 +82,4 @@ jobs:
Write-Host "::notice::NuGet Package Check Script URL: $scriptUrl";
<# Deno Args:
1. Organization name
2. Project name
3. Repo name
4. Issue or PR number
5. PAT
#>
deno run `
--allow-net --allow-read `
"$scriptUrl" `
"${{ inputs.org-name }}" `
"${{ inputs.org-project-name }}" `
"${{ inputs.repo-name }}" `
"${{ inputs.item-number }}" `
"${{ secrets.cicd-pat }}";
deno run --allow-net --allow-read "$scriptUrl";
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-action-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
validate_sdk_setup:
name: Validate SDK Setup
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/validate-sdk-setup[email protected]
uses: KinsonDigital/Infrastructure/.github/workflows/validate-sdk-versions[email protected]
with:
repo-name: "${{ inputs.project-name }}"
secrets:
Expand Down
89 changes: 30 additions & 59 deletions .github/workflows/dotnet-lib-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ on:
description: The Twitter access token secret.


env:
OWNER_NAME: "${{ vars.ORGANIZATION_NAME }}"
REPO_NAME: "${{ inputs.project-name }}"


jobs:
print_validate_workflow:
name: Print & Validate DotNet Lib Release Workflow
Expand Down Expand Up @@ -198,7 +203,7 @@ jobs:
validate_sdk_setup:
name: Validate SDK Setup
needs: print_validate_workflow
uses: KinsonDigital/Infrastructure/.github/workflows/validate-sdk-setup[email protected]
uses: KinsonDigital/Infrastructure/.github/workflows/validate-sdk-versions[email protected]
with:
repo-name: "${{ inputs.project-name }}"
secrets:
Expand Down Expand Up @@ -305,26 +310,15 @@ jobs:
- name: Transpile README
if: inputs.transpile-readme == true
run: |
$scriptUrl = "${{ steps.script-url.outputs.url }}/transpile-readme.ts";
$readmeDirPath = "$env:GITHUB_WORKSPACE";
<# Deno Args:
1. Readme file directory path
2. PAT
#>
deno run `
--allow-read `
--allow-write `
"$scriptUrl" `
"$readmeDirPath" `
"${{ secrets.cicd-pat }}";
env:
BASE_DIR_PATH: "${{ github.workspace }}"
run: deno run -ERW "${{ steps.script-url.outputs.url }}/transpile-readme.ts";

- name: Create Nuget Package
run: |
dotnet pack `
"$env:GITHUB_WORKSPACE/${{ inputs.project-name }}/${{ inputs.project-name }}.csproj" `
-o "$env:GITHUB_WORKSPACE" `
"${{ github.workspace }}/${{ inputs.project-name }}/${{ inputs.project-name }}.csproj" `
-o "${{ github.workspace }}" `
-c ${{ inputs.build-config }};
- name: Publish Nuget Package
Expand All @@ -334,14 +328,14 @@ jobs:
$version = $version.StartsWith("v") ? $version.Substring(1) : $version;
dotnet nuget push `
"$env:GITHUB_WORKSPACE/${{ vars.ORGANIZATION_NAME }}.${{ inputs.project-name }}.$version.nupkg" `
"${{ github.workspace }}/${{ vars.ORGANIZATION_NAME }}.${{ inputs.project-name }}.$version.nupkg" `
--api-key ${{ secrets.nuget-org-api-key }} `
--source https://api.nuget.org/v3/index.json;
- name: Get GitHub Workspace
id: base-dir-path
run: |
"github-workspace=$env:GITHUB_WORKSPACE" >> $env:GITHUB_OUTPUT;
"github-workspace=${{ github.workspace }}" >> $env:GITHUB_OUTPUT;
- name: Create GitHub Release ${{ inputs.dry-run == true && '(Dry Run)' || '' }}
if: ${{ inputs.dry-run == false }}
Expand Down Expand Up @@ -373,49 +367,26 @@ jobs:
-F $fullReleaseNotesPath `
$isPreRelease `
$fullReleaseNotesPath;
- name: Close Milestone
if: ${{ inputs.dry-run == false }}
run: |
$scriptUrl = "${{ steps.script-url.outputs.url }}/close-milestone.ts";
<# Deno Args:
1. Project name
2. Milestone name - This is the version
3. PAT
#>
deno run `
--allow-read --allow-net `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ inputs.project-name }}" `
"${{ needs.validate_version.outputs.version }}" `
"${{ secrets.cicd-pat }}";
env:
MILESTONE_NAME: "${{ needs.validate_version.outputs.version }}"
GITHUB_TOKEN: "${{ secrets.cicd-pat }}"
run: deno run -ERN "${{ steps.script-url.outputs.url }}/close-milestone.ts";

- name: Send Twitter Announcement
if: ${{ inputs.send-release-tweet == true && inputs.dry-run == false }}
run: |
$scriptUrl = "${{ steps.script-url.outputs.url }}/send-release-tweet.ts";
<# Deno Args:
1. Repo owner
2. Project name
3. Version
4. Twitter consumer api key
5. Twitter consumer api secret
6. Twitter access token
7. Twitter access token secret
8. PAT
#>
deno run `
--allow-read --allow-net --allow-env `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ inputs.project-name }}" `
"${{ needs.validate_version.outputs.version }}" `
"${{ secrets.twitter-consumer-api-key }}" `
"${{ secrets.twitter-consumer-api-secret }}" `
"${{ secrets.twitter-access-token }}" `
"${{ secrets.twitter-access-token-secret }}" `
"${{ secrets.cicd-pat }}";
env:
VERSION: "${{ needs.validate_version.outputs.version }}"
GITHUB_TOKEN: "${{ secrets.cicd-pat }}"
RELEASE_TWEET_TEMPLATE_REPO_NAME: "${{ vars.RELEASE_TWEET_TEMPLATE_REPO_NAME }}"
RELEASE_TWEET_TEMPLATE_BRANCH_NAME: "${{ vars.RELEASE_TWEET_TEMPLATE_BRANCH_NAME }}"
RELATIVE_RELEASE_TWEET_TEMPLATE_FILE_PATH: "${{ vars.RELATIVE_RELEASE_TWEET_TEMPLATE_FILE_PATH }}"
DISCORD_INVITE_CODE: "${{ vars.DISCORD_INVITE_CODE }}"
TWITTER_BROADCAST_ENABLED: "${{ vars.TWITTER_BROADCAST_ENABLED }}"
TWITTER_ACCESS_TOKEN_KEY: "${{ secrets.twitter-access-token }}"
TWITTER_ACCESS_TOKEN_SECRET: "${{ secrets.twitter-access-token-secret }}"
TWITTER_CONSUMER_API_KEY: "${{ secrets.twitter-consumer-api-key }}"
TWITTER_CONSUMER_API_SECRET: "${{ secrets.twitter-consumer-api-secret }}"
run: deno run -ERN "${{ steps.script-url.outputs.url }}/send-release-tweet.ts";
13 changes: 4 additions & 9 deletions .github/workflows/nuget-package-does-not-exist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
deno-version: ${{ vars.DENO_VERSION }}

- name: Package Does Not Exist
env:
NUGET_PKG_NAME: "${{ vars.ORGANIZATION_NAME }}.${{ inputs.project-name }}"
NUGET_PKG_VERSION: "${{ inputs.version }}"
run: |
# Construct the URL to the organizations CICD scripts
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH }}";
Expand All @@ -67,12 +70,4 @@ jobs:
Write-Host "::notice::NuGet Package Check Script URL: $scriptUrl";
<# Deno Args:
1. Package name
2. Version
#>
deno run `
--allow-net --allow-read `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}.${{ inputs.project-name }}" `
"${{ inputs.version }}";
deno run -ERN "$scriptUrl";
27 changes: 6 additions & 21 deletions .github/workflows/resolve-csharp-proj-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ jobs:
outputs:
project-file-path: ${{ steps.resolve-file-path.outputs.project-file-path }}
steps:
- name: Print Environment Variables
run: Get-ChildItem -Path Env:* | Sort-Object Name

- uses: actions/checkout@v4

- name: Set Up Deno
- name: Set Up Deno (${{ vars.DENO_VERSION }})
uses: denoland/setup-deno@v1
with:
deno-version: ${{ vars.DENO_VERSION }}
Expand Down Expand Up @@ -77,20 +74,8 @@ jobs:
- name: Resolve Project File Path
id: resolve-file-path
run: |
$scriptUrl = "${{ steps.script-url.outputs.url }}/resolve-csproj.ts";
$basePath = "${{ inputs.base-path }}" -eq "" ? "${{ github.workspace }}" : "${{ inputs.base-path }}";
<# Deno Args:
1. The name of the project
2. The fully qualified directory path to start the search
3. The GitHub token
#>
deno run `
--allow-read `
--allow-write `
--allow-env `
"$scriptUrl" `
"${{ vars.PROJECT_NAME }}" `
"$basePath" `
"${{ secrets.cicd-pat }}";
env:
PROJECT_NAME: "${{ vars.PROJECT_NAME }}"
BASE_DIR_PATH: "${{ inputs.base-path == '' && github.workspace || inputs.base-path }}"
GITHUB_TOKEN: ${{ secrets.cicd-pat }}
run: deno run -ERW "${{ steps.script-url.outputs.url }}/resolve-csproj.ts";
16 changes: 4 additions & 12 deletions .github/workflows/validate-csharp-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ jobs:

- name: Validate Version
id: validate-version
env:
VERSION: "${{ steps.get-version.outputs.version }}"
RELEASE_TYPE: "${{ inputs.release-type }}"
run: |
# Construct the URL to the organizations CICD scripts
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH }}";
Expand All @@ -88,18 +91,7 @@ jobs:
Write-Host "::notice::Validate DotNet Version Script URL: $scriptUrl";
# Get the release version and make sure it starts with the letter 'v'
$releaseVersion = "${{ steps.get-version.outputs.version }}".Trim().ToLower();
$releaseVersion = $releaseVersion.StartsWith("v") ? $releaseVersion : "v$releaseVersion";
# Set the output of this step
"version=$releaseVersion" >> $env:GITHUB_OUTPUT;
<# Deno Args:
1. Version
2. Version type
#>
deno run `
"$scriptUrl" `
"$releaseVersion" `
"${{ inputs.release-type }}";
deno run -E "$scriptUrl";
18 changes: 6 additions & 12 deletions .github/workflows/validate-github-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
deno-version: ${{ vars.DENO_VERSION }}

- name: GitHub Release Does Not Exist
env:
OWNER_NAME: "${{ vars.ORGANIZATION_NAME }}"
REPO_NAME: "${{ inputs.project-name }}"
TAG_NAME: "${{ inputs.version }}"
GITHUB_TOKEN: "${{ secrets.cicd-pat }}"
run: |
# Construct the URL to the organizations CICD scripts
$scriptUrl = "${{ vars.SCRIPT_BASE_URL }}/${{ vars.CICD_SCRIPTS_VERSION }}/${{ vars.SCRIPT_RELATIVE_DIR_PATH }}";
Expand All @@ -80,15 +85,4 @@ jobs:
Write-Host "::notice::Validate GitHub Release Version Script URL: $scriptUrl";
<# Deno Args:
1. Repo name
2. TagName - This is prev or prod version
3. PAT
#>
deno run `
--allow-net --allow-read `
"$scriptUrl" `
"${{ vars.ORGANIZATION_NAME }}" `
"${{ inputs.project-name }}" `
"${{ inputs.version }}" `
"${{ secrets.cicd-pat }}";
deno run -ERN "$scriptUrl";
Loading

0 comments on commit 828d873

Please sign in to comment.