mirror of
https://github.com/brittonhayes/validate-yaml.git
synced 2024-11-23 05:30:56 -05:00
fix: migrating to yaml validation action
This commit is contained in:
parent
ddb023fb9d
commit
a3414cb702
20 changed files with 3995 additions and 6467 deletions
|
@ -1,6 +1,11 @@
|
||||||
{
|
{
|
||||||
"plugins": ["jest", "@typescript-eslint"],
|
"plugins": [
|
||||||
"extends": ["plugin:github/recommended"],
|
"jest",
|
||||||
|
"@typescript-eslint"
|
||||||
|
],
|
||||||
|
"extends": [
|
||||||
|
"plugin:github/recommended"
|
||||||
|
],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 9,
|
"ecmaVersion": 9,
|
||||||
|
@ -12,18 +17,31 @@
|
||||||
"import/no-namespace": "off",
|
"import/no-namespace": "off",
|
||||||
"no-unused-vars": "off",
|
"no-unused-vars": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
"@typescript-eslint/explicit-member-accessibility": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"accessibility": "no-public"
|
||||||
|
}
|
||||||
|
],
|
||||||
"@typescript-eslint/no-require-imports": "error",
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
"@typescript-eslint/array-type": "error",
|
"@typescript-eslint/array-type": "error",
|
||||||
"@typescript-eslint/await-thenable": "error",
|
"@typescript-eslint/await-thenable": "error",
|
||||||
"@typescript-eslint/ban-ts-comment": "error",
|
"@typescript-eslint/ban-ts-comment": "error",
|
||||||
"camelcase": "off",
|
"camelcase": "off",
|
||||||
"@typescript-eslint/consistent-type-assertions": "error",
|
"@typescript-eslint/consistent-type-assertions": "error",
|
||||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
"@typescript-eslint/explicit-function-return-type": [
|
||||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
"error",
|
||||||
|
{
|
||||||
|
"allowExpressions": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/func-call-spacing": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
"@typescript-eslint/no-array-constructor": "error",
|
"@typescript-eslint/no-array-constructor": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
"@typescript-eslint/no-extraneous-class": "error",
|
"@typescript-eslint/no-extraneous-class": "error",
|
||||||
"@typescript-eslint/no-for-in-array": "error",
|
"@typescript-eslint/no-for-in-array": "error",
|
||||||
"@typescript-eslint/no-inferrable-types": "error",
|
"@typescript-eslint/no-inferrable-types": "error",
|
||||||
|
@ -42,9 +60,13 @@
|
||||||
"@typescript-eslint/require-array-sort-compare": "error",
|
"@typescript-eslint/require-array-sort-compare": "error",
|
||||||
"@typescript-eslint/restrict-plus-operands": "error",
|
"@typescript-eslint/restrict-plus-operands": "error",
|
||||||
"semi": "off",
|
"semi": "off",
|
||||||
"@typescript-eslint/semi": ["error", "never"],
|
"@typescript-eslint/semi": [
|
||||||
|
"error",
|
||||||
|
"never"
|
||||||
|
],
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
"@typescript-eslint/type-annotation-spacing": "error",
|
||||||
"@typescript-eslint/unbound-method": "error"
|
"@typescript-eslint/unbound-method": "error",
|
||||||
|
"i18n-text/no-en": "off"
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +1,2 @@
|
||||||
dist/** -diff linguist-generated=true
|
dist/** -diff linguist-generated=true
|
||||||
|
*.js linguist-vendored=true
|
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
|
@ -1,9 +1,9 @@
|
||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
# Enable version updates for npm
|
# Enable version updates for npm
|
||||||
- package-ecosystem: 'npm'
|
- package-ecosystem: "npm"
|
||||||
# Look for `package.json` and `lock` files in the `root` directory
|
# Look for `package.json` and `lock` files in the `root` directory
|
||||||
directory: '/'
|
directory: "/"
|
||||||
# Check the npm registry for updates every day (weekdays)
|
# Check the npm registry for updates every day (weekdays)
|
||||||
schedule:
|
schedule:
|
||||||
interval: 'daily'
|
interval: "weekly"
|
||||||
|
|
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
|
@ -1,10 +1,10 @@
|
||||||
name: 'build-test'
|
name: "build-test"
|
||||||
on: # rebuild any PRs and main branch changes
|
on: # rebuild any PRs and main branch changes
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- 'releases/*'
|
- "releases/*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build: # make sure build/ci work properly
|
build: # make sure build/ci work properly
|
||||||
|
@ -12,13 +12,11 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
yarn install
|
||||||
- run: |
|
- run: |
|
||||||
npm run all
|
yarn run all
|
||||||
test: # make sure the action works on a clean machine without building
|
test: # make sure the action works on a clean machine without building
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
|
||||||
milliseconds: 1000
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
* @actions/actions-runtime
|
* @brittonhayes
|
||||||
|
|
|
@ -1,29 +1,9 @@
|
||||||
import {wait} from '../src/wait'
|
import {validateYAML} from '../src/validate'
|
||||||
import * as process from 'process'
|
|
||||||
import * as cp from 'child_process'
|
|
||||||
import * as path from 'path'
|
|
||||||
import {expect, test} from '@jest/globals'
|
import {expect, test} from '@jest/globals'
|
||||||
|
|
||||||
test('throws invalid number', async () => {
|
test('valid yaml files', async () => {
|
||||||
const input = parseInt('foo', 10)
|
const files: string[] = ['__tests__/valid.yaml']
|
||||||
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
|
const schemaPath: string = '__tests__/schema.json'
|
||||||
})
|
|
||||||
|
|
||||||
test('wait 500 ms', async () => {
|
await expect(validateYAML(files, schemaPath)).resolves.toBe(0)
|
||||||
const start = new Date()
|
|
||||||
await wait(500)
|
|
||||||
const end = new Date()
|
|
||||||
var delta = Math.abs(end.getTime() - start.getTime())
|
|
||||||
expect(delta).toBeGreaterThan(450)
|
|
||||||
})
|
|
||||||
|
|
||||||
// shows how the runner will run a javascript action with env / stdout protocol
|
|
||||||
test('test runs', () => {
|
|
||||||
process.env['INPUT_MILLISECONDS'] = '500'
|
|
||||||
const np = process.execPath
|
|
||||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
|
||||||
const options: cp.ExecFileSyncOptions = {
|
|
||||||
env: process.env
|
|
||||||
}
|
|
||||||
console.log(cp.execFileSync(np, [ip], options).toString())
|
|
||||||
})
|
})
|
||||||
|
|
8
__tests__/schema.json
Normal file
8
__tests__/schema.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"structure":{
|
||||||
|
"myValue": "string",
|
||||||
|
"myValue2": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
__tests__/valid.yaml
Normal file
5
__tests__/valid.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
test:
|
||||||
|
structure:
|
||||||
|
myValue: "1"
|
||||||
|
myValue2: "2"
|
18
action.yml
18
action.yml
|
@ -1,11 +1,13 @@
|
||||||
name: 'Your name here'
|
name: "Validate YAML"
|
||||||
description: 'Provide a description here'
|
description: "Validate YAML files against a strict schema"
|
||||||
author: 'Your name or organization here'
|
author: "Britton Hayes"
|
||||||
inputs:
|
inputs:
|
||||||
milliseconds: # change this
|
files:
|
||||||
|
description: "Files to validate"
|
||||||
|
required: true
|
||||||
|
schemaPath:
|
||||||
|
description: "Path to schema to validate against"
|
||||||
required: true
|
required: true
|
||||||
description: 'input description here'
|
|
||||||
default: 'default value if applicable'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: "node12"
|
||||||
main: 'dist/index.js'
|
main: "dist/index.js"
|
||||||
|
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
BIN
dist/licenses.txt
generated
vendored
BIN
dist/licenses.txt
generated
vendored
Binary file not shown.
BIN
dist/sourcemap-register.js
generated
vendored
BIN
dist/sourcemap-register.js
generated
vendored
Binary file not shown.
6334
package-lock.json
generated
6334
package-lock.json
generated
File diff suppressed because it is too large
Load diff
20
package.json
20
package.json
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "typescript-action",
|
"name": "validate-yaml",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "TypeScript template action",
|
"description": "Validate YAML against a schema using github actions",
|
||||||
"main": "lib/main.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
|
@ -11,21 +11,24 @@
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"package": "ncc build --source-map --license licenses.txt",
|
"package": "ncc build --source-map --license licenses.txt",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
"all": "yarn run build && yarn run format && yarn run lint && yarn run package && yarn test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/actions/typescript-action.git"
|
"url": "git+https://github.com/brittonhayes/wails-build-action.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"actions",
|
"actions",
|
||||||
"node",
|
"node",
|
||||||
"setup"
|
"go",
|
||||||
|
"wails"
|
||||||
],
|
],
|
||||||
"author": "",
|
"author": "Britton Hayes",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.4.0"
|
"@actions/core": "^1.4.0",
|
||||||
|
"@actions/exec": "^1.1.0",
|
||||||
|
"yaml-validator": "^3.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.3.3",
|
"@types/node": "^16.3.3",
|
||||||
|
@ -34,6 +37,7 @@
|
||||||
"eslint": "^7.31.0",
|
"eslint": "^7.31.0",
|
||||||
"eslint-plugin-github": "^4.1.1",
|
"eslint-plugin-github": "^4.1.1",
|
||||||
"eslint-plugin-jest": "^24.3.6",
|
"eslint-plugin-jest": "^24.3.6",
|
||||||
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"prettier": "2.2.1",
|
"prettier": "2.2.1",
|
||||||
|
|
15
src/index.ts
Normal file
15
src/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import {validateYAML} from './validate'
|
||||||
|
|
||||||
|
async function run(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const files: string[] = core.getMultilineInput('files')
|
||||||
|
const schemaPath: string = core.getInput('schemaPath')
|
||||||
|
|
||||||
|
await validateYAML(files, schemaPath)
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed((error as Error).message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
19
src/main.ts
19
src/main.ts
|
@ -1,19 +0,0 @@
|
||||||
import * as core from '@actions/core'
|
|
||||||
import {wait} from './wait'
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
|
||||||
try {
|
|
||||||
const ms: string = core.getInput('milliseconds')
|
|
||||||
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
|
||||||
|
|
||||||
core.debug(new Date().toTimeString())
|
|
||||||
await wait(parseInt(ms, 10))
|
|
||||||
core.debug(new Date().toTimeString())
|
|
||||||
|
|
||||||
core.setOutput('time', new Date().toTimeString())
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed(error.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run()
|
|
23
src/validate.ts
Normal file
23
src/validate.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import YamlValidator, {IYamlValidatorOptions} from 'yaml-validator'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
export async function validateYAML(
|
||||||
|
files: string[],
|
||||||
|
schemaPath: string
|
||||||
|
): Promise<number> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const structure = fs.readFileSync(schemaPath, {encoding: 'utf-8'})
|
||||||
|
const options: IYamlValidatorOptions = {
|
||||||
|
log: 'validator.log',
|
||||||
|
onWarning: (err, file) => {
|
||||||
|
reject(new Error(`File: ${file} - ${err.message}`))
|
||||||
|
},
|
||||||
|
structure: JSON.parse(structure),
|
||||||
|
writeJson: false
|
||||||
|
}
|
||||||
|
|
||||||
|
const validator = new YamlValidator(options)
|
||||||
|
validator.validate(files)
|
||||||
|
resolve(validator.report())
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
export async function wait(milliseconds: number): Promise<string> {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (isNaN(milliseconds)) {
|
|
||||||
throw new Error('milliseconds not a number')
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(() => resolve('done!'), milliseconds)
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
Reference in a new issue