Skip to content

Commit

Permalink
remove dagger connect, 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 244aea2 commit 0d88599
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Run Dagger Pipelines
run: fluentci run deno_pipeline fmt lint test
- name: Upload to Codecov
run: fluentci run codecov_pipeline
run: dagger run deno run -A src/dagger/runner.ts
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7 changes: 0 additions & 7 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export default Client;

export type { DirectoryID, SecretID } from "./sdk/client.gen.ts";
export { Directory, Secret } 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";
export { stringifyTree } from "https://esm.sh/stringify-tree@1.1.1";
import gql from "https://esm.sh/graphql-tag@2.12.6";
export { gql };
Expand Down Expand Up @@ -37,11 +35,6 @@ export {
ERROR_CODES,
} from "https://esm.sh/@dagger.io/dagger@0.9.3";

export type {
CallbackFct,
ConnectOpts,
} from "https://sdk.fluentci.io/v0.3.0/mod.ts";

export * as FluentGitlabCI from "https://deno.land/x/fluent_gitlab_ci@v0.4.2/mod.ts";
export * as FluentGithubActions from "https://deno.land/x/fluent_github_actions@v0.2.1/mod.ts";
export * as FluentCircleCI from "https://deno.land/x/fluent_circleci@v0.2.5/mod.ts";
Expand Down
81 changes: 39 additions & 42 deletions src/dagger/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @module codecov
* @description Uploads code coverage to Codecov ☂️
*/
import Client, { Directory, Secret } from "../../deps.ts";
import { connect } from "../../sdk/connect.ts";
import { Directory, Secret } from "../../deps.ts";
import { dag } from "../../sdk/client.gen.ts";
import { getDirectory, getCodecovToken } from "./lib.ts";

export enum Job {
Expand All @@ -23,49 +23,46 @@ export async function upload(
src: string | Directory,
token: string | Secret
): Promise<string> {
await connect(async (client: Client) => {
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);
}
const context = await getDirectory(dag, src);
const secret = await getCodecovToken(dag, token);
if (!secret) {
console.error("CODECOV_TOKEN is not set. Skipping code coverage upload.");
Deno.exit(1);
}

const ctr = client
.pipeline(Job.upload)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
.withExec(["apk", "add", "curl", "git"])
.withExec([
"curl",
"-Os",
"https://uploader.codecov.io/latest/alpine/codecov",
])
.withExec(["chmod", "a+x", "codecov"])
.withExec(["mv", "codecov", "/usr/local/bin/codecov"])
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withSecretVariable("CODECOV_TOKEN", secret)
.withEnvVariable("CODECOV_URL", Deno.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")}`
: ""
}`,
]);
const ctr = dag
.pipeline(Job.upload)
.container()
.from("alpine:latest")
.withExec(["apk", "update"])
.withExec(["apk", "add", "curl", "git"])
.withExec([
"curl",
"-Os",
"https://uploader.codecov.io/latest/alpine/codecov",
])
.withExec(["chmod", "a+x", "codecov"])
.withExec(["mv", "codecov", "/usr/local/bin/codecov"])
.withDirectory("/app", context, { exclude })
.withWorkdir("/app")
.withSecretVariable("CODECOV_TOKEN", secret)
.withEnvVariable("CODECOV_URL", Deno.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")}`
: ""
}`,
]);

const result = await ctr.stdout();
const result = await ctr.stdout();

console.log(result);
});
return "Codecov upload complete.";
return result;
}

export type JobExec = (
Expand Down
6 changes: 1 addition & 5 deletions src/dagger/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { uploadContext } from "../../deps.ts";
import * as jobs from "./jobs.ts";

const { upload, runnableJobs, exclude } = jobs;
const { upload, runnableJobs } = jobs;

export default async function pipeline(src = ".", args: string[] = []) {
if (Deno.env.has("FLUENTCI_SESSION_ID")) {
await uploadContext(src, exclude);
}
if (args.length > 0) {
await runSpecificJobs(args as jobs.Job[]);
return;
Expand Down

0 comments on commit 0d88599

Please sign in to comment.