Skip to content

Commit

Permalink
Print working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Feb 23, 2024
1 parent e5e4853 commit 8c5d172
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"]
});
Expand All @@ -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"],
Expand Down
40 changes: 32 additions & 8 deletions src/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
]
`;
Expand Down Expand Up @@ -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",
],
]
`;
Expand Down Expand Up @@ -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",
],
]
`;
Expand Down Expand Up @@ -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",
],
]
`;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
],
]
`;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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(() => {
Expand Down
9 changes: 5 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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",
Expand Down

0 comments on commit 8c5d172

Please sign in to comment.