218 lines · 8.2 KB
import { evaluate, evaluateCondition, stringify } from "./expressions";
import type { ExprContext, ExprValue } from "./expressions";
import type { JobSpec, StepSpec, WorkflowSpec } from "./spec";

export type Segment = { kind: "text"; value: string } | { kind: "secret"; name: string };

export type CompiledStep = {
  index: number;
  name: string;
  kind: "run" | "upload-artifact" | "noop";
  script: string;
  shell: string;
  workingDirectory: string | null;
  env: Array<[string, Segment[]]>;
  continueOnError: boolean;
  timeoutMinutes: number | null;
  runIfOk: boolean;
  runIfFailed: boolean;
  artifact: { name: string; path: string } | null;
};

export type CompiledJob = {
  key: string;
  baseKey: string;
  name: string;
  runsOn: string[];
  needs: string[];
  runIfOk: boolean;
  runIfFailed: boolean;
  timeoutMinutes: number;
  continueOnError: boolean;
  env: Array<[string, Segment[]]>;
  steps: CompiledStep[];
};

export type EventContext = Record<string, ExprValue>;

const EXPRESSION = /\$\{\{([\s\S]*?)\}\}/g;
const SECRET_REFERENCE = /^\s*secrets\.([A-Za-z_][A-Za-z0-9_]*)\s*$/;
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;