2023-01-09 19:02:19 -05:00
|
|
|
import {TemplateContext, TemplateValidationErrors} from "../templates/template-context";
|
|
|
|
|
import * as templateReader from "../templates/template-reader";
|
|
|
|
|
import {TemplateToken} from "../templates/tokens/template-token";
|
|
|
|
|
import {TraceWriter} from "../templates/trace-writer";
|
|
|
|
|
import {File} from "./file";
|
|
|
|
|
import {WORKFLOW_ROOT} from "./workflow-constants";
|
|
|
|
|
import {getWorkflowSchema} from "./workflow-schema";
|
|
|
|
|
import {YamlObjectReader} from "./yaml-object-reader";
|
2023-01-06 15:54:31 -08:00
|
|
|
export interface ParseWorkflowResult {
|
2023-01-09 19:02:19 -05:00
|
|
|
context: TemplateContext;
|
|
|
|
|
value: TemplateToken | undefined;
|
2023-01-06 15:54:31 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-06 15:10:34 -05:00
|
|
|
export function parseWorkflow(entryFile: File, trace: TraceWriter): ParseWorkflowResult;
|
|
|
|
|
export function parseWorkflow(entryFile: File, context: TemplateContext): ParseWorkflowResult;
|
|
|
|
|
export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | TemplateContext): ParseWorkflowResult {
|
|
|
|
|
const context =
|
|
|
|
|
contextOrTrace instanceof TemplateContext
|
|
|
|
|
? contextOrTrace
|
|
|
|
|
: new TemplateContext(new TemplateValidationErrors(), getWorkflowSchema(), contextOrTrace);
|
2023-01-06 15:54:31 -08:00
|
|
|
|
2023-02-06 11:15:15 -05:00
|
|
|
const fileId = context.getFileId(entryFile.name);
|
2023-02-09 18:50:05 -05:00
|
|
|
const reader = new YamlObjectReader(fileId, entryFile.content);
|
|
|
|
|
if (reader.errors.length > 0) {
|
2023-01-06 15:54:31 -08:00
|
|
|
// The file is not valid YAML, template errors could be misleading
|
2023-02-09 18:50:05 -05:00
|
|
|
for (const err of reader.errors) {
|
|
|
|
|
context.error(fileId, err.message, err.range);
|
|
|
|
|
}
|
2023-01-06 15:54:31 -08:00
|
|
|
return {
|
|
|
|
|
context,
|
2023-01-09 19:02:19 -05:00
|
|
|
value: undefined
|
|
|
|
|
};
|
2023-01-06 15:54:31 -08:00
|
|
|
}
|
2023-01-09 19:02:19 -05:00
|
|
|
const result = templateReader.readTemplate(context, WORKFLOW_ROOT, reader, fileId);
|
2023-01-06 15:54:31 -08:00
|
|
|
|
|
|
|
|
return <ParseWorkflowResult>{
|
|
|
|
|
context,
|
2023-01-09 19:02:19 -05:00
|
|
|
value: result
|
|
|
|
|
};
|
2023-01-06 15:54:31 -08:00
|
|
|
}
|