Add date validation and install dependencies in workflow

This commit is contained in:
PawiX25 2025-02-23 22:58:09 +01:00
parent 787097961d
commit db091851a3
3 changed files with 48 additions and 1 deletions

View file

@ -16,8 +16,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: npm install
- name: json-yaml-validate
id: json-yaml-validate
uses: GrantBirki/json-yaml-validate@v3.2.1
with:
comment: "true"
- name: Validate Dates in data.yml
run: node validateDates.js

7
package.json Normal file
View file

@ -0,0 +1,7 @@
{
"name": "gowno",
"version": "1.0.0",
"dependencies": {
"js-yaml": "^4.1.0"
}
}

34
validateDates.js Normal file
View file

@ -0,0 +1,34 @@
const fs = require('fs');
const jsyaml = require('js-yaml');
function isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime());
}
try {
const fileContent = fs.readFileSync('data.yml', 'utf8');
const data = jsyaml.load(fileContent);
let invalidDates = [];
for (let category in data) {
if (Array.isArray(data[category])) {
data[category].forEach(program => {
if (program.deadline) {
const d = new Date(program.deadline);
if (!isValidDate(d)) {
invalidDates.push({ name: program.name, deadline: program.deadline });
}
}
});
}
}
if (invalidDates.length) {
console.warn('Found invalid dates in data.yml:');
console.warn(invalidDates);
process.exit(1);
} else {
console.log('All dates are valid.');
}
} catch (err) {
console.error(err);
process.exit(1);
}