-
Notifications
You must be signed in to change notification settings - Fork 420
Add debug-scoped /tmp/gh-aw file inventory to setup post cleanup
#38780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,75 @@ const path = require("path"); | |
| const { spawnSync } = require("child_process"); | ||
| const fs = require("fs"); | ||
|
|
||
| function isDebugModeEnabled() { | ||
| const toBool = (value) => { | ||
| const normalized = String(value || "").toLowerCase(); | ||
| return normalized === "1" || normalized === "true"; | ||
| }; | ||
| return toBool(process.env.RUNNER_DEBUG) || toBool(process.env.ACTIONS_STEP_DEBUG); | ||
| } | ||
|
|
||
| function listTmpGhAwFiles(tmpDir, maxDepth, maxFiles) { | ||
| if (!fs.existsSync(tmpDir)) { | ||
| console.log(`[debug] ${tmpDir} does not exist; skipping file listing`); | ||
| return; | ||
| } | ||
|
|
||
| const files = []; | ||
| let readErrors = 0; | ||
|
|
||
| const walk = (currentDir, depth) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/diagnose] The truncation signal only fires when 💡 Suggested fixTrack whether any directory was skipped due to depth, and emit a companion signal: const walk = (currentDir, depth) => {
if (depth >= maxDepth) {
depthCapped = true; // new flag
return;
}
if (files.length >= maxFiles) {
return;
}
// ...
};Then after the walk: if (depthCapped) {
console.log(`[debug] some subdirectories beyond depth ${maxDepth} were not listed`);
}This keeps the two truncation reasons distinct and both observable. |
||
| if (depth >= maxDepth || files.length >= maxFiles) { | ||
| return; | ||
|
Comment on lines
+33
to
+35
|
||
| } | ||
|
|
||
| let entries; | ||
| try { | ||
| entries = fs.readdirSync(currentDir, { withFileTypes: true }); | ||
| } catch (err) { | ||
| readErrors += 1; | ||
| console.log(`[debug] failed to read ${currentDir}: ${err.message}`); | ||
| return; | ||
| } | ||
|
|
||
| entries.sort((a, b) => a.name.localeCompare(b.name)); | ||
|
|
||
|
|
||
| for (const entry of entries) { | ||
| if (files.length >= maxFiles) { | ||
| return; | ||
| } | ||
|
|
||
| const fullPath = path.join(currentDir, entry.name); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/zoom-out] DFS-first traversal means the 200-file limit can be exhausted entirely inside a deep subdirectory, silently omitting all sibling files at shallower levels. For a debug inventory whose purpose is to show what was left before cleanup, breadth-first (or listing files before recursing) would give a more representative snapshot. 💡 Files-before-dirs alternativeA minimal change: process file entries in the current directory before recursing into subdirs. // separate dirs and files
const dirs = entries.filter(e => e.isDirectory());
const fileEntries = entries.filter(e => !e.isDirectory());
for (const entry of fileEntries) {
if (files.length >= maxFiles) return;
files.push(path.relative(tmpDir, path.join(currentDir, entry.name)));
}
for (const dir of dirs) {
if (files.length >= maxFiles) return;
walk(path.join(currentDir, dir.name), depth + 1);
}This ensures the root-level (most actionable) files always appear, regardless of how many nested files exist. |
||
| if (entry.isDirectory()) { | ||
| walk(fullPath, depth + 1); | ||
| continue; | ||
| } | ||
|
|
||
| files.push(path.relative(tmpDir, fullPath) || "."); | ||
| } | ||
| }; | ||
|
|
||
| walk(tmpDir, 0); | ||
|
|
||
| const truncated = files.length >= maxFiles; | ||
| console.log( | ||
| `[debug] listing files under ${tmpDir} (max depth ${maxDepth}, max files ${maxFiles})`, | ||
| ); | ||
| if (files.length === 0) { | ||
| console.log("[debug] no files found"); | ||
| } else { | ||
| for (const file of files) { | ||
| console.log(`[debug] - ${file}`); | ||
| } | ||
| } | ||
| if (truncated) { | ||
| console.log(`[debug] output truncated at ${maxFiles} files`); | ||
| } | ||
| if (readErrors > 0) { | ||
| console.log(`[debug] encountered ${readErrors} directory read error(s)`); | ||
| } | ||
| } | ||
|
|
||
| // Wrap everything in an async IIFE so that the OTLP span is fully sent before | ||
| // the cleanup deletes /tmp/gh-aw/ (which contains aw_info.json and otel.jsonl). | ||
| (async () => { | ||
|
|
@@ -28,6 +97,12 @@ const fs = require("fs"); | |
| } | ||
|
|
||
| const tmpDir = "/tmp/gh-aw"; | ||
| const maxDebugDepth = 4; | ||
| const maxDebugFiles = 200; | ||
|
|
||
| if (isDebugModeEnabled()) { | ||
| listTmpGhAwFiles(tmpDir, maxDebugDepth, maxDebugFiles); | ||
| } | ||
|
|
||
| console.log(`Cleaning up ${tmpDir}...`); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd]
listTmpGhAwFiles(andisDebugModeEnabled) have no unit tests — edge-case bugs here will surface as silent debug-output gaps rather than test failures.💡 Key cases to cover
tmpDirdoes not existreadErrorscounter pathmaxFilesentriesmaxDepth = 0RUNNER_DEBUG=1vsRUNNER_DEBUG=trueBecause the functions are not exported they would need a light refactor (e.g.
module.exports = { listTmpGhAwFiles, isDebugModeEnabled }behind a test guard, or extract into adebug-inventory.jsmodule) before a test file can import them.