Skip to content

Commit

Permalink
use global dag client
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Mar 1, 2024
1 parent 8eb7301 commit 2f03226
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export async function upload(
src: string | Directory,
token: string | Secret
): Promise<string> {
const context = await getDirectory(dag, src);
const secret = await getCodecovToken(dag, token);
const context = await getDirectory(src);
const secret = await getCodecovToken(token);
if (!secret) {
console.error("CODECOV_TOKEN is not set. Skipping code coverage upload.");
Deno.exit(1);
Expand Down
28 changes: 12 additions & 16 deletions src/dagger/lib.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import { Directory, DirectoryID, Secret, SecretID } from "../../deps.ts";
import { Client } from "../../sdk/client.gen.ts";
import { dag } from "../../sdk/client.gen.ts";

export const getDirectory = async (
client: Client,
src: string | Directory | undefined = "."
) => {
if (src instanceof Directory) {
return src;
}
if (typeof src === "string") {
try {
const directory = client.loadDirectoryFromID(src as DirectoryID);
const directory = dag.loadDirectoryFromID(src as DirectoryID);
await directory.id();
return directory;
} catch (_) {
return client.host
? client.host().directory(src)
: client.currentModule().source().directory(src);
return dag.host
? dag.host().directory(src)
: dag.currentModule().source().directory(src);
}
}
return client.host
? client.host().directory(src)
: client.currentModule().source().directory(src);
return dag.host
? dag.host().directory(src)
: dag.currentModule().source().directory(src);
};

export const getCodecovToken = async (
client: Client,
token?: string | Secret
) => {
export const getCodecovToken = async (token?: string | Secret) => {
if (Deno.env.get("CODECOV_TOKEN")) {
return client.setSecret("CODECOV_TOKEN", Deno.env.get("CODECOV_TOKEN")!);
return dag.setSecret("CODECOV_TOKEN", Deno.env.get("CODECOV_TOKEN")!);
}
if (token && typeof token === "string") {
try {
const secret = client.loadSecretFromID(token as SecretID);
const secret = dag.loadSecretFromID(token as SecretID);
await secret.id();
return secret;
} catch (_) {
return client.setSecret("CODECOV_TOKEN", token);
return dag.setSecret("CODECOV_TOKEN", token);
}
}
if (token && token instanceof Secret) {
Expand Down

0 comments on commit 2f03226

Please sign in to comment.