Skip to content

Commit

Permalink
fix issue with dagger ids
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jan 24, 2024
1 parent 909f308 commit fc380e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function upload(
token: string | Secret
): Promise<string> {
await connect(async (client: Client) => {
const context = getDirectory(client, src);
const secret = getCodecovToken(client, token);
const context = await getDirectory(client, src);
const secret = await getCodecovToken(client, token);
if (!secret) {
console.error("CODECOV_TOKEN is not set. Skipping code coverage upload.");
Deno.exit(1);
Expand Down
28 changes: 19 additions & 9 deletions src/dagger/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,37 @@ import Client, {
SecretID,
} from "../../deps.ts";

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

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

0 comments on commit fc380e0

Please sign in to comment.