in src/pipeline.ts [127:188]
protected doBuildPipeline() {
const app = Stage.of(this);
if (!app) { throw new Error('');}
const cdkoutDir = app?.outdir;
const jobs = new Array<Job>();
const structure = new PipelineGraph(this, {
selfMutation: false,
publishTemplate: true,
prepareStep: false, // we create and execute the changeset in a single job
});
for (const stageNode of flatten(structure.graph.sortedChildren())) {
if (!isGraph(stageNode)) {
throw new Error(`Top-level children must be graphs, got '${stageNode}'`);
}
const tranches = stageNode.sortedLeaves();
for (const tranche of tranches) {
for (const node of tranche) {
const job = this.jobForNode(node, {
assemblyDir: cdkoutDir,
structure,
});
if (job) {
jobs.push(job);
}
}
}
}
// convert jobs to a map and make sure there are no duplicates
const jobmap: Record<string, github.Job> = {};
for (const job of jobs) {
if (job.id in jobmap) {
throw new Error(`duplicate job id ${job.id}`);
}
jobmap[job.id] = snakeCaseKeys(job.definition);
}
// Update jobs with late-bound output requests
this.insertJobOutputs(jobmap);
const workflow = {
name: this.workflowName,
on: snakeCaseKeys(this.workflowTriggers, '_'),
jobs: jobmap,
};
// write as a yaml file
const yaml = YAML.stringify(workflow, {
indent: 2,
});
// eslint-disable-next-line no-console
console.error(`writing ${this.workflowPath}`);
mkdirSync(path.dirname(this.workflowPath), { recursive: true });
writeFileSync(this.workflowPath, yaml);
}