Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Create status checks #87

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions .github/cicd/validate-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { existsSync } from "https://deno.land/[email protected]/fs/exists.ts";
// Validate the arguments
if (Deno.args.length !== 2) {
let errorMsg = "The 'validate-notes' cicd script must have two arguments.";
errorMsg += "\nThe first arg must be either 'production' or 'preview'.";
errorMsg += "\nThe first arg must be either 'production', 'preview' or 'either'.";
errorMsg += "\nThe second arg must be the version of the notes.";

throw new Error(errorMsg);
}

const notesType: string = Deno.args[0].toLowerCase();
const version: string = Deno.args[1];

console.log("::group::Argument Values");
console.log(`Notes Type: ${notesType}`);
console.log(`Version: ${version}`);
console.log("::endgroup::");

if (notesType !== "production" && notesType !== "preview") {
let errorMsg = "The notes type argument must be a value of 'production' or 'preview'.";
if (notesType !== "production" && notesType !== "preview" && notesType != "either") {
let errorMsg = "The notes type argument must be a value of 'production', 'preview' or 'either'.";
errorMsg += "\nThe value is case-insensitive.";

throw new Error(errorMsg);
Expand All @@ -21,7 +27,6 @@ if (notesType !== "production" && notesType !== "preview") {
const prodVersionRegex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
const prevVersionRegex = /^v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$/;

const version: string = Deno.args[1];
let isValid = false;

if (notesType === "production") {
Expand All @@ -34,7 +39,15 @@ if (isValid === false) {
throw new Error(`The version is not in the correct ${notesType} version syntax.`);
}

const notesDirName = notesType === "production" ? "ProductionReleases" : "PreviewReleases";
let notesDirName = "";

if (notesType == "production" || notesType === "preview") {
notesDirName = notesType === "production" ? "ProductionReleases" : "PreviewReleases";
} else {
const isPrevTag: boolean = version.indexOf("-preview.") != -1;
notesDirName = isPrevTag ? "PreviewReleases" : "ProductionReleases";
}

const notesFilePath = `${Deno.cwd()}/Documentation/ReleaseNotes/${notesDirName}/Release-Notes-${version}.md`;

if (!existsSync(notesFilePath)) {
Expand Down
48 changes: 30 additions & 18 deletions .github/cicd/validate-tag.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
// Validate the arguments
if (Deno.args.length !== 3) {
let errorMsg = "The 'validate-tag' cicd script must have two arguments.";
errorMsg += "\nThe first arg must be either 'production' or 'preview'.";
errorMsg += "\nThe first arg must be either 'production', 'preview' or 'either'.";
errorMsg += "\nThe second arg must be the name of the tag.";

throw new Error(errorMsg);
}

const tagType: string = Deno.args[0].toLowerCase();
const tag: string = Deno.args[1].startsWith("v") ? Deno.args[1] : `v${Deno.args[1]}`;
const projectName: string = Deno.args[2];

console.log("::group::Argument Values")
console.log(`Tag Type: ${tagType}`);
console.log(`Tag: ${tag}`);
console.log(`Project Name: ${projectName}`);
console.log("::endgroup::");

if (tagType !== "production" && tagType !== "preview") {
let errorMsg = "The tag type argument must be a value of 'production' or 'preview'.";
if (tagType !== "production" && tagType !== "preview" && tagType !== "either") {
let errorMsg = "The tag type argument must be a value of 'production', 'preview' or 'either'.";
errorMsg += "\nThe value is case-insensitive.";

throw new Error(errorMsg);
}

const projectName: string = Deno.args[2];

const prodVersionRegex = /^v[0-9]+\.[0-9]+\.[0-9]+$/;
const prevVersionRegex = /^v[0-9]+\.[0-9]+\.[0-9]+-preview\.[0-9]+$/;

let tag: string = Deno.args[1];

tag = tag.startsWith("v")
? tag
: `v${tag}`;

let isValid = false;

if (tagType === "production") {
isValid = prodVersionRegex.test(tag);
} else {
isValid = prevVersionRegex.test(tag);
switch (tagType) {
case "production":
isValid = prodVersionRegex.test(tag);
break;
case "preview":
isValid = prevVersionRegex.test(tag);
break;
case "either":
isValid = prodVersionRegex.test(tag) || prevVersionRegex.test(tag);
break;
default:
break;
}

if (isValid === false) {
throw new Error(`The tag is not in the correct ${tagType} version syntax.`);
const tagTypeStr = tagType === "production" || tagType === "preview"
? tagType
: "production or preview";

throw new Error(`The tag is not in the correct ${tagTypeStr} version syntax.`);
}

const tagsUrl = `https://api.github.com/repos/KinsonDigital/${projectName}/tags`;
const response = await fetch(tagsUrl);
const responseData = <{ name: ""}[]>await response.json();
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-status-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
run: |
# If the destination branch that the pull request is merging into is master, do a release build
if ( "${{ github.base_ref }}" -eq "master") {
Write-Host "::set-output name=build-config::Release"
"build-config=Release" >> "$env:GITHUB_OUTPUT";
} else { # Any other branch than master, do a debug build
Write-Host "::set-output name=build-config::Debug"
"build-config=Debug" >> "$env:GITHUB_OUTPUT";
}

- name: Setup .NET SDK
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests-status-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
run: |
# If the destination branch that the pull request is merging into is master, do a release build
if ( "${{ github.base_ref }}" -eq "master") {
Write-Host "::set-output name=build-config::Release"
} else { # Any other branch than master, do a debug build
Write-Host "::set-output name=build-config::Debug"
"build-config=Release" >> "$env:GITHUB_OUTPUT";
} else { # Any other branch than master, do a debug build
"build-config=Debug" >> "$env:GITHUB_OUTPUT";
}

- name: Setup .NET SDK
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/version-notes-status-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: ✅Version and Notes Status Check


defaults:
run:
shell: pwsh


env:
project-name: PackageMonster


on:
workflow_dispatch:
pull_request:
branches: master
paths:
- "**.cs"
- "**.csproj"


jobs:
version_and_notes_status_check:
name: Version and Notes Status Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get Branch Name
id: get-branch-name
run: |
Write-Host "::group::Environment Variables";
Write-Host "GITHUB_REF: ${{ github.ref }}";
Write-Host "GITHUB_HEAD_REF: ${{ github.head_ref }}";
Write-Host "::endgroup::";

$branch = "";

if ("${{ github.ref }}".startsWith("refs/pull/")) {
$branch = "${{ github.head_ref }}";
Write-Host "Pull Request Run Head Branch: $branch";
} else {
$branch = "${{ github.ref }}".Replace("refs/heads/", "");
Write-Host "Manual Run Branch: $branch";
}

"branch-name=$branch" >> "$env:GITHUB_OUTPUT";

- name: Test Step Output
run: Write-Host "Branch Name Output ${{ steps.get-branch-name.outputs.branch-name }}";

- name: Get Version (Manual Run)
id: get-version
uses: KinsonDigital/[email protected]
with: # github action output is 'version'
repo-owner: KinsonDigital
repo-name: ${{ env.project-name }}
repo-token: ${{ secrets.CICD_TOKEN }}
branch-name: "${{ steps.get-branch-name.outputs.branch-name }}"
file-format: xml # Not case sensitive
file-path: "${{ env.project-name }}/${{ env.project-name }}.csproj"
version-keys: Version

- name: Set Up Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Validate Tag
run: |
deno run `
--allow-run `
--allow-net `
"${{ github.workspace }}/.github/cicd/validate-tag.ts" `
"Either" `
"v${{ steps.get-version.outputs.version }}"`
"${{ env.project-name }}";

- name: Validate Release Notes
run: |
deno `
run `
--allow-read `
"${{ github.workspace }}/.github/cicd/validate-notes.ts" `
"Either" `
"v${{ steps.get-version.outputs.version }}";
46 changes: 44 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Validate Tag (DEBUG)",
"name": "Validate Prod Tag (DEBUG)",
"request": "launch",
"type": "node",
"program": "${workspaceFolder}/.github/cicd/validate-tag.ts",
Expand All @@ -15,7 +15,49 @@
"--inspect-wait",
"--allow-all"
],
"args": ["Preview", "1.0.0-preview.1", "PackageMonster"],
"args": ["Production", "v1.2.3", "PackageMonster"],
"attachSimplePort": 9229,
"console": "integratedTerminal",
"windows": {
"runtimeExecutable": "${userHome}\\.deno\\bin\\deno.exe",
},
"linux": {
"runtimeExecutable": "${userHome}/.deno/bin/deno",
},
},
{
"name": "Validate Preview Tag (DEBUG)",
"request": "launch",
"type": "node",
"program": "${workspaceFolder}/.github/cicd/validate-tag.ts",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-all"
],
"args": ["Preview", "v1.2.3-preview.5", "PackageMonster"],
"attachSimplePort": 9229,
"console": "integratedTerminal",
"windows": {
"runtimeExecutable": "${userHome}\\.deno\\bin\\deno.exe",
},
"linux": {
"runtimeExecutable": "${userHome}/.deno/bin/deno",
},
},
{
"name": "Validate Either Tag (DEBUG)",
"request": "launch",
"type": "node",
"program": "${workspaceFolder}/.github/cicd/validate-tag.ts",
"cwd": "${workspaceFolder}",
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-all"
],
"args": ["Either", "v1.2.3", "PackageMonster"],
"attachSimplePort": 9229,
"console": "integratedTerminal",
"windows": {
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"deno.enable": true,
"cSpell.words": [
"cicd"
"cicd",
"endgroup"
]
}