From 1f78ebb163d83f66c06dee7f6b19b62250168fce Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Tue, 7 Nov 2023 19:19:13 +0000 Subject: [PATCH] feat: pass arguments to pipeline --- README.md | 2 +- main.ts | 8 +++++--- src/cmd/run.ts | 47 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 01f9c37..359f90d 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ fluentci # Run the pipeline fluentci --help Usage: fluentci [pipeline] [jobs...] -Version: 0.6.9 +Version: 0.7.0 Description: diff --git a/main.ts b/main.ts index 7b5dc5d..e725eb2 100644 --- a/main.ts +++ b/main.ts @@ -16,7 +16,7 @@ import doctor from "./src/cmd/doctor.ts"; export async function main() { await new Command() .name("fluentci") - .version("0.6.9") + .version("0.7.0") .description( ` . @@ -31,14 +31,16 @@ export async function main() { ) .arguments("[pipeline:string] [jobs...:string]") .option("-r, --reload", "Reload pipeline source cache") + .option("-*, --* ", "Pass arguments to pipeline") .action(function (options, pipeline, ...jobs: [string, ...Array]) { - run(pipeline || ".", jobs, options.reload); + run(pipeline || ".", jobs, options); }) .command("run", "Run a pipeline") .arguments(" [jobs...:string]") .option("-r, --reload", "Reload pipeline source cache") + .option("-*, --* ", "Pass arguments to pipeline") .action(function (options, pipeline, ...jobs: [string, ...Array]) { - run(pipeline, jobs, options.reload); + run(pipeline, jobs, options); }) .command("init", "Initialize a new pipeline") .arguments("[pipeline-name:string]") diff --git a/src/cmd/run.ts b/src/cmd/run.ts index 94d5e85..dcef19b 100644 --- a/src/cmd/run.ts +++ b/src/cmd/run.ts @@ -6,13 +6,13 @@ import { LogEventSchema } from "../types.ts"; * Runs a Fluent CI pipeline. * @param pipeline - The name of the pipeline to run. If set to ".", the pipeline will be run from the current directory. * @param jobs - An array of job names to run. - * @param reload - Whether to reload the pipeline before running it. + * @param options - An object of options. * @throws An error if the pipeline fails to run. */ async function run( pipeline: string, jobs: [string, ...Array], - reload = false + options: Record ) { if (pipeline === ".") { try { @@ -37,6 +37,10 @@ async function run( "--import-map=.fluentci/import_map.json", ".fluentci/src/dagger/runner.ts", ...jobs, + Object.keys(options) + .filter((key) => key !== "reload") + .map((key) => `--${key} ${options[key]}`) + .join(" "), ], stdout: "inherit", stderr: "inherit", @@ -55,6 +59,10 @@ async function run( "--import-map=.fluentci/import_map.json", ".fluentci/src/dagger/runner.ts", ...jobs, + Object.keys(options) + .filter((key) => key !== "reload") + .map((key) => `--${key} ${options[key]}`) + .join(" "), ], stdout: "inherit", stderr: "inherit", @@ -68,6 +76,23 @@ async function run( const jobFile = await Deno.stat(`.fluentci/${job}.ts`); if (jobFile.isFile) { jobFileExists = true; + commands.push( + new Deno.Command("dagger", { + args: [ + "run", + "deno", + "run", + "-A", + `.fluentci/${job}.ts`, + Object.keys(options) + .filter((key) => key !== "reload") + .map((key) => `--${key} ${options[key]}`) + .join(" "), + ], + stdout: "inherit", + stderr: "inherit", + }) + ); break; } } catch (_) { @@ -76,7 +101,17 @@ async function run( } commands.push( new Deno.Command("dagger", { - args: ["run", "deno", "run", "-A", `.fluentci/${job}.ts`], + args: [ + "run", + "deno", + "run", + "-A", + `.fluentci/${job}.ts`, + Object.keys(options) + .filter((key) => key !== "reload") + .map((key) => `--${key} ${options[key]}`) + .join(" "), + ], stdout: "inherit", stderr: "inherit", }) @@ -109,9 +144,13 @@ async function run( `--import-map=https://pkg.fluentci.io/${pipeline}@${data.version}/import_map.json`, `https://pkg.fluentci.io/${pipeline}@${data.version}/src/dagger/runner.ts`, ...jobs, + Object.keys(options) + .filter((key) => key !== "reload") + .map((key) => `--${key} ${options[key]}`) + .join(" "), ]; - if (reload) { + if (options.reload) { denoModule = ["-r", ...denoModule]; }