Skip to content

Commit

Permalink
Merge pull request #15 from fluentci-io/feat/post-fluentci-agent-logs
Browse files Browse the repository at this point in the history
Feat/post fluentci agent logs
  • Loading branch information
tsirysndr authored Jan 10, 2024
2 parents cff8737 + 559be86 commit 8a68325
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fluentci # Run the pipeline
fluentci --help

Usage: fluentci [pipeline] [jobs...]
Version: 0.10.2
Version: 0.10.3

Description:

Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { brightGreen } from "./deps.ts";
export async function main() {
await new Command()
.name("fluentci")
.version("0.10.2")
.version("0.10.3")
.description(
`
.
Expand Down
25 changes: 20 additions & 5 deletions src/cmd/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ const spawnFluentCI = async (
jobs: [string, ...Array<string>],
clientId: string
) => {
const accessToken = await getAccessToken();
const headers = {
Authorization: `Bearer ${accessToken}`,
};
const command = new Deno.Command("dagger", {
args: ["--progress", "plain", "run", "fluentci", "run", pipeline, ...jobs],
cwd: `${dir("home")}/.fluentci/builds/${project_id}/${sha256}`,
Expand All @@ -160,28 +164,39 @@ const spawnFluentCI = async (
_EXPERIMENTAL_DAGGER_CLOUD_URL: `https://events.fluentci.io?id=${
"build-" + clientId
}&project_id=${project_id}`,
DAGGER_CLOUD_TOKEN: Deno.env.get("DAGGER_TOKEN") || "123",
DAGGER_CLOUD_TOKEN: Deno.env.get("DAGGER_CLOUD_TOKEN") || "123",
},
});
const process = command.spawn();
const logs = "";
const writable = new WritableStream({
write: (chunk) => {
const text = new TextDecoder().decode(chunk);
logger.info(text);
logs.concat(text);
fetch(`${FLUENTCI_EVENTS_URL}?client_id=${clientId}`, {
method: "POST",
body: text,
headers,
}).catch((e) => logger.error(e.message));
},
});

await process.stderr?.pipeTo(writable);
const { code } = await process.status;

fetch(`${FLUENTCI_EVENTS_URL}?client_id=${clientId}`, {
method: "POST",
body: `fluentci_exit=${code}`,
}).catch((e) => logger.error(e.message));
Promise.all([
fetch(`${FLUENTCI_EVENTS_URL}?client_id=${clientId}`, {
method: "POST",
body: `fluentci_exit=${code}`,
headers,
}),
fetch(`${FLUENTCI_EVENTS_URL}?client_id=${clientId}`, {
method: "POST",
body: `fluentci_logs=${logs}`,
headers,
}),
]).catch((e) => logger.error(e.message));
};

export default startAgent;

0 comments on commit 8a68325

Please sign in to comment.