move directory logging

This commit is contained in:
David Blass
2025-11-06 20:34:35 -05:00
parent c31824144b
commit 6d0c21f0f5
4 changed files with 66 additions and 68 deletions
+36
View File
@@ -4,6 +4,8 @@
* Entry point for GitHub Action
*/
import { readdir } from "node:fs/promises";
import { join } from "node:path";
import * as core from "@actions/core";
import { type Inputs, main } from "./main.ts";
import { createMcpServer } from "./mcp/server.ts";
@@ -12,7 +14,41 @@ import { log } from "./utils/cli.ts";
// Export createMcpServer so it can be called from the spawned MCP process
export { createMcpServer };
async function printDirectoryTree(dir: string, prefix = "", rootDir = dir): Promise<string> {
const entries = await readdir(dir, { withFileTypes: true });
const lines: string[] = [];
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
const isLast = i === entries.length - 1;
const currentPrefix = isLast ? "└── " : "├── ";
const nextPrefix = isLast ? " " : "│ ";
const fullPath = join(dir, entry.name);
lines.push(`${prefix}${currentPrefix}${entry.name}`);
if (entry.isDirectory()) {
const subTree = await printDirectoryTree(fullPath, `${prefix}${nextPrefix}`, rootDir);
lines.push(subTree);
}
}
return lines.join("\n");
}
async function run(): Promise<void> {
// Debug: Print current directory tree before changing directories
const cwd = process.cwd();
log.info(`Current working directory: ${cwd}`);
try {
const tree = await printDirectoryTree(cwd);
log.info(`Directory tree:\n${tree}`);
} catch (error) {
log.warning(
`Failed to print directory tree: ${error instanceof Error ? error.message : String(error)}`
);
}
// Change to GITHUB_WORKSPACE if set (this is where actions/checkout puts the repo)
// JavaScript actions run from the action's directory, not the checked-out repo
if (process.env.GITHUB_WORKSPACE && process.cwd() !== process.env.GITHUB_WORKSPACE) {