Skip to content

@ghagen/ghagen

YAML serialization and raw value escape hatch.

Function Description

raw

Create a Raw value that bypasses type constraints.

toYaml

Serialize a workflow or action model to a YAML string.

Keys are emitted in canonical order, comments are attached, and multiline strings use block-literal style. A header comment identifying the generating tool is prepended by default.

Example

const yaml = toYaml(myWorkflow);
console.log(yaml);
// Suppress the auto-generated header comment:
const bare = toYaml(myWorkflow, { includeHeader: false });

toYamlFile

Serialize a model to a YAML file.

Creates any intermediate directories that do not yet exist and writes the YAML output synchronously. This is a convenience wrapper around toYaml for the common “write to disk” use case.

Example

toYamlFile(myWorkflow, ".github/workflows/ci.yml");
// With a custom header:
toYamlFile(myAction, "action.yml", {
header: "Generated by {tool} v{version}",
});