From 940bbaa0b09cc4737ffab2ecf15dacead970b003 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 3 Aug 2023 19:03:10 +0000 Subject: [PATCH] feat: allow running specific jobs from a pipeline --- example/.fluentci/src/dagger/pipeline.ts | 22 ++++++++++++++++++++-- example/.fluentci/src/dagger/runner.ts | 2 +- src/dagger/pipeline.ts | 22 ++++++++++++++++++++-- src/dagger/runner.ts | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/example/.fluentci/src/dagger/pipeline.ts b/example/.fluentci/src/dagger/pipeline.ts index 715ad70..0669010 100644 --- a/example/.fluentci/src/dagger/pipeline.ts +++ b/example/.fluentci/src/dagger/pipeline.ts @@ -1,10 +1,28 @@ import Client, { connect } from "@dagger.io/dagger"; -import { assembleDebug, debugTests, lintDebug } from "./jobs.ts"; +import * as jobs from "./jobs.ts"; -export default function pipeline(src = ".") { +const { assembleDebug, debugTests, lintDebug } = jobs; + +export default function pipeline(src = ".", args: string[] = []) { connect(async (client: Client) => { + if (args.length > 0) { + await runSpecificJobs(client, args); + return; + } + await lintDebug(client, src); await debugTests(client, src); await assembleDebug(client, src); }); } + +async function runSpecificJobs(client: Client, args: string[]) { + for (const name of args) { + // deno-lint-ignore no-explicit-any + const job = (jobs as any)[name]; + if (!job) { + throw new Error(`Job ${name} not found`); + } + await job(client); + } +} diff --git a/example/.fluentci/src/dagger/runner.ts b/example/.fluentci/src/dagger/runner.ts index f90999c..e23879e 100644 --- a/example/.fluentci/src/dagger/runner.ts +++ b/example/.fluentci/src/dagger/runner.ts @@ -1,3 +1,3 @@ import pipeline from "./pipeline.ts"; -pipeline(); +pipeline(".", Deno.args); diff --git a/src/dagger/pipeline.ts b/src/dagger/pipeline.ts index 715ad70..0669010 100644 --- a/src/dagger/pipeline.ts +++ b/src/dagger/pipeline.ts @@ -1,10 +1,28 @@ import Client, { connect } from "@dagger.io/dagger"; -import { assembleDebug, debugTests, lintDebug } from "./jobs.ts"; +import * as jobs from "./jobs.ts"; -export default function pipeline(src = ".") { +const { assembleDebug, debugTests, lintDebug } = jobs; + +export default function pipeline(src = ".", args: string[] = []) { connect(async (client: Client) => { + if (args.length > 0) { + await runSpecificJobs(client, args); + return; + } + await lintDebug(client, src); await debugTests(client, src); await assembleDebug(client, src); }); } + +async function runSpecificJobs(client: Client, args: string[]) { + for (const name of args) { + // deno-lint-ignore no-explicit-any + const job = (jobs as any)[name]; + if (!job) { + throw new Error(`Job ${name} not found`); + } + await job(client); + } +} diff --git a/src/dagger/runner.ts b/src/dagger/runner.ts index f90999c..e23879e 100644 --- a/src/dagger/runner.ts +++ b/src/dagger/runner.ts @@ -1,3 +1,3 @@ import pipeline from "./pipeline.ts"; -pipeline(); +pipeline(".", Deno.args);