Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions actions/setup/js/file_helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
const fs = require("fs");
const path = require("path");
const { getErrorMessage } = require("./error_helpers.cjs");
const { safeJoin } = require("./path_helpers.cjs");

/**
* List all files recursively in a directory
Expand All @@ -22,21 +23,41 @@ const { getErrorMessage } = require("./error_helpers.cjs");
function listFilesRecursively(dirPath, relativeTo) {
const files = [];
try {
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Listing files in: ${dirPath}`);
}
if (!fs.existsSync(dirPath)) {
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Directory does not exist: ${dirPath}`);
}
return files;
}
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Found ${entries.length} entries in ${dirPath}`);
}
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
const fullPath = safeJoin(dirPath, entry.name);
if (entry.isDirectory()) {
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Recursing into directory: ${entry.name}`);
}
files.push(...listFilesRecursively(fullPath, relativeTo));
} else {
const displayPath = relativeTo ? path.relative(relativeTo, fullPath) : fullPath;
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Found file: ${displayPath}`);
}
files.push(displayPath);
}
}
if (typeof core !== "undefined") {
core.info(`[listFilesRecursively] Total files found: ${files.length}`);
}
} catch (error) {
core.warning("Failed to list files in " + dirPath + ": " + getErrorMessage(error));
if (typeof core !== "undefined") {
core.warning("Failed to list files in " + dirPath + ": " + getErrorMessage(error));
}
}
return files;
}
Expand All @@ -50,32 +71,51 @@ function listFilesRecursively(dirPath, relativeTo) {
* @returns {boolean} True if file exists (or not required), false otherwise
*/
function checkFileExists(filePath, artifactDir, fileDescription, required) {
if (typeof core !== "undefined") {
core.info(`[checkFileExists] Checking ${fileDescription}: ${filePath}`);
core.info(`[checkFileExists] Required: ${required}`);
}

if (fs.existsSync(filePath)) {
try {
const stats = fs.statSync(filePath);
const fileInfo = filePath + " (" + stats.size + " bytes)";
core.info(fileDescription + " found: " + fileInfo);
if (typeof core !== "undefined") {
core.info(`[checkFileExists] ✓ ${fileDescription} found: ${fileInfo}`);
core.info(fileDescription + " found: " + fileInfo);
}
return true;
} catch (error) {
core.warning("Failed to stat " + fileDescription.toLowerCase() + ": " + getErrorMessage(error));
if (typeof core !== "undefined") {
core.warning("Failed to stat " + fileDescription.toLowerCase() + ": " + getErrorMessage(error));
}
return false;
}
} else {
if (required) {
core.error("❌ " + fileDescription + " not found at: " + filePath);
// List all files in artifact directory for debugging
core.info("📁 Listing all files in artifact directory: " + artifactDir);
if (typeof core !== "undefined") {
core.warning(`[checkFileExists] ❌ ${fileDescription} not found at: ${filePath}`);
core.warning("❌ " + fileDescription + " not found at: " + filePath);
// List all files in artifact directory for debugging
core.info(`[checkFileExists] Listing artifact directory for debugging: ${artifactDir}`);
core.info("📁 Listing all files in artifact directory: " + artifactDir);
}
const files = listFilesRecursively(artifactDir, artifactDir);
if (files.length === 0) {
core.warning(" No files found in " + artifactDir);
} else {
core.info(" Found " + files.length + " file(s):");
files.forEach(file => core.info(" - " + file));
if (typeof core !== "undefined") {
if (files.length === 0) {
core.warning(" No files found in " + artifactDir);
} else {
core.info(" Found " + files.length + " file(s):");
files.forEach(file => core.info(" - " + file));
}
core.setFailed("❌ " + fileDescription + " not found at: " + filePath);
}
core.setFailed("❌ " + fileDescription + " not found at: " + filePath);
return false;
} else {
core.info("No " + fileDescription.toLowerCase() + " found at: " + filePath);
if (typeof core !== "undefined") {
core.info(`[checkFileExists] No ${fileDescription.toLowerCase()} found at: ${filePath} (optional)`);
core.info("No " + fileDescription.toLowerCase() + " found at: " + filePath);
}
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion actions/setup/js/file_helpers.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe("checkFileExists", () => {

const result = checkFileExists(filePath, tempDir, "Test file", true);
expect(result).toBe(false);
expect(mockCore.errorCalls.some(msg => msg.includes("Test file not found"))).toBe(true);
expect(mockCore.warningCalls.some(msg => msg.includes("Test file not found"))).toBe(true);
expect(mockCore.setFailedCalls).toHaveLength(1);
});

Expand Down
4 changes: 4 additions & 0 deletions actions/setup/js/fuzz_template_substitution_harness.test.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @ts-check
const { testTemplateSubstitution, testValueState } = require("./fuzz_template_substitution_harness.cjs");

// Mock the global core object
const core = { info: vi.fn(), warning: vi.fn(), setFailed: vi.fn() };
global.core = core;

describe("fuzz_template_substitution_harness", () => {
describe("testValueState", () => {
it("should handle undefined values correctly", async () => {
Expand Down
Loading
Loading