From f4f5950afebb22f0f6f9932d432a704dfa5ea47a Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Sun, 6 Aug 2023 02:39:45 +0000 Subject: [PATCH] feat: allow user to list available jobs --- deno.lock | 3 ++ example/.fluentci/deno.lock | 3 ++ example/.fluentci/src/dagger/jobs.ts | 36 +++++++++++++++++++---- example/.fluentci/src/dagger/list_jobs.ts | 21 +++++++++++++ example/.fluentci/src/dagger/pipeline.ts | 9 +++--- src/dagger/jobs.ts | 36 +++++++++++++++++++---- src/dagger/list_jobs.ts | 21 +++++++++++++ src/dagger/pipeline.ts | 9 +++--- 8 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 example/.fluentci/src/dagger/list_jobs.ts create mode 100644 src/dagger/list_jobs.ts diff --git a/deno.lock b/deno.lock index a26c3ce..fb8508a 100644 --- a/deno.lock +++ b/deno.lock @@ -19,6 +19,7 @@ "https://deno.land/x/nix_installer_pipeline@v0.3.5/src/dagger/steps.ts": "37aaf4015ddea4de0fc23af6ed8068aa500b44eba39cb6f5862d350de04d06d5", "https://deno.land/x/nix_installer_pipeline@v0.3.6/src/dagger/steps.ts": "a34aea3753c7079de5877f592ce31f30d05d552155729ff3e695d77326405133", "https://deno.land/x/xhr@0.3.0/mod.ts": "094aacd627fd9635cd942053bf8032b5223b909858fa9dc8ffa583752ff63b20", + "https://esm.sh/stringify-tree@1.1.1": "8d994a105481fa944515323d89bd2596c1de79f3d9bd1386266463934716eca0", "https://esm.sh/v128/*@dagger.io/dagger@0.6.3": "cb691a77c0cdaee22f2b8393731b5143c83ce22dbbea204cdbfd203768d15b64", "https://esm.sh/v128/@dagger.io/dagger@0.6.3/X-ZS8q/denonext/dagger.mjs": "fd0901784d75b99615b5409c3654b5c7edfc5ba377c9e1a5a67ffff4f7d3ac32", "https://esm.sh/v128/adm-zip@0.5.10": "d9c54d6d2dd788462781a57d923295bd79304e6fd74b242fd4b30e35b39c5dcf", @@ -73,6 +74,8 @@ "https://esm.sh/v128/which@2.0.2/denonext/which.mjs": "86bf76e4937edb7fa3464d7bb9a426ef273684d1cefbec5ba5f1bdcb5cafff91", "https://esm.sh/v128/yallist@4.0.0/denonext/yallist.mjs": "61f180d807dda50bac17028eda05d5722a3fecef6e98a9064e2353ea6864fd82", "https://esm.sh/v128/yaml@2.3.1/denonext/yaml.mjs": "71f677b4bfc69271af9d98db5194e354f9a1863955e208e26d32a9ef78bd89f5", + "https://esm.sh/v130/lodash.flatten@4.4.0/denonext/lodash.flatten.mjs": "8e86ab607deea15cc3c1acfb5eae278ecbc5b80f24167b4e8f4c56df3278cd55", + "https://esm.sh/v130/stringify-tree@1.1.1/denonext/stringify-tree.mjs": "40a9d40e0282b5432302a3da68b88aa11685bc0b8a0b70246168deed5c5773fe", "https://esm.sh/yaml@v2.3.1": "8ef3aee065e93b03cebf8fd5a3418bc30131344b7f2b8c8ae27bf9f277416087" }, "npm": { diff --git a/example/.fluentci/deno.lock b/example/.fluentci/deno.lock index a26c3ce..fb8508a 100644 --- a/example/.fluentci/deno.lock +++ b/example/.fluentci/deno.lock @@ -19,6 +19,7 @@ "https://deno.land/x/nix_installer_pipeline@v0.3.5/src/dagger/steps.ts": "37aaf4015ddea4de0fc23af6ed8068aa500b44eba39cb6f5862d350de04d06d5", "https://deno.land/x/nix_installer_pipeline@v0.3.6/src/dagger/steps.ts": "a34aea3753c7079de5877f592ce31f30d05d552155729ff3e695d77326405133", "https://deno.land/x/xhr@0.3.0/mod.ts": "094aacd627fd9635cd942053bf8032b5223b909858fa9dc8ffa583752ff63b20", + "https://esm.sh/stringify-tree@1.1.1": "8d994a105481fa944515323d89bd2596c1de79f3d9bd1386266463934716eca0", "https://esm.sh/v128/*@dagger.io/dagger@0.6.3": "cb691a77c0cdaee22f2b8393731b5143c83ce22dbbea204cdbfd203768d15b64", "https://esm.sh/v128/@dagger.io/dagger@0.6.3/X-ZS8q/denonext/dagger.mjs": "fd0901784d75b99615b5409c3654b5c7edfc5ba377c9e1a5a67ffff4f7d3ac32", "https://esm.sh/v128/adm-zip@0.5.10": "d9c54d6d2dd788462781a57d923295bd79304e6fd74b242fd4b30e35b39c5dcf", @@ -73,6 +74,8 @@ "https://esm.sh/v128/which@2.0.2/denonext/which.mjs": "86bf76e4937edb7fa3464d7bb9a426ef273684d1cefbec5ba5f1bdcb5cafff91", "https://esm.sh/v128/yallist@4.0.0/denonext/yallist.mjs": "61f180d807dda50bac17028eda05d5722a3fecef6e98a9064e2353ea6864fd82", "https://esm.sh/v128/yaml@2.3.1/denonext/yaml.mjs": "71f677b4bfc69271af9d98db5194e354f9a1863955e208e26d32a9ef78bd89f5", + "https://esm.sh/v130/lodash.flatten@4.4.0/denonext/lodash.flatten.mjs": "8e86ab607deea15cc3c1acfb5eae278ecbc5b80f24167b4e8f4c56df3278cd55", + "https://esm.sh/v130/stringify-tree@1.1.1/denonext/stringify-tree.mjs": "40a9d40e0282b5432302a3da68b88aa11685bc0b8a0b70246168deed5c5773fe", "https://esm.sh/yaml@v2.3.1": "8ef3aee065e93b03cebf8fd5a3418bc30131344b7f2b8c8ae27bf9f277416087" }, "npm": { diff --git a/example/.fluentci/src/dagger/jobs.ts b/example/.fluentci/src/dagger/jobs.ts index 860e2f2..94cd04f 100644 --- a/example/.fluentci/src/dagger/jobs.ts +++ b/example/.fluentci/src/dagger/jobs.ts @@ -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") @@ -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"]) @@ -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"]) @@ -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"]) @@ -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") @@ -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"]) @@ -332,3 +340,21 @@ export const debugTests = async (client: Client, src = ".") => { console.log(result); }; + +export type JobExec = (client: Client, src?: string) => Promise; + +export const runnableJobs: Record = { + [Job.lintDebug]: lintDebug, + [Job.assembleDebug]: assembleDebug, + [Job.assembleRelease]: assembleRelease, + [Job.bundleRelease]: bundleRelease, + [Job.debugTests]: debugTests, +}; + +export const jobDescriptions: Record = { + [Job.lintDebug]: "Runs lintDebug", + [Job.assembleDebug]: "Assembles debug apk", + [Job.assembleRelease]: "Assembles release apk", + [Job.bundleRelease]: "Bundles release apk", + [Job.debugTests]: "Runs debug tests", +}; diff --git a/example/.fluentci/src/dagger/list_jobs.ts b/example/.fluentci/src/dagger/list_jobs.ts new file mode 100644 index 0000000..6b6cf48 --- /dev/null +++ b/example/.fluentci/src/dagger/list_jobs.ts @@ -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 + ) +); diff --git a/example/.fluentci/src/dagger/pipeline.ts b/example/.fluentci/src/dagger/pipeline.ts index 0669010..9fc311c 100644 --- a/example/.fluentci/src/dagger/pipeline.ts +++ b/example/.fluentci/src/dagger/pipeline.ts @@ -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; } @@ -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`); } diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index 860e2f2..94cd04f 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -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") @@ -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"]) @@ -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"]) @@ -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"]) @@ -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") @@ -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"]) @@ -332,3 +340,21 @@ export const debugTests = async (client: Client, src = ".") => { console.log(result); }; + +export type JobExec = (client: Client, src?: string) => Promise; + +export const runnableJobs: Record = { + [Job.lintDebug]: lintDebug, + [Job.assembleDebug]: assembleDebug, + [Job.assembleRelease]: assembleRelease, + [Job.bundleRelease]: bundleRelease, + [Job.debugTests]: debugTests, +}; + +export const jobDescriptions: Record = { + [Job.lintDebug]: "Runs lintDebug", + [Job.assembleDebug]: "Assembles debug apk", + [Job.assembleRelease]: "Assembles release apk", + [Job.bundleRelease]: "Bundles release apk", + [Job.debugTests]: "Runs debug tests", +}; diff --git a/src/dagger/list_jobs.ts b/src/dagger/list_jobs.ts new file mode 100644 index 0000000..6b6cf48 --- /dev/null +++ b/src/dagger/list_jobs.ts @@ -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 + ) +); diff --git a/src/dagger/pipeline.ts b/src/dagger/pipeline.ts index 0669010..9fc311c 100644 --- a/src/dagger/pipeline.ts +++ b/src/dagger/pipeline.ts @@ -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; } @@ -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`); }