From 7909d63850299774cf855edf11095923f3d154ff Mon Sep 17 00:00:00 2001 From: Grant Birkinbine Date: Fri, 23 Aug 2024 21:33:42 -0700 Subject: [PATCH] Fix file validation in action summary Fixes #70 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/GrantBirki/json-yaml-validate/issues/70?shareId=XXXX-XXXX-XXXX-XXXX). --- src/functions/json-validator.js | 12 ++++++++++++ src/functions/yaml-validator.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/functions/json-validator.js b/src/functions/json-validator.js index 6d74cca..d444cb6 100644 --- a/src/functions/json-validator.js +++ b/src/functions/json-validator.js @@ -149,6 +149,9 @@ export async function jsonValidator(exclude) { .withPromise() } + // Create a Set to track processed files + const processedFiles = new Set() + for (const fullPath of files) { core.debug(`found file: ${fullPath}`) @@ -188,6 +191,12 @@ export async function jsonValidator(exclude) { continue } + // Check if the file has already been processed + if (processedFiles.has(fullPath)) { + core.debug(`skipping duplicate file: ${fullPath}`) + continue + } + var data try { // if the file is a yaml file but being treated as json and yamlAsJson is true @@ -250,6 +259,9 @@ export async function jsonValidator(exclude) { continue } + // Add the file to the processedFiles Set + processedFiles.add(fullPath) + result.passed++ core.info(`${fullPath} is valid`) } diff --git a/src/functions/yaml-validator.js b/src/functions/yaml-validator.js index 2363470..b64e34b 100644 --- a/src/functions/yaml-validator.js +++ b/src/functions/yaml-validator.js @@ -62,6 +62,9 @@ export async function yamlValidator(exclude) { .withPromise() } + // Create a Set to track processed files + const processedFiles = new Set() + for (const fullPath of files) { core.debug(`found file: ${fullPath}`) @@ -93,6 +96,12 @@ export async function yamlValidator(exclude) { continue } + // Check if the file has already been processed + if (processedFiles.has(fullPath)) { + core.debug(`skipping duplicate file: ${fullPath}`) + continue + } + let multipleDocuments = false try { @@ -176,6 +185,9 @@ export async function yamlValidator(exclude) { continue } + // Add the file to the processedFiles Set + processedFiles.add(fullPath) + result.passed++ core.info(`${fullPath} is valid`) }