Skip to content

Commit

Permalink
Merge pull request #3 from fluentci-io/feat/pipeline-args
Browse files Browse the repository at this point in the history
feat: pass arguments to pipeline
  • Loading branch information
tsirysndr authored Nov 7, 2023
2 parents 11674f6 + 1f78ebb commit 37b6b1f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.6.9
Version: 0.7.0

Description:

Expand Down
8 changes: 5 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
.
Expand All @@ -31,14 +31,16 @@ export async function main() {
)
.arguments("[pipeline:string] [jobs...:string]")
.option("-r, --reload", "Reload pipeline source cache")
.option("-*, --* <args:string>", "Pass arguments to pipeline")
.action(function (options, pipeline, ...jobs: [string, ...Array<string>]) {
run(pipeline || ".", jobs, options.reload);
run(pipeline || ".", jobs, options);
})
.command("run", "Run a pipeline")
.arguments("<pipeline:string> [jobs...:string]")
.option("-r, --reload", "Reload pipeline source cache")
.option("-*, --* <args:string>", "Pass arguments to pipeline")
.action(function (options, pipeline, ...jobs: [string, ...Array<string>]) {
run(pipeline, jobs, options.reload);
run(pipeline, jobs, options);
})
.command("init", "Initialize a new pipeline")
.arguments("[pipeline-name:string]")
Expand Down
47 changes: 43 additions & 4 deletions src/cmd/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>],
reload = false
options: Record<string, string | number | boolean | undefined>
) {
if (pipeline === ".") {
try {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 (_) {
Expand All @@ -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",
})
Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit 37b6b1f

Please sign in to comment.