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
128
.eslintrc.json
128
.eslintrc.json
|
@ -1,54 +1,76 @@
|
|||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
||||
"plugins": [
|
||||
"jest",
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"plugin:github/recommended"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "no-public"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error",
|
||||
{
|
||||
"allowExpressions": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error",
|
||||
"i18n-text/no-en": "off"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
3
.gitattributes
vendored
3
.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
|
||||
updates:
|
||||
# Enable version updates for npm
|
||||
- package-ecosystem: 'npm'
|
||||
- package-ecosystem: "npm"
|
||||
# Look for `package.json` and `lock` files in the `root` directory
|
||||
directory: '/'
|
||||
directory: "/"
|
||||
# Check the npm registry for updates every day (weekdays)
|
||||
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
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- 'releases/*'
|
||||
- "releases/*"
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
|
@ -12,13 +12,11 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
yarn install
|
||||
- run: |
|
||||
npm run all
|
||||
yarn run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
milliseconds: 1000
|
||||
|
|
|
@ -1 +1 @@
|
|||
* @actions/actions-runtime
|
||||
* @brittonhayes
|
||||
|
|
|
@ -1,29 +1,9 @@
|
|||
import {wait} from '../src/wait'
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as path from 'path'
|
||||
import {validateYAML} from '../src/validate'
|
||||
import {expect, test} from '@jest/globals'
|
||||
|
||||
test('throws invalid number', async () => {
|
||||
const input = parseInt('foo', 10)
|
||||
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
|
||||
})
|
||||
test('valid yaml files', async () => {
|
||||
const files: string[] = ['__tests__/valid.yaml']
|
||||
const schemaPath: string = '__tests__/schema.json'
|
||||
|
||||
test('wait 500 ms', async () => {
|
||||
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())
|
||||
await expect(validateYAML(files, schemaPath)).resolves.toBe(0)
|
||||
})
|
||||
|
|
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'
|
||||
description: 'Provide a description here'
|
||||
author: 'Your name or organization here'
|
||||
name: "Validate YAML"
|
||||
description: "Validate YAML files against a strict schema"
|
||||
author: "Britton Hayes"
|
||||
inputs:
|
||||
milliseconds: # change this
|
||||
files:
|
||||
description: "Files to validate"
|
||||
required: true
|
||||
schemaPath:
|
||||
description: "Path to schema to validate against"
|
||||
required: true
|
||||
description: 'input description here'
|
||||
default: 'default value if applicable'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
using: "node12"
|
||||
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",
|
||||
"private": true,
|
||||
"description": "TypeScript template action",
|
||||
"main": "lib/main.js",
|
||||
"description": "Validate YAML against a schema using github actions",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
|
@ -11,21 +11,24 @@
|
|||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"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": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/typescript-action.git"
|
||||
"url": "git+https://github.com/brittonhayes/wails-build-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"setup"
|
||||
"go",
|
||||
"wails"
|
||||
],
|
||||
"author": "",
|
||||
"author": "Britton Hayes",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.4.0"
|
||||
"@actions/core": "^1.4.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"yaml-validator": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.3.3",
|
||||
|
@ -34,6 +37,7 @@
|
|||
"eslint": "^7.31.0",
|
||||
"eslint-plugin-github": "^4.1.1",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "^27.0.6",
|
||||
"js-yaml": "^4.1.0",
|
||||
"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