awesome-uses/scripts/data-validate.js
Andrew Luca 86b6b5d6d3
feat: change validate action to take into consideration only add… (#422)
`node scripts/data-valdiate.js` cand also be run locally

This also will fix the issue when some valid URL returned timeout
Because the action wanted to make all requests at the same time

`git restore` is available only from Git 2.23

https://github.blog/2019-08-16-highlights-from-git-2-23/#experimental-alternatives-for-git-checkout

Closes #382
2020-01-18 15:27:15 +02:00

42 lines
1.2 KiB
JavaScript

import core from '@actions/core';
import { getMasterData, Schema, getStatusCode } from './utils.js';
import srcData from '../src/data.js';
(async () => {
// on master branch will be empty array
const masterDataUrls = (await getMasterData()).map(d => d.url);
// so here data will be an array with all users
const data = srcData.filter(d => !masterDataUrls.includes(d.url));
const errors = data
.map(person => Schema.validate(person))
.filter(v => v.error)
.map(v => v.error);
errors.forEach(e => {
core.error(e._original.name || e._original.url);
e.details.forEach(d => core.error(d.message));
});
let failedUrlsCount = 0;
for await (const { url } of data) {
try {
const statusCode = await getStatusCode(url);
if (statusCode < 200 || statusCode >= 400) {
core.error(`Ping to "${url}" failed with status: ${statusCode}`);
failedUrlsCount += 1;
}
} catch (e) {
core.error(`Ping to "${url}" failed with error: ${e}`);
failedUrlsCount += 1;
}
}
if (failedUrlsCount) {
core.error(`Action failed with ${failedUrlsCount} URL fetch failures`);
}
if (errors.length || failedUrlsCount) {
core.setFailed('Action failed with errors, see logs');
}
})();