mirror of
https://github.com/tiennm99/is-a-good-dev.git
synced 2026-07-28 18:21:39 +00:00
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
package-lock.json
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
+5
-1
@@ -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?")
|
||||
|
||||
Reference in New Issue
Block a user