MCPcopy Create free account
hub / github.com/actions/starter-workflows / checkWorkflow

Function checkWorkflow

script/validate-data/index.ts:73–126  ·  view source on GitHub ↗
(workflowPath: string, propertiesPath: string, allowed_categories: object[])

Source from the content-addressed store, hash-verified

71}
72
73async function checkWorkflow(workflowPath: string, propertiesPath: string, allowed_categories: object[]): Promise<WorkflowWithErrors> {
74 let workflowErrors: WorkflowWithErrors = {
75 id: workflowPath,
76 name: null,
77 errors: []
78 }
79 try {
80 const workflowFileContent = await fs.readFile(workflowPath, "utf8");
81 safeLoad(workflowFileContent); // Validate yaml parses without error
82
83 const propertiesFileContent = await fs.readFile(propertiesPath, "utf8")
84 const properties: WorkflowProperties = JSON.parse(propertiesFileContent)
85 if(properties.name && properties.name.trim().length > 0) {
86 workflowErrors.name = properties.name
87 }
88 let v = new validator();
89 const res = v.validate(properties, propertiesSchema)
90 workflowErrors.errors = res.errors.map(e => e.toString())
91
92 if (properties.iconName) {
93 if(! /^octicon\s+/.test(properties.iconName)) {
94 try {
95 await fs.access(`../../icons/${properties.iconName}.svg`)
96 } catch (e) {
97 workflowErrors.errors.push(`No icon named ${properties.iconName} found`)
98 }
99 }
100 else {
101 let iconName = properties.iconName.match(/^octicon\s+(.*)/)
102 if(!iconName || iconName[1].split(".")[0].length <= 0) {
103 workflowErrors.errors.push(`No icon named ${properties.iconName} found`)
104 }
105 }
106
107 }
108 var path = dirname(workflowPath)
109 var folder_categories = allowed_categories.find( category => category["path"] == path)["categories"]
110 if (!workflowPath.endsWith("blank.yml")) {
111 if(!properties.categories || properties.categories.length == 0) {
112 workflowErrors.errors.push(`Workflow categories cannot be null or empty`)
113 }
114 else if(!folder_categories.some(category => properties.categories[0].toLowerCase() == category.toLowerCase())) {
115 workflowErrors.errors.push(`The first category in properties.json categories for workflow in ${basename(path)} folder must be one of "${folder_categories}. Either move the workflow to an appropriate directory or change the category."`)
116 }
117 }
118
119 if(basename(path).toLowerCase() == 'deployments' && !properties.creator) {
120 workflowErrors.errors.push(`The "creator" in properties.json must be present.`)
121 }
122 } catch (e) {
123 workflowErrors.errors.push(e.toString())
124 }
125 return workflowErrors;
126}
127
128(async function main() {
129 try {

Callers 1

checkWorkflowsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected