Skip to content

Commit

Permalink
update .gitignore and refactor main.ts to improve argument parsing an…
Browse files Browse the repository at this point in the history
…d output formatting
  • Loading branch information
DE7924 committed Dec 12, 2024
1 parent c2869a3 commit 0a07525
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ __tests__/runner/*
*.code-workspace

# TS Docs
docs
docs

.vscode
39 changes: 24 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "❌";
Expand All @@ -18,8 +18,10 @@ export const passedEmoji = "✅";
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
// 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");
Expand All @@ -30,45 +32,52 @@ export async function run(): Promise<void> {
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;
} else {
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;

Expand All @@ -83,7 +92,7 @@ export async function run(): Promise<void> {
octokit,
context,
analyzeStr,
runCodeFormattingStr,
codeFormattingStr,
testingStr,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export const comment = async (
ocotokit: ReturnType<typeof getOctokit>,
context: Context,
analyzeStr: stepResponse | undefined,
runCodeFormattingStr: stepResponse | undefined,
codeFormattingStr: stepResponse | undefined,
testingStr: stepResponse | undefined,
): Promise<stepResponse> => {
try {
const commentBody = `
## PR Checks Complete\n
${analyzeStr?.output}\n
${runCodeFormattingStr?.output}\n
${codeFormattingStr?.output}\n
${testingStr?.output}\n`;
// ## Coverage = ${coverageStr?.output}\n`

Expand Down
6 changes: 3 additions & 3 deletions src/scripts/formatting.ts
Original file line number Diff line number Diff line change
@@ -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<stepResponse> => {
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 };
}
};

0 comments on commit 0a07525

Please sign in to comment.