diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..737bc52 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +package-lock.json \ No newline at end of file diff --git a/tests/json.test.js b/tests/json.test.js index 5533900..10bfd1d 100644 --- a/tests/json.test.js +++ b/tests/json.test.js @@ -23,6 +23,7 @@ beforeAll(() => { setupMessages(); if (data == 3) { outputInvalidJsonFile(); + console.log("ERROR: JSON file is invalid. Either the file is not JSON, or there is an error in the JSON syntax."); return process.exit(1) }; @@ -52,8 +53,10 @@ test('Check if JSON file follows format', () => { test('Check if JSON file matches the value name', () => { const passed = getFileName(process.env.FILES, data); + let fileNameMessage = passed === true ? "File name matches target.RECORD_TYPE." : "File name does not match any target.RECORD_TYPE."; core.setOutput('fileNameMessage', fileNameMessage); + expect(typeof passed).toBe('boolean'); // Check if the result is a boolean expect(passed).toBe(true); }); diff --git a/utils/getFileName.js b/utils/getFileName.js index a866ab0..9bf698a 100644 --- a/utils/getFileName.js +++ b/utils/getFileName.js @@ -1,16 +1,13 @@ const { stripExt } = require('./utils.js'); -async function getFileName(file, data) { - // Extract the file name without extension +function getFileName(file, data) { + const fileNameWithoutExt = stripExt(file); // Validate if the file name matches any of the target.RECORD_TYPE values - const recordTypes = Object.keys(data.target); - if (!recordTypes.includes(fileNameWithoutExt.toUpperCase())) { - return false; - } else { - return true; - } + const recordTypes = Object.values(data.target); + + return recordTypes[0].name == fileNameWithoutExt.toLowerCase(); } -module.exports = getFileName; +module.exports = getFileName; \ No newline at end of file diff --git a/utils/getJSON.js b/utils/getJSON.js index e1fec48..077e3fc 100644 --- a/utils/getJSON.js +++ b/utils/getJSON.js @@ -2,8 +2,10 @@ const fs = require('fs'); const { getFileExtension, stripExt } = require('./utils.js'); const core = require('@actions/core'); -function getJSON(file, filename) { +function getJSON(file) { + const path = `${process.env.actions_path}/${file}`; // File path. + const ext = getFileExtension(file); if (path.includes("sub-logs") && !ext || ext != 'json') return 3 //if file is subdomain file but has no ext or diff ext than .json if (!ext) return false; // If no file extension, return. @@ -11,6 +13,7 @@ function getJSON(file, filename) { try { if (fs.existsSync(path)) { // Check if file exists in domain directory + // It exists const rawdata = fs.readFileSync(path); // Read the file const data = JSON.parse(rawdata); // Parse it @@ -19,6 +22,7 @@ function getJSON(file, filename) { } return 3; // It doesn't exist } catch(err) { + core.setOutput('infoMessage', "Could not validate info."); core.setOutput('recordMessage', "Could not validate records."); core.setOutput('jsonData', "Could not read the JSON file, did you have an error in your syntax?")