From d54e91c6582ed160cf2f2fcf977e48b4439d133b Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Sun, 18 May 2025 22:54:15 -0700 Subject: snapshot --- model/deno.json | 2 +- model/job.ts | 19 +++++++++++++++++++ model/pipeline.ts | 37 ++++++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 14 deletions(-) (limited to 'model') diff --git a/model/deno.json b/model/deno.json index d22242e..afd9f22 100644 --- a/model/deno.json +++ b/model/deno.json @@ -1,5 +1,5 @@ { - "name": "@liz-ci/model", + "name": "@emprespresso/ci-model", "version": "0.1.0", "exports": "./mod.ts" } diff --git a/model/job.ts b/model/job.ts index 53d548f..a3b52dd 100644 --- a/model/job.ts +++ b/model/job.ts @@ -1,8 +1,13 @@ +import { isObject } from "@emprespresso/pengueno"; + export type JobArgT = Record; export interface Job { readonly type: string; readonly arguments: JobArgT; } +export const isJob = (j: unknown): j is Job => + !!(isObject(j) && "arguments" in j && isObject(j.arguments) && + "type" in j && typeof j.type === "string" && j); export interface FetchCodeJobProps extends JobArgT { readonly remoteUrl: string; @@ -40,3 +45,17 @@ export interface AnsiblePlaybookJob extends Job { readonly type: "ansible_playbook"; readonly arguments: AnsiblePlaybookJobProps; } + +export interface CheckoutCiJobProps extends JobArgT { + readonly remote: string; + readonly refname: string; + readonly rev: string; + + readonly run: string; + readonly returnPath: string; +} + +export interface CheckoutCiJob extends Job { + readonly type: "checkout_ci"; + readonly arguments: CheckoutCiJobProps; +} diff --git a/model/pipeline.ts b/model/pipeline.ts index 06361a4..b0db1b7 100644 --- a/model/pipeline.ts +++ b/model/pipeline.ts @@ -1,13 +1,20 @@ -import type { FetchCodeJob, Job } from "./mod.ts"; - -export interface Pipeline { - getStages(): ReadonlyArray; - serialize(): string; -} +import { Either, type IEither, isObject } from "@emprespresso/pengueno"; +import { type FetchCodeJob, isJob, type Job } from "@emprespresso/ci-model"; export interface PipelineStage { readonly parallelJobs: Array; } +export const isPipelineStage = (t: unknown): t is PipelineStage => + isObject(t) && "parallelJobs" in t && Array.isArray(t.parallelJobs) && + t.parallelJobs.every((j) => isJob(j)); + +export interface Pipeline { + readonly serialJobs: Array; + serialize(): string; +} +export const isPipeline = (t: unknown): t is Pipeline => + isObject(t) && "serialJobs" in t && Array.isArray(t.serialJobs) && + t.serialJobs.every((p) => isPipelineStage(p)); export interface PipelineBuilder { addStage(stage: PipelineStage): PipelineBuilder; @@ -15,18 +22,22 @@ export interface PipelineBuilder { } export class PipelineImpl implements Pipeline { - constructor(private readonly serialJobs: ReadonlyArray) {} - - public getStages() { - return this.serialJobs; - } + constructor(public readonly serialJobs: Array) {} public serialize() { return JSON.stringify(this.serialJobs); } - public static from(s: string): Pipeline { - return new PipelineImpl(JSON.parse(s)); + public static from(s: string): IEither { + return Either.fromFailable(() => JSON.parse(s)).flatMap< + Pipeline + >(( + eitherPipelineJson, + ) => + isPipeline(eitherPipelineJson) + ? Either.right(eitherPipelineJson) + : Either.left(new Error("oh noes D: its a bad pipewine :((")) + ).mapRight((pipeline) => new PipelineImpl(pipeline.serialJobs)); } } -- cgit v1.2.3-70-g09d2