diff --git a/.gitignore b/.gitignore index ec903c1..d34d1e5 100644 --- a/.gitignore +++ b/.gitignore @@ -102,4 +102,6 @@ __tests__/runner/* *.code-workspace # TS Docs -docs \ No newline at end of file +docs + +.vscode \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 481d145..5b5b6d2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { testing } from "./scripts/testing"; import { comment } from "./scripts/comment"; import { cwd, chdir } from "process"; // import { coverage } from './scripts/coverage' -// import minimist from "minimist"; +import minimist from "minimist"; export type stepResponse = { output: string; error: boolean }; export const failedEmoji = "❌"; @@ -18,8 +18,10 @@ export const passedEmoji = "✅"; * @returns {Promise} Resolves when the action is complete. */ export async function run(): Promise { - // const argv = minimist(process.argv); - // console.log("ARGV MINIMIST!!!", argv); + const argv = minimist(process.argv.slice(2)); + + const isLocal = + argv._.findLast((x: string) => x == "--local") == "--local" ? true : false; try { await exec("npm ci"); @@ -30,13 +32,12 @@ export async function run(): Promise { try { const workingDirectory = getInput("working-directory"); // Check if the working directory is different from the current directory - // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access const currentDirectory = cwd(); if (workingDirectory && workingDirectory !== currentDirectory) { chdir(workingDirectory); } - const isLocal = true; + // get token and octokit let token = ""; if (process.env.GITHUB_TOKEN && isLocal) { token = process.env.GITHUB_TOKEN; @@ -44,31 +45,39 @@ export async function run(): Promise { token = getInput("token"); } const octokit = getOctokit(token); - const runStaticAnalysis: boolean = isLocal + + // get static analysis input + const doStaticAnalysis: boolean = isLocal ? true : getBooleanInput("run-static-analysis"); - const runCodeFormatting: boolean = isLocal + + // get code formatting input + const doCodeFormatting: boolean = isLocal ? true : getBooleanInput("run-code-formatting"); - const runTests: boolean = isLocal ? true : getBooleanInput("run-tests"); + + // get tests input + const doTests: boolean = isLocal ? true : getBooleanInput("run-tests"); + // const runCoverage: boolean = getBooleanInput('run-coverage'); // const coveragePassScore: string = getInput('coverage-pass-score'); + const createComment: boolean = isLocal ? true : getBooleanInput("create-comment"); - // runStaticAnalysis - const analyzeStr: stepResponse | undefined = runStaticAnalysis + // run Static Analysis + const analyzeStr: stepResponse | undefined = doStaticAnalysis ? await analyze() : undefined; - // runCodeFormatting - const runCodeFormattingStr: stepResponse | undefined = runCodeFormatting + // run Code Formatting + const codeFormattingStr: stepResponse | undefined = doCodeFormatting ? await formatting() : undefined; - // runTests - const testingStr: stepResponse | undefined = runTests + // run Tests + const testingStr: stepResponse | undefined = doTests ? await testing() : undefined; @@ -83,7 +92,7 @@ export async function run(): Promise { octokit, context, analyzeStr, - runCodeFormattingStr, + codeFormattingStr, testingStr, ); } diff --git a/src/scripts/comment.ts b/src/scripts/comment.ts index 33f1e09..70b79f3 100644 --- a/src/scripts/comment.ts +++ b/src/scripts/comment.ts @@ -7,14 +7,14 @@ export const comment = async ( ocotokit: ReturnType, context: Context, analyzeStr: stepResponse | undefined, - runCodeFormattingStr: stepResponse | undefined, + codeFormattingStr: stepResponse | undefined, testingStr: stepResponse | undefined, ): Promise => { try { const commentBody = ` ## PR Checks Complete\n ${analyzeStr?.output}\n - ${runCodeFormattingStr?.output}\n + ${codeFormattingStr?.output}\n ${testingStr?.output}\n`; // ## Coverage = ${coverageStr?.output}\n` diff --git a/src/scripts/formatting.ts b/src/scripts/formatting.ts index 343384a..89d0150 100644 --- a/src/scripts/formatting.ts +++ b/src/scripts/formatting.ts @@ -1,15 +1,15 @@ import { exec } from "@actions/exec"; import { setFailed } from "@actions/core"; -import { stepResponse } from "src/main"; +import { stepResponse, failedEmoji, passedEmoji } from "src/main"; export const formatting = async (): Promise => { try { // Run prettier await exec("npm run prettier"); - return { output: "Formatting complete", error: false }; + return { output: `${passedEmoji} - Formatting`, error: false }; } catch (error) { if (error instanceof Error) setFailed(error.message); - return { output: "Formatting failed", error: true }; + return { output: `${failedEmoji} - Formatting`, error: true }; } };