Skip to content

Commit

Permalink
Merge pull request #4 from fluent-ci-templates/feat/run-specific-jobs
Browse files Browse the repository at this point in the history
feat: allow running specific jobs from a pipeline
  • Loading branch information
tsirysndr authored Aug 3, 2023
2 parents d100f9c + 940bbaa commit 2992ebc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
22 changes: 20 additions & 2 deletions example/.fluentci/src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion example/.fluentci/src/dagger/runner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pipeline from "./pipeline.ts";

pipeline();
pipeline(".", Deno.args);
22 changes: 20 additions & 2 deletions src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/dagger/runner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pipeline from "./pipeline.ts";

pipeline();
pipeline(".", Deno.args);

0 comments on commit 2992ebc

Please sign in to comment.