185 lines · 5.9 KB
import { z } from "zod";
import { parse as parseYaml } from "yaml";

const stringList = z
  .union([z.string(), z.array(z.string())])
  .transform((value) => (Array.isArray(value) ? value : [value]));

const scalar = z.union([z.string(), z.number(), z.boolean()]).transform((value) => String(value));
const envMap = z.record(z.string(), scalar);

const refFilters = z
  .object({
    branches: stringList.optional(),
    "branches-ignore": stringList.optional(),
    tags: stringList.optional(),
    "tags-ignore": stringList.optional(),
    paths: stringList.optional(),
    "paths-ignore": stringList.optional(),
    types: stringList.optional(),
    workflows: stringList.optional(),
  })
  .nullable()
  .transform((value) => value ?? {});

export type RefFilters = z.infer<typeof refFilters>;

const dispatchInput = z.object({
  description: z.string().optional(),
  required: z.boolean().optional(),
  default: scalar.optional(),
  type: z.enum(["string", "boolean", "choice", "number"]).optional(),
  options: z.array(scalar).optional(),
});

const schedule = z.array(z.object({ cron: z.string().min(1).max(100) })).max(20);

const triggerMap = z.object({
  push: refFilters.optional(),
  pull_request: refFilters.optional(),
  release: refFilters.optional(),