1import { GcpEnvironment } from "@/GCP/Environment";
2import * as Effect from "effect/Effect";
3import { MinimumLogLevel } from "effect/References";
4import * as Schedule from "effect/Schedule";
5
6export const logLevel = Effect.provideService(
7 MinimumLogLevel,
8 process.env.DEBUG ? "Debug" : "Info",
9);
10
11export const runLifecycle = !process.env.FAST;
12
13// Releases need a blueprint image pushed to Artifact Registry. Set
14// GCP_TEST_SAAS_BLUEPRINT_PACKAGE (e.g.
15// `us-central1-docker.pkg.dev/<project>/blueprints/store:v1`) to run the
16// release, rollout, and unit-operation lifecycles.
17export const blueprintPackage = process.env.GCP_TEST_SAAS_BLUEPRINT_PACKAGE;
18export const runBlueprintLifecycle =
19 runLifecycle && blueprintPackage !== undefined;
20
21export const currentProject = GcpEnvironment.current.pipe(
22 Effect.map((env) => env.project),
23);
24export const location = "us-central1";
25
26export const waitUntilGone = <E extends { readonly _tag: string }, R>(
27 get: Effect.Effect<unknown, E, R>,
28) =>
29 get.pipe(
30 Effect.as("found" as const),
31 Effect.catchIf(
32 (error) => error._tag === "NotFound",
33 () => Effect.succeed("gone" as const),
34 ),
35 Effect.repeat({
36 schedule: Schedule.spaced("1 second"),
37 until: (status) => status === "gone",
38 times: 10,
39 }),
40 );