Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow user to list available jobs #5

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions example/.fluentci/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 31 additions & 5 deletions example/.fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Client, { Container } from "@dagger.io/dagger";
import { withDevbox } from "https://deno.land/x/nix_installer_pipeline@v0.3.6/src/dagger/steps.ts";

export enum Job {
lintDebug = "lintDebug",
assembleDebug = "assembleDebug",
assembleRelease = "assembleRelease",
bundleRelease = "bundleRelease",
debugTests = "debugTests",
}

export const withAndroidSdk = (ctr: Container) =>
ctr
.withEnvVariable("ANDROID_HOME", "/root/android-sdk")
Expand All @@ -27,7 +35,7 @@ export const lintDebug = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("lintDebug")
.pipeline(Job.lintDebug)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -94,7 +102,7 @@ export const assembleDebug = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("assembleDebug")
.pipeline(Job.assembleDebug)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -154,7 +162,7 @@ export const assembleRelease = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("assembleRelease")
.pipeline(Job.assembleRelease)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -214,7 +222,7 @@ export const bundleRelease = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("bundleRelease")
.pipeline(Job.bundleRelease)
.container()
.from("alpine:latest")
.withEnvVariable("ANDROID_HOME", "/root/android-sdk")
Expand Down Expand Up @@ -275,7 +283,7 @@ export const debugTests = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("debugTests")
.pipeline(Job.debugTests)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -332,3 +340,21 @@ export const debugTests = async (client: Client, src = ".") => {

console.log(result);
};

export type JobExec = (client: Client, src?: string) => Promise<void>;

export const runnableJobs: Record<Job, JobExec> = {
[Job.lintDebug]: lintDebug,
[Job.assembleDebug]: assembleDebug,
[Job.assembleRelease]: assembleRelease,
[Job.bundleRelease]: bundleRelease,
[Job.debugTests]: debugTests,
};

export const jobDescriptions: Record<Job, string> = {
[Job.lintDebug]: "Runs lintDebug",
[Job.assembleDebug]: "Assembles debug apk",
[Job.assembleRelease]: "Assembles release apk",
[Job.bundleRelease]: "Bundles release apk",
[Job.debugTests]: "Runs debug tests",
};
21 changes: 21 additions & 0 deletions example/.fluentci/src/dagger/list_jobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { brightGreen } from "https://deno.land/std@0.191.0/fmt/colors.ts";
import { runnableJobs, jobDescriptions, Job } from "./jobs.ts";
import { stringifyTree } from "https://esm.sh/stringify-tree@1.1.1";

const tree = {
name: brightGreen("android_pipeline"),
children: (Object.keys(runnableJobs) as Job[]).map((job) => ({
name: jobDescriptions[job]
? `${brightGreen(job)} - ${jobDescriptions[job]}`
: brightGreen(job),
children: [],
})),
};

console.log(
stringifyTree(
tree,
(t) => t.name,
(t) => t.children
)
);
9 changes: 4 additions & 5 deletions example/.fluentci/src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Client, { connect } from "@dagger.io/dagger";
import * as jobs from "./jobs.ts";

const { assembleDebug, debugTests, lintDebug } = jobs;
const { assembleDebug, debugTests, lintDebug, runnableJobs } = jobs;

export default function pipeline(src = ".", args: string[] = []) {
connect(async (client: Client) => {
if (args.length > 0) {
await runSpecificJobs(client, args);
await runSpecificJobs(client, args as jobs.Job[]);
return;
}

Expand All @@ -16,10 +16,9 @@ export default function pipeline(src = ".", args: string[] = []) {
});
}

async function runSpecificJobs(client: Client, args: string[]) {
async function runSpecificJobs(client: Client, args: jobs.Job[]) {
for (const name of args) {
// deno-lint-ignore no-explicit-any
const job = (jobs as any)[name];
const job = runnableJobs[name];
if (!job) {
throw new Error(`Job ${name} not found`);
}
Expand Down
36 changes: 31 additions & 5 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Client, { Container } from "@dagger.io/dagger";
import { withDevbox } from "https://deno.land/x/nix_installer_pipeline@v0.3.6/src/dagger/steps.ts";

export enum Job {
lintDebug = "lintDebug",
assembleDebug = "assembleDebug",
assembleRelease = "assembleRelease",
bundleRelease = "bundleRelease",
debugTests = "debugTests",
}

export const withAndroidSdk = (ctr: Container) =>
ctr
.withEnvVariable("ANDROID_HOME", "/root/android-sdk")
Expand All @@ -27,7 +35,7 @@ export const lintDebug = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("lintDebug")
.pipeline(Job.lintDebug)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -94,7 +102,7 @@ export const assembleDebug = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("assembleDebug")
.pipeline(Job.assembleDebug)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -154,7 +162,7 @@ export const assembleRelease = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("assembleRelease")
.pipeline(Job.assembleRelease)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -214,7 +222,7 @@ export const bundleRelease = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("bundleRelease")
.pipeline(Job.bundleRelease)
.container()
.from("alpine:latest")
.withEnvVariable("ANDROID_HOME", "/root/android-sdk")
Expand Down Expand Up @@ -275,7 +283,7 @@ export const debugTests = async (client: Client, src = ".") => {
const baseCtr = withDevbox(
withAndroidSdk(
client
.pipeline("debugTests")
.pipeline(Job.debugTests)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
Expand Down Expand Up @@ -332,3 +340,21 @@ export const debugTests = async (client: Client, src = ".") => {

console.log(result);
};

export type JobExec = (client: Client, src?: string) => Promise<void>;

export const runnableJobs: Record<Job, JobExec> = {
[Job.lintDebug]: lintDebug,
[Job.assembleDebug]: assembleDebug,
[Job.assembleRelease]: assembleRelease,
[Job.bundleRelease]: bundleRelease,
[Job.debugTests]: debugTests,
};

export const jobDescriptions: Record<Job, string> = {
[Job.lintDebug]: "Runs lintDebug",
[Job.assembleDebug]: "Assembles debug apk",
[Job.assembleRelease]: "Assembles release apk",
[Job.bundleRelease]: "Bundles release apk",
[Job.debugTests]: "Runs debug tests",
};
21 changes: 21 additions & 0 deletions src/dagger/list_jobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { brightGreen } from "https://deno.land/std@0.191.0/fmt/colors.ts";
import { runnableJobs, jobDescriptions, Job } from "./jobs.ts";
import { stringifyTree } from "https://esm.sh/stringify-tree@1.1.1";

const tree = {
name: brightGreen("android_pipeline"),
children: (Object.keys(runnableJobs) as Job[]).map((job) => ({
name: jobDescriptions[job]
? `${brightGreen(job)} - ${jobDescriptions[job]}`
: brightGreen(job),
children: [],
})),
};

console.log(
stringifyTree(
tree,
(t) => t.name,
(t) => t.children
)
);
9 changes: 4 additions & 5 deletions src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Client, { connect } from "@dagger.io/dagger";
import * as jobs from "./jobs.ts";

const { assembleDebug, debugTests, lintDebug } = jobs;
const { assembleDebug, debugTests, lintDebug, runnableJobs } = jobs;

export default function pipeline(src = ".", args: string[] = []) {
connect(async (client: Client) => {
if (args.length > 0) {
await runSpecificJobs(client, args);
await runSpecificJobs(client, args as jobs.Job[]);
return;
}

Expand All @@ -16,10 +16,9 @@ export default function pipeline(src = ".", args: string[] = []) {
});
}

async function runSpecificJobs(client: Client, args: string[]) {
async function runSpecificJobs(client: Client, args: jobs.Job[]) {
for (const name of args) {
// deno-lint-ignore no-explicit-any
const job = (jobs as any)[name];
const job = runnableJobs[name];
if (!job) {
throw new Error(`Job ${name} not found`);
}
Expand Down