From 8c5d172ac8d69cb977e6459d8d01260ad9137826 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 23 Feb 2024 15:15:57 -0800 Subject: [PATCH] Print working directory --- dist/index.js | 9 ++++--- src/__snapshots__/main.test.ts.snap | 40 +++++++++++++++++++++++------ src/main.test.ts | 8 +++++- src/main.ts | 9 ++++--- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/dist/index.js b/dist/index.js index 083a04c..5dd94d8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7162,9 +7162,10 @@ async function getPylancePyrightVersion(pylanceVersion) { } // src/main.ts -function printInfo(pyrightVersion, node, args) { +function printInfo(pyrightVersion, node, cwd, args) { core2.info(`pyright ${pyrightVersion}, node ${node.version}, pyright-action ${getActionVersion()}`); - core2.info(`${node.execPath} ${(0, import_shell_quote2.quote)(args)}`); + core2.info(`Working directory: ${cwd}`); + core2.info(`Running: ${node.execPath} ${(0, import_shell_quote2.quote)(args)}`); } async function main() { try { @@ -7174,7 +7175,7 @@ async function main() { process.chdir(workingDirectory); } if (noComments) { - printInfo(pyrightVersion, node, args); + printInfo(pyrightVersion, node, process.cwd(), args); const { status: status2 } = cp.spawnSync(node.execPath, args, { stdio: ["ignore", "inherit", "inherit"] }); @@ -7187,7 +7188,7 @@ async function main() { if (!updatedArgs.includes("--outputjson")) { updatedArgs.push("--outputjson"); } - printInfo(pyrightVersion, node, updatedArgs); + printInfo(pyrightVersion, node, process.cwd(), updatedArgs); const { status, stdout } = cp.spawnSync(node.execPath, updatedArgs, { encoding: "utf8", stdio: ["ignore", "pipe", "inherit"], diff --git a/src/__snapshots__/main.test.ts.snap b/src/__snapshots__/main.test.ts.snap index 445629a..587ae47 100644 --- a/src/__snapshots__/main.test.ts.snap +++ b/src/__snapshots__/main.test.ts.snap @@ -8,7 +8,10 @@ exports[`no comments > failure > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], ] `; @@ -56,7 +59,10 @@ exports[`no comments > success > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], ] `; @@ -114,7 +120,10 @@ exports[`with comments > failure > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], ] `; @@ -158,7 +167,10 @@ exports[`with comments > invalid stdout > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], ] `; @@ -202,7 +214,10 @@ exports[`with comments > no diagnostics > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], [ "0 errors, 0 warnings, 0 informations", @@ -243,7 +258,10 @@ exports[`with comments > unparsable json > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], ] `; @@ -308,7 +326,10 @@ exports[`with comments > with 1 each > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], [ "/path/to/file1.py:1:1 - error: some error", @@ -403,7 +424,10 @@ exports[`with comments > with diagnostics > core.info 1`] = ` "pyright 1.1.240, node v20.8.1, pyright-action 1.1.0", ], [ - "/path/to/node /path/to/pyright/dist/index.js --outputjson", + "Working directory: /some/wd", + ], + [ + "Running: /path/to/node /path/to/pyright/dist/index.js --outputjson", ], [ "/path/to/file1.py:1:1 - error: some error", diff --git a/src/main.test.ts b/src/main.test.ts index c30495a..4e91154 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -22,6 +22,9 @@ vitest.mock("./helpers"); const mockedHelpers = vitest.mocked(helpers); const mockedProcessChdir = vitest.spyOn(process, "chdir"); +const mockedProcessCwd = vitest.spyOn(process, "cwd"); + +let currentWorkingDirectory = "/some/default/cwd"; import { main } from "./main"; import type { Report } from "./schema"; @@ -33,7 +36,10 @@ beforeEach(() => { execPath: nodeExecPath, }); mockedHelpers.getActionVersion.mockReturnValue("1.1.0"); - mockedProcessChdir.mockReturnValue(undefined); // This is a spy mock; prevent real process from being called. + mockedProcessChdir.mockImplementation((dir) => { + currentWorkingDirectory = dir; + }); + mockedProcessCwd.mockImplementation(() => currentWorkingDirectory); }); afterEach(() => { diff --git a/src/main.ts b/src/main.ts index 6a9b800..2ba1252 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,9 +8,10 @@ import { quote } from "shell-quote"; import { getActionVersion, getArgs, getNodeInfo, type NodeInfo } from "./helpers"; import { type Diagnostic, isEmptyRange, parseReport } from "./schema"; -function printInfo(pyrightVersion: string, node: NodeInfo, args: string[]) { +function printInfo(pyrightVersion: string, node: NodeInfo, cwd: string, args: string[]) { core.info(`pyright ${pyrightVersion}, node ${node.version}, pyright-action ${getActionVersion()}`); - core.info(`${node.execPath} ${quote(args)}`); + core.info(`Working directory: ${cwd}`); + core.info(`Running: ${node.execPath} ${quote(args)}`); } export async function main() { @@ -22,7 +23,7 @@ export async function main() { } if (noComments) { - printInfo(pyrightVersion, node, args); + printInfo(pyrightVersion, node, process.cwd(), args); // If comments are disabled, there's no point in directly processing the output, // as it's only used for comments. // If we're running the type verifier, there's no guarantee that we can even act @@ -44,7 +45,7 @@ export async function main() { updatedArgs.push("--outputjson"); } - printInfo(pyrightVersion, node, updatedArgs); + printInfo(pyrightVersion, node, process.cwd(), updatedArgs); const { status, stdout } = cp.spawnSync(node.execPath, updatedArgs, { encoding: "utf8",