mirror of
https://github.com/System-End/YSWS-Catalog.git
synced 2026-04-19 14:27:00 +00:00
Add date validation and install dependencies in workflow
This commit is contained in:
parent
787097961d
commit
db091851a3
3 changed files with 48 additions and 1 deletions
8
.github/workflows/validate.yml
vendored
8
.github/workflows/validate.yml
vendored
|
|
@ -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"
|
||||
comment: "true"
|
||||
|
||||
- name: Validate Dates in data.yml
|
||||
run: node validateDates.js
|
||||
7
package.json
Normal file
7
package.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "gowno",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"js-yaml": "^4.1.0"
|
||||
}
|
||||
}
|
||||
34
validateDates.js
Normal file
34
validateDates.js
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue