d2ffb50a92
- Add validation, completion, hover, and document links for action.yml files - Implement document type detection to route action.yml to action-specific handlers - Add expression context for composite actions (inputs, steps, github, runner, etc.) - Add schema validation for required fields, branding, and composite step requirements - Support JavaScript (node20/node24), Docker, and composite action types - Validate action references in composite action uses steps - Add JSDoc comments to parser and template functions - Refactor hover to use hoverToken consistently - Fix lint errors and add return type annotations
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
import {TemplateParseResult} from "../templates/template-parse-result.js";
|
|
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";
|
|
|
|
/** @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 {
|
|
const context =
|
|
contextOrTrace instanceof TemplateContext
|
|
? contextOrTrace
|
|
: new TemplateContext(new TemplateValidationErrors(), getWorkflowSchema(), contextOrTrace);
|
|
|
|
const fileId = context.getFileId(entryFile.name);
|
|
const reader = new YamlObjectReader(fileId, entryFile.content);
|
|
if (reader.errors.length > 0) {
|
|
// The file is not valid YAML, template errors could be misleading
|
|
for (const err of reader.errors) {
|
|
context.error(fileId, err.message, err.range);
|
|
}
|
|
return {
|
|
context,
|
|
value: undefined
|
|
};
|
|
}
|
|
const result = templateReader.readTemplate(context, WORKFLOW_ROOT, reader, fileId);
|
|
|
|
return <TemplateParseResult>{
|
|
context,
|
|
value: result
|
|
};
|
|
}
|