mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
Merge pull request #279 from iamandrewluca/validate-data
feat: add action to validate data.js
This commit is contained in:
commit
52e9c7f3f9
2 changed files with 56 additions and 0 deletions
25
.github/workflows/data-validate.yml
vendored
Normal file
25
.github/workflows/data-validate.yml
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
name: Validate data.js
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths: src/data.js
|
||||
|
||||
env:
|
||||
CI: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 13.x
|
||||
- name: Install validation libs
|
||||
run: |
|
||||
npm install -g @hapi/joi@17.0.2
|
||||
npm install -g @actions/core@1.2.0
|
||||
npm link @hapi/joi
|
||||
npm link @actions/core
|
||||
- name: Validate data.js
|
||||
run: node ./scripts/data-validate.js
|
||||
31
scripts/data-validate.js
Normal file
31
scripts/data-validate.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import Joi from '@hapi/joi';
|
||||
import core from '@actions/core';
|
||||
import data from '../src/data.js';
|
||||
|
||||
const schema = Joi.object({
|
||||
name: Joi.string().required(),
|
||||
description: Joi.string().required(),
|
||||
url: Joi.string()
|
||||
.uri()
|
||||
.required(),
|
||||
country: Joi.string().required(),
|
||||
twitter: Joi.string(),
|
||||
emoji: Joi.string(),
|
||||
computer: Joi.string().valid('apple', 'windows', 'linux'),
|
||||
phone: Joi.string().valid('iphone', 'ios', 'android'),
|
||||
tags: Joi.array().items(Joi.string()),
|
||||
});
|
||||
|
||||
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.details.forEach(d => core.error(d.message));
|
||||
});
|
||||
|
||||
if (errors.length) {
|
||||
core.setFailed('Action failed with validation errors, see logs');
|
||||
}
|
||||
Loading…
Reference in a new issue