Skip to content

Commit 55c3a99

Browse files
committed
use global dag client
1 parent dabdb59 commit 55c3a99

File tree

5 files changed

+41
-51
lines changed

5 files changed

+41
-51
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ jobs:
1313
- name: Setup Fluent CI
1414
uses: fluentci-io/setup-fluentci@v4
1515
- name: Run Dagger Pipelines
16-
run: fluentci run deno_pipeline fmt lint test
16+
run: |
17+
fluentci run deno_pipeline fmt lint test
18+
dagger -m github.com/fluent-ci-templates/github-pipeline@main functions
1719
- name: Upload to Codecov
1820
run: fluentci run codecov_pipeline
1921
env:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ releaseUpload(
6060
You can also use this pipeline programmatically:
6161

6262
```typescript
63-
import { releaseUpload } from "https://pkg.fluentci.io/[email protected].3/mod.ts";
63+
import { releaseUpload } from "https://pkg.fluentci.io/[email protected].4/mod.ts";
6464

6565
await releaseUpload(
6666
".",

ci.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { releaseUpload } from "https://pkg.fluentci.io/[email protected].3/mod.ts";
1+
import { releaseUpload } from "https://pkg.fluentci.io/[email protected].4/mod.ts";
22

33
await releaseUpload();

src/dagger/jobs.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Client, { Directory, Secret } from "../../deps.ts";
2-
import { connect } from "../../sdk/connect.ts";
1+
import { dag } from "../../sdk/client.gen.ts";
2+
import { Directory, Secret } from "../../deps.ts";
33
import { getDirectory, getGithubToken } from "./lib.ts";
44

55
export enum Job {
@@ -23,34 +23,30 @@ export async function releaseUpload(
2323
file: string,
2424
token: string | Secret
2525
): Promise<string> {
26-
await connect(async (client: Client) => {
27-
const TAG = Deno.env.get("TAG") || tag || "latest";
28-
const FILE = Deno.env.get("FILE") || file!;
29-
const context = await getDirectory(client, src);
30-
const secret = await getGithubToken(client, token);
26+
const TAG = Deno.env.get("TAG") || tag || "latest";
27+
const FILE = Deno.env.get("FILE") || file!;
28+
const context = await getDirectory(src);
29+
const secret = await getGithubToken(token);
3130

32-
if (!secret) {
33-
console.error("GH_TOKEN is required");
34-
Deno.exit(1);
35-
}
31+
if (!secret) {
32+
console.error("GH_TOKEN is required");
33+
Deno.exit(1);
34+
}
3635

37-
const ctr = client
38-
.pipeline(Job.releaseUpload)
39-
.container()
40-
.from("pkgxdev/pkgx:latest")
41-
.withExec(["apt-get", "update"])
42-
.withExec(["apt-get", "install", "-y", "ca-certificates"])
43-
.withExec(["pkgx", "install", "gh", "git"])
44-
.withMountedCache("/assets", client.cacheVolume("gh-release-assets"))
45-
.withDirectory("/app", context)
46-
.withWorkdir("/app")
47-
.withSecretVariable("GH_TOKEN", secret)
48-
.withExec(["gh", "release", "upload", TAG, FILE]);
36+
const ctr = dag
37+
.pipeline(Job.releaseUpload)
38+
.container()
39+
.from("pkgxdev/pkgx:latest")
40+
.withExec(["apt-get", "update"])
41+
.withExec(["apt-get", "install", "-y", "ca-certificates"])
42+
.withExec(["pkgx", "install", "gh", "git"])
43+
.withMountedCache("/assets", dag.cacheVolume("gh-release-assets"))
44+
.withDirectory("/app", context)
45+
.withWorkdir("/app")
46+
.withSecretVariable("GH_TOKEN", secret)
47+
.withExec(["gh", "release", "upload", TAG, FILE]);
4948

50-
await ctr.stdout();
51-
});
52-
53-
return "Done";
49+
return ctr.stdout();
5450
}
5551

5652
export type JobExec = (

src/dagger/lib.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1-
import Client, {
2-
Directory,
3-
DirectoryID,
4-
Secret,
5-
SecretID,
6-
} from "../../deps.ts";
1+
import { Directory, DirectoryID, Secret, SecretID } from "../../deps.ts";
2+
import { dag } from "../../sdk/client.gen.ts";
73

84
export const getDirectory = async (
9-
client: Client,
105
src: string | Directory | undefined = "."
116
) => {
127
if (src instanceof Directory) {
138
return src;
149
}
1510
if (typeof src === "string") {
1611
try {
17-
const directory = client.loadDirectoryFromID(src as DirectoryID);
12+
const directory = dag.loadDirectoryFromID(src as DirectoryID);
1813
await directory.id();
1914
return directory;
2015
} catch (_) {
21-
return client.host
22-
? client.host().directory(src)
23-
: client.currentModule().source().directory(src);
16+
return dag.host
17+
? dag.host().directory(src)
18+
: dag.currentModule().source().directory(src);
2419
}
2520
}
26-
return client.host
27-
? client.host().directory(src)
28-
: client.currentModule().source().directory(src);
21+
return dag.host
22+
? dag.host().directory(src)
23+
: dag.currentModule().source().directory(src);
2924
};
3025

31-
export const getGithubToken = async (
32-
client: Client,
33-
token?: string | Secret
34-
) => {
26+
export const getGithubToken = async (token?: string | Secret) => {
3527
if (Deno.env.get("GH_TOKEN")) {
36-
return client.setSecret("GH_TOKEN", Deno.env.get("GH_TOKEN")!);
28+
return dag.setSecret("GH_TOKEN", Deno.env.get("GH_TOKEN")!);
3729
}
3830
if (token && typeof token === "string") {
3931
try {
40-
const secret = client.loadSecretFromID(token as SecretID);
32+
const secret = dag.loadSecretFromID(token as SecretID);
4133
await secret.id();
4234
return secret;
4335
} catch (_) {
44-
return client.setSecret("GH_TOKEN", token);
36+
return dag.setSecret("GH_TOKEN", token);
4537
}
4638
}
4739
if (token && token instanceof Secret) {

0 commit comments

Comments
 (0)