diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 257c9fd..ed79c9b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -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" \ No newline at end of file + comment: "true" + + - name: Validate Dates in data.yml + run: node validateDates.js \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..a818c5f --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "name": "gowno", + "version": "1.0.0", + "dependencies": { + "js-yaml": "^4.1.0" + } +} diff --git a/validateDates.js b/validateDates.js new file mode 100644 index 0000000..d5499c3 --- /dev/null +++ b/validateDates.js @@ -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); +}