2026-01-02 10:38:52 -06:00
|
|
|
import {TemplateParseResult} from "../templates/template-parse-result.js";
|
2025-12-18 13:35:48 -06:00
|
|
|
import {TemplateContext, TemplateValidationErrors} from "../templates/template-context.js";
|
|
|
|
|
import * as templateReader from "../templates/template-reader.js";
|
|
|
|
|
import {TraceWriter} from "../templates/trace-writer.js";
|
|
|
|
|
import {File} from "./file.js";
|
|
|
|
|
import {WORKFLOW_ROOT} from "./workflow-constants.js";
|
|
|
|
|
import {getWorkflowSchema} from "./workflow-schema.js";
|
|
|
|
|
import {YamlObjectReader} from "./yaml-object-reader.js";
|
2023-01-06 15:54:31 -08:00
|
|
|
|
2026-01-02 10:38:52 -06:00
|
|
|
/** @deprecated Use TemplateParseResult instead */
|
|
|
|
|
export type ParseWorkflowResult = TemplateParseResult;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses a GitHub Actions workflow YAML file and returns the parsed template result.
|
|
|
|
|
* Validates the workflow against the workflow schema and reports any errors.
|
|
|
|
|
*/
|
|
|
|
|
export function parseWorkflow(entryFile: File, trace: TraceWriter): TemplateParseResult;
|
|
|
|
|
export function parseWorkflow(entryFile: File, context: TemplateContext): TemplateParseResult;
|
|
|
|
|
export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | TemplateContext): TemplateParseResult {
|
2023-02-06 15:10:34 -05:00
|
|
|
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
|
|
|
|
2026-01-02 10:38:52 -06:00
|
|
|
return <TemplateParseResult>{
|
2023-01-06 15:54:31 -08:00
|
|
|
context,
|
2023-01-09 19:02:19 -05:00
|
|
|
value: result
|
|
|
|
|
};
|
2023-01-06 15:54:31 -08:00
|
|
|
}
|