Skip to content

Commit

Permalink
make it work with Node.js and Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Mar 3, 2024
1 parent 1223137 commit 1dc73c4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ jobs:
run: dagger run deno run -A src/dagger/runner.ts
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
publish:
needs: tests
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Publish package
run: npx jsr publish
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dagger call upload --src . --token CODECOV_TOKEN
| CODECOV_URL | Your Codecov URL. | Optional |
| COVERAGE_FILE | Your coverage file. | Optional |

## 📝 Jobs
## Jobs

| Job | Description |
|---------|----------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fluentci/codecov",
"version": "0.9.0",
"version": "0.9.1",
"exports": "./mod.ts",
"importMap": "import_map.json",
"tasks": {
Expand Down
6 changes: 5 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { assertEquals } from "jsr:@std/testing@0.218.2/asserts";

export type { DirectoryID, SecretID } from "./sdk/client.gen.ts";
export { Directory, Secret } from "./sdk/client.gen.ts";
export { dag, Directory, Secret, Container } from "./sdk/client.gen.ts";
export { brightGreen } from "jsr:@std/fmt@0.218.2/colors";
export { stringifyTree } from "npm:stringify-tree@1.1.1";
import { gql } from "npm:graphql-request@6.1.0";
Expand All @@ -14,6 +14,10 @@ const snakeCase = _.default.snakeCase;
const camelCase = _.default.camelCase;
export { snakeCase, camelCase };

import * as env from "jsr:@tsirysndr/env-js";
export { env };
export { exit } from "jsr:@tsirysndr/exit-js";

export { ClientError, GraphQLClient } from "npm:graphql-request@6.1.0";
export {
DaggerSDKError,
Expand Down
16 changes: 6 additions & 10 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* @module codecov
* @description Uploads code coverage to Codecov ☂️
*/
import { Directory, Secret } from "../../deps.ts";
import { dag } from "../../sdk/client.gen.ts";
import { dag, Directory, Secret, env, exit } from "../../deps.ts";
import { getDirectory, getCodecovToken } from "./lib.ts";

export enum Job {
Expand All @@ -27,7 +26,8 @@ export async function upload(
const secret = await getCodecovToken(token);
if (!secret) {
console.error("CODECOV_TOKEN is not set. Skipping code coverage upload.");
Deno.exit(1);
exit(1);
return "";
}

const ctr = dag
Expand All @@ -46,18 +46,14 @@ export async function upload(
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withSecretVariable("CODECOV_TOKEN", secret)
.withEnvVariable("CODECOV_URL", Deno.env.get("CODECOV_URL") || "")
.withEnvVariable("CODECOV_URL", env.get("CODECOV_URL") || "")
.withExec(["ls", "-la"])
.withExec([
"sh",
"-c",
`codecov -t $CODECOV_TOKEN ${
Deno.env.get("CODECOV_URL") ? `--url $CODECOV_URL` : ""
} ${
Deno.env.get("COVERAGE_FILE")
? `-f ${Deno.env.get("COVERAGE_FILE")}`
: ""
}`,
env.get("CODECOV_URL") ? `--url $CODECOV_URL` : ""
} ${env.get("COVERAGE_FILE") ? `-f ${env.get("COVERAGE_FILE")}` : ""}`,
]);

const result = await ctr.stdout();
Expand Down
14 changes: 10 additions & 4 deletions src/dagger/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Directory, DirectoryID, Secret, SecretID } from "../../deps.ts";
import { dag } from "../../sdk/client.gen.ts";
import {
dag,
env,
Directory,
DirectoryID,
Secret,
SecretID,
} from "../../deps.ts";

export const getDirectory = async (
src: string | Directory | undefined = "."
Expand All @@ -24,8 +30,8 @@ export const getDirectory = async (
};

export const getCodecovToken = async (token?: string | Secret) => {
if (Deno.env.get("CODECOV_TOKEN")) {
return dag.setSecret("CODECOV_TOKEN", Deno.env.get("CODECOV_TOKEN")!);
if (env.get("CODECOV_TOKEN")) {
return dag.setSecret("CODECOV_TOKEN", env.get("CODECOV_TOKEN")!);
}
if (token && typeof token === "string") {
try {
Expand Down
5 changes: 3 additions & 2 deletions src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as jobs from "./jobs.ts";
import { env } from "../../deps.ts";

const { upload, runnableJobs } = jobs;

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

await upload(src, Deno.env.get("CODECOV_TOKEN") || "");
await upload(src, env.get("CODECOV_TOKEN") || "");
}

async function runSpecificJobs(args: jobs.Job[]) {
Expand All @@ -17,6 +18,6 @@ async function runSpecificJobs(args: jobs.Job[]) {
if (!job) {
throw new Error(`Job ${name} not found`);
}
await job(".", Deno.env.get("CODECOV_TOKEN") || "");
await job(".", env.get("CODECOV_TOKEN") || "");
}
}

0 comments on commit 1dc73c4

Please sign in to comment.