Skip to content
Source
Sign inSign up
samwillis/hackernews-realtime
Open History to see the last commit

deploy-ingest.mjs

28 lines1.2 KB

1import { execFileSync } from "node:child_process";
2const project = process.env.INGEST_PROJECT_ID;
3const branch = process.env.INGEST_BRANCH_ID;
4if (!project || !branch)
5 throw new Error("Set the dedicated INGEST_PROJECT_ID and INGEST_BRANCH_ID");
6const base = [
7 "scripts/neon.mjs",
8 "--profile",
9 process.env.NEON_PROFILE ?? "staging",
10];
11const target = ["--project-id", project, "--branch", branch];
12const run = (args, capture = false) =>
13 execFileSync(process.execPath, [...base, ...args], {
14 stdio: capture ? ["ignore", "pipe", "inherit"] : "inherit",
15 encoding: "utf8",
16 });
17run(["deploy", ...target, "--env", ".env.local", "--no-env-pull", "--yes"]);
18if (process.env.ENABLE_INGEST === "1") {
19 const result = JSON.parse(
20 run(["triggers", "list", ...target, "--output", "json"], true),
21 );
22 const triggers = Array.isArray(result) ? result : result.triggers;
23 const trigger = triggers.find((value) => value.name === "hnminute");
24 if (!trigger) throw new Error("The hnminute trigger was not created");
25 if (!trigger.trigger_id)
26 throw new Error("Missing trigger_id in CLI response");
27 run(["triggers", "update", trigger.trigger_id, ...target, "--enabled=true"]);