mirror of
https://github.com/tiennm99/is-a-good-dev.git
synced 2026-10-20 02:17:36 +00:00
4 files changed
+16
-9
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
package-lock.json
|
||||||
@@ -23,6 +23,7 @@ beforeAll(() => {
|
|||||||
setupMessages();
|
setupMessages();
|
||||||
if (data == 3) {
|
if (data == 3) {
|
||||||
outputInvalidJsonFile();
|
outputInvalidJsonFile();
|
||||||
|
|
||||||
console.log("ERROR: JSON file is invalid. Either the file is not JSON, or there is an error in the JSON syntax.");
|
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)
|
return process.exit(1)
|
||||||
};
|
};
|
||||||
@@ -52,8 +53,10 @@ test('Check if JSON file follows format', () => {
|
|||||||
|
|
||||||
test('Check if JSON file matches the value name', () => {
|
test('Check if JSON file matches the value name', () => {
|
||||||
const passed = getFileName(process.env.FILES, data);
|
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.";
|
let fileNameMessage = passed === true ? "File name matches target.RECORD_TYPE." : "File name does not match any target.RECORD_TYPE.";
|
||||||
|
|
||||||
core.setOutput('fileNameMessage', fileNameMessage);
|
core.setOutput('fileNameMessage', fileNameMessage);
|
||||||
|
expect(typeof passed).toBe('boolean'); // Check if the result is a boolean
|
||||||
expect(passed).toBe(true);
|
expect(passed).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
const { stripExt } = require('./utils.js');
|
const { stripExt } = require('./utils.js');
|
||||||
|
|
||||||
async function getFileName(file, data) {
|
function getFileName(file, data) {
|
||||||
// Extract the file name without extension
|
|
||||||
const fileNameWithoutExt = stripExt(file);
|
const fileNameWithoutExt = stripExt(file);
|
||||||
|
|
||||||
// Validate if the file name matches any of the target.RECORD_TYPE values
|
// Validate if the file name matches any of the target.RECORD_TYPE values
|
||||||
const recordTypes = Object.keys(data.target);
|
const recordTypes = Object.values(data.target);
|
||||||
if (!recordTypes.includes(fileNameWithoutExt.toUpperCase())) {
|
|
||||||
return false;
|
return recordTypes[0].name == fileNameWithoutExt.toLowerCase();
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getFileName;
|
module.exports = getFileName;
|
||||||
+5
-1
@@ -2,8 +2,10 @@ const fs = require('fs');
|
|||||||
const { getFileExtension, stripExt } = require('./utils.js');
|
const { getFileExtension, stripExt } = require('./utils.js');
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
function getJSON(file, filename) {
|
function getJSON(file) {
|
||||||
|
|
||||||
const path = `${process.env.actions_path}/${file}`; // File path.
|
const path = `${process.env.actions_path}/${file}`; // File path.
|
||||||
|
|
||||||
const ext = getFileExtension(file);
|
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 (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.
|
if (!ext) return false; // If no file extension, return.
|
||||||
@@ -11,6 +13,7 @@ function getJSON(file, filename) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(path)) { // Check if file exists in domain directory
|
if (fs.existsSync(path)) { // Check if file exists in domain directory
|
||||||
|
|
||||||
// It exists
|
// It exists
|
||||||
const rawdata = fs.readFileSync(path); // Read the file
|
const rawdata = fs.readFileSync(path); // Read the file
|
||||||
const data = JSON.parse(rawdata); // Parse it
|
const data = JSON.parse(rawdata); // Parse it
|
||||||
@@ -19,6 +22,7 @@ function getJSON(file, filename) {
|
|||||||
}
|
}
|
||||||
return 3; // It doesn't exist
|
return 3; // It doesn't exist
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
|
||||||
core.setOutput('infoMessage', "Could not validate info.");
|
core.setOutput('infoMessage', "Could not validate info.");
|
||||||
core.setOutput('recordMessage', "Could not validate records.");
|
core.setOutput('recordMessage', "Could not validate records.");
|
||||||
core.setOutput('jsonData', "Could not read the JSON file, did you have an error in your syntax?")
|
core.setOutput('jsonData', "Could not read the JSON file, did you have an error in your syntax?")
|
||||||
|
|||||||
Reference in new issue
Block a user