summaryrefslogtreecommitdiff
path: root/worker/scripts/run_pipeline
blob: ad58573b6e97c00edd25d40df9bdb63b231cecd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env -S deno --allow-env --allow-net --allow-read

import { type Job, PipelineImpl } from "@liz-ci/model";
import { getRequiredEnv, getStdout, validateIdentifier } from "@liz-ci/utils";

const stages = await (Deno.readTextFile(getRequiredEnv("pipeline")))
  .then(PipelineImpl.from)
  .then((pipeline) => pipeline.getStages());

const validateJob = (job: Job) => {
  Object.entries(job.arguments).forEach((e) => {
    if (!e.every(validateIdentifier)) {
      throw new Error(`job of type ${job.type} has invalid entry ${e}`);
    }
  });
};

for (const stage of stages) {
  await Promise.all(
    stage.parallelJobs.map((job) => {
      validateJob(job);

      return getStdout(job.type, {
        env: job.arguments,
      });
    }),
  );
}