Merge pull request #1 from aparna-ravindra/workflow-schema-validation
workflow schema validation
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
# This is a basic workflow that is manually triggered
|
|
||||||
|
|
||||||
name: Manual workflow
|
|
||||||
|
|
||||||
# Controls when the action will run. Workflow runs when manually triggered using the UI
|
|
||||||
# or API.
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
# Inputs the workflow accepts.
|
|
||||||
inputs:
|
|
||||||
name:
|
|
||||||
# Friendly description to be shown in the UI instead of 'name'
|
|
||||||
description: 'Person to greet'
|
|
||||||
# Default value if no value is explicitly provided
|
|
||||||
default: 'World'
|
|
||||||
# Input has to be provided for the workflow to run
|
|
||||||
required: true
|
|
||||||
|
|
||||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
|
||||||
jobs:
|
|
||||||
# This workflow contains a single job called "greet"
|
|
||||||
greet:
|
|
||||||
# The type of runner that the job will run on
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
|
||||||
steps:
|
|
||||||
# Runs a single command using the runners shell
|
|
||||||
- name: Send greeting
|
|
||||||
run: echo "Hello ${{ github.event.inputs.name }}"
|
|
||||||
@@ -16,7 +16,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: macOS-latest
|
runs-on: macos-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
r-version: [3.5, 3.6]
|
r-version: [3.5, 3.6]
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ const propertiesSchema = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkWorkflows(folders: string[]): Promise<WorkflowWithErrors[]> {
|
async function checkWorkflows(folders: string[]): Promise<WorkflowWithErrors[]> {
|
||||||
const result: WorkflowWithErrors[] = []
|
const result: WorkflowWithErrors[] = []
|
||||||
|
|
||||||
@@ -66,6 +65,29 @@ async function checkWorkflows(folders: string[]): Promise<WorkflowWithErrors[]>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function validateWorkflowProperties(propertiesPath: string) : Promise<string[]> {
|
||||||
|
try {
|
||||||
|
let errors = []
|
||||||
|
const propertiesFileContent = await fs.readFile(propertiesPath, "utf8")
|
||||||
|
const properties: WorkflowProperties = JSON.parse(propertiesFileContent)
|
||||||
|
|
||||||
|
let v = new validator();
|
||||||
|
const res = v.validate(properties, propertiesSchema)
|
||||||
|
errors = res.errors.map(e => e.toString())
|
||||||
|
if (properties.iconName && !properties.iconName.startsWith("octicon")) {
|
||||||
|
try {
|
||||||
|
await fs.access(`../../icons/${properties.iconName}.svg`)
|
||||||
|
} catch (e) {
|
||||||
|
errors.push(`No icon named ${properties.iconName} found`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkWorkflow(workflowPath: string, propertiesPath: string): Promise<WorkflowWithErrors> {
|
async function checkWorkflow(workflowPath: string, propertiesPath: string): Promise<WorkflowWithErrors> {
|
||||||
let workflowErrors: WorkflowWithErrors = {
|
let workflowErrors: WorkflowWithErrors = {
|
||||||
id: workflowPath,
|
id: workflowPath,
|
||||||
@@ -73,23 +95,18 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string): Prom
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
workflowErrors.errors = await validateWorkflowProperties(propertiesPath)
|
||||||
|
|
||||||
const workflowFileContent = await fs.readFile(workflowPath, "utf8");
|
const workflowFileContent = await fs.readFile(workflowPath, "utf8");
|
||||||
safeLoad(workflowFileContent); // Validate yaml parses without error
|
const workflow = safeLoad(workflowFileContent); // Validate yaml parses without error
|
||||||
|
|
||||||
const propertiesFileContent = await fs.readFile(propertiesPath, "utf8")
|
let workflowValidator = new validator();
|
||||||
const properties: WorkflowProperties = JSON.parse(propertiesFileContent)
|
const workflowSchema = require("./workflow-schema.json");
|
||||||
|
|
||||||
let v = new validator();
|
const workflowValidationResult = workflowValidator.validate(workflow, workflowSchema)
|
||||||
const res = v.validate(properties, propertiesSchema)
|
const workflowValidationErrors = workflowValidationResult.errors.map(e => e.toString())
|
||||||
workflowErrors.errors = res.errors.map(e => e.toString())
|
workflowErrors.errors = workflowErrors.errors.concat(workflowValidationErrors)
|
||||||
|
|
||||||
if (properties.iconName && !properties.iconName.startsWith("octicon")) {
|
|
||||||
try {
|
|
||||||
await fs.access(`../../icons/${properties.iconName}.svg`)
|
|
||||||
} catch (e) {
|
|
||||||
workflowErrors.errors.push(`No icon named ${properties.iconName} found`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
workflowErrors.errors.push(e.toString())
|
workflowErrors.errors.push(e.toString())
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user