Skip to content

Commit

Permalink
add support for directory args
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Nov 19, 2023
1 parent 2367bee commit f19c985
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 16 deletions.
2 changes: 2 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts";
import { Client } from "./sdk/client.gen.ts";
export default Client;

export type { DirectoryID } from "./sdk/client.gen.ts";
export { Directory } from "./sdk/client.gen.ts";
export { connect, uploadContext } from "https://sdk.fluentci.io/v0.3.0/mod.ts";
export { brightGreen } from "https://deno.land/std@0.191.0/fmt/colors.ts";
export { withDevbox } from "https://nix.fluentci.io/v0.5.3/src/dagger/steps.ts";
Expand Down
2 changes: 2 additions & 0 deletions example/.fluentci/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export { assertEquals } from "https://deno.land/std@0.191.0/testing/asserts.ts";
import { Client } from "./sdk/client.gen.ts";
export default Client;

export type { DirectoryID } from "./sdk/client.gen.ts";
export { Directory } from "./sdk/client.gen.ts";
export { connect, uploadContext } from "https://sdk.fluentci.io/v0.3.0/mod.ts";
export { brightGreen } from "https://deno.land/std@0.191.0/fmt/colors.ts";
export { withDevbox } from "https://nix.fluentci.io/v0.5.3/src/dagger/steps.ts";
Expand Down
18 changes: 13 additions & 5 deletions example/.fluentci/src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client from "../../deps.ts";
import Client, { Directory } from "../../deps.ts";
import { connect } from "../../sdk/connect.ts";
import { getDirectory } from "./lib.ts";

export enum Job {
test = "test",
Expand All @@ -10,10 +11,13 @@ const NODE_VERSION = Deno.env.get("NODE_VERSION") || "18.16.1";

export const exclude = [".git", ".devbox", "node_modules", ".fluentci"];

export const test = async (src = ".", bunVersion?: string) => {
export const test = async (
src: string | Directory | undefined = ".",
bunVersion?: string
) => {
const BUN_VERSION = Deno.env.get("BUN_VERSION") || bunVersion || "1.0.3";
await connect(async (client: Client) => {
const context = client.host().directory(src);
const context = getDirectory(client, src);
const ctr = client
.pipeline(Job.test)
.container()
Expand Down Expand Up @@ -43,10 +47,14 @@ export const test = async (src = ".", bunVersion?: string) => {
return "All tests passed";
};

export const run = async (command: string, src = ".", bunVersion?: string) => {
export const run = async (
command: string,
src: string | Directory | undefined = ".",
bunVersion?: string
) => {
const BUN_VERSION = Deno.env.get("BUN_VERSION") || bunVersion || "1.0.3";
await connect(async (client: Client) => {
const context = client.host().directory(src);
const context = getDirectory(client, src);
let ctr = client
.pipeline(Job.run)
.container()
Expand Down
13 changes: 13 additions & 0 deletions example/.fluentci/src/dagger/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Client, { Directory, DirectoryID } from "../../deps.ts";

export const getDirectory = (
client: Client,
src: string | Directory | undefined = "."
) => {
if (typeof src === "string" && src.startsWith("core.Directory")) {
return client.directory({
id: src as DirectoryID,
});
}
return src instanceof Directory ? src : client.host().directory(src);
};
17 changes: 14 additions & 3 deletions example/.fluentci/src/dagger/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Query = queryType({
bunVersion: stringArg(),
},
resolve: async (_root, args, _ctx) =>
await test(args.src || undefined, args.bunVersion),
await test(args.src || undefined, args.bunVersion || undefined),
});
t.string("run", {
args: {
Expand All @@ -27,15 +27,26 @@ const Query = queryType({
bunVersion: stringArg(),
},
resolve: async (_root, args, _ctx) =>
await run(args.command, args.src, args.bunVersion),
await run(
args.command,
args.src || undefined,
args.bunVersion || undefined
),
});
},
});

export const schema = makeSchema({
const schema = makeSchema({
types: [Query],
outputs: {
schema: resolve(join(dirname(".."), dirname(".."), "schema.graphql")),
typegen: resolve(join(dirname(".."), dirname(".."), "gen", "nexus.ts")),
},
});

schema.description = JSON.stringify({
"test.src": "directory",
"run.src": "directory",
});

export { schema };
18 changes: 13 additions & 5 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client from "../../deps.ts";
import Client, { Directory } from "../../deps.ts";
import { connect } from "../../sdk/connect.ts";
import { getDirectory } from "./lib.ts";

export enum Job {
test = "test",
Expand All @@ -10,10 +11,13 @@ const NODE_VERSION = Deno.env.get("NODE_VERSION") || "18.16.1";

export const exclude = [".git", ".devbox", "node_modules", ".fluentci"];

export const test = async (src = ".", bunVersion?: string) => {
export const test = async (
src: string | Directory | undefined = ".",
bunVersion?: string
) => {
const BUN_VERSION = Deno.env.get("BUN_VERSION") || bunVersion || "1.0.3";
await connect(async (client: Client) => {
const context = client.host().directory(src);
const context = getDirectory(client, src);
const ctr = client
.pipeline(Job.test)
.container()
Expand Down Expand Up @@ -43,10 +47,14 @@ export const test = async (src = ".", bunVersion?: string) => {
return "All tests passed";
};

export const run = async (command: string, src = ".", bunVersion?: string) => {
export const run = async (
command: string,
src: string | Directory | undefined = ".",
bunVersion?: string
) => {
const BUN_VERSION = Deno.env.get("BUN_VERSION") || bunVersion || "1.0.3";
await connect(async (client: Client) => {
const context = client.host().directory(src);
const context = getDirectory(client, src);
let ctr = client
.pipeline(Job.run)
.container()
Expand Down
13 changes: 13 additions & 0 deletions src/dagger/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Client, { Directory, DirectoryID } from "../../deps.ts";

export const getDirectory = (
client: Client,
src: string | Directory | undefined = "."
) => {
if (typeof src === "string" && src.startsWith("core.Directory")) {
return client.directory({
id: src as DirectoryID,
});
}
return src instanceof Directory ? src : client.host().directory(src);
};
17 changes: 14 additions & 3 deletions src/dagger/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Query = queryType({
bunVersion: stringArg(),
},
resolve: async (_root, args, _ctx) =>
await test(args.src || undefined, args.bunVersion),
await test(args.src || undefined, args.bunVersion || undefined),
});
t.string("run", {
args: {
Expand All @@ -27,15 +27,26 @@ const Query = queryType({
bunVersion: stringArg(),
},
resolve: async (_root, args, _ctx) =>
await run(args.command, args.src, args.bunVersion),
await run(
args.command,
args.src || undefined,
args.bunVersion || undefined
),
});
},
});

export const schema = makeSchema({
const schema = makeSchema({
types: [Query],
outputs: {
schema: resolve(join(dirname(".."), dirname(".."), "schema.graphql")),
typegen: resolve(join(dirname(".."), dirname(".."), "gen", "nexus.ts")),
},
});

schema.description = JSON.stringify({
"test.src": "directory",
"run.src": "directory",
});

export { schema };

0 comments on commit f19c985

Please sign in to comment.