diff --git a/.github/workflows/data-validate.yml b/.github/workflows/data-validate.yml new file mode 100644 index 00000000..94a21ac1 --- /dev/null +++ b/.github/workflows/data-validate.yml @@ -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 \ No newline at end of file diff --git a/scripts/data-validate.js b/scripts/data-validate.js new file mode 100644 index 00000000..2588d112 --- /dev/null +++ b/scripts/data-validate.js @@ -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'); +}