Merge pull request #1 from aparna-ravindra/workflow-schema-validation

workflow schema validation
This commit is contained in:
Aparna Ravindra
2021-07-28 22:14:09 +05:30
committed by GitHub
4 changed files with 1280 additions and 49 deletions
-30
View File
@@ -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 }}"
+1 -1
View File
@@ -16,7 +16,7 @@ on:
jobs:
build:
runs-on: macOS-latest
runs-on: macos-latest
strategy:
matrix:
r-version: [3.5, 3.6]
+35 -18
View File
@@ -39,7 +39,6 @@ const propertiesSchema = {
},
}
}
async function checkWorkflows(folders: string[]): Promise<WorkflowWithErrors[]> {
const result: WorkflowWithErrors[] = []
@@ -66,6 +65,29 @@ async function checkWorkflows(folders: string[]): Promise<WorkflowWithErrors[]>
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> {
let workflowErrors: WorkflowWithErrors = {
id: workflowPath,
@@ -73,23 +95,18 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string): Prom
}
try {
workflowErrors.errors = await validateWorkflowProperties(propertiesPath)
const workflowFileContent = await fs.readFile(workflowPath, "utf8");
safeLoad(workflowFileContent); // Validate yaml parses without error
const propertiesFileContent = await fs.readFile(propertiesPath, "utf8")
const properties: WorkflowProperties = JSON.parse(propertiesFileContent)
let v = new validator();
const res = v.validate(properties, propertiesSchema)
workflowErrors.errors = res.errors.map(e => e.toString())
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`)
}
}
const workflow = safeLoad(workflowFileContent); // Validate yaml parses without error
let workflowValidator = new validator();
const workflowSchema = require("./workflow-schema.json");
const workflowValidationResult = workflowValidator.validate(workflow, workflowSchema)
const workflowValidationErrors = workflowValidationResult.errors.map(e => e.toString())
workflowErrors.errors = workflowErrors.errors.concat(workflowValidationErrors)
} catch (e) {
workflowErrors.errors.push(e.toString())
}
@@ -120,4 +137,4 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string): Prom
error(`Unhandled error while syncing workflows: ${e}`);
setFailed(`Unhandled error`)
}
})();
})();
File diff suppressed because it is too large Load Diff