effect-ci 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/chunks/chunk-MZ5FQEN6.js +80 -0
- package/dist/chunks/chunk-U3DVQKHN.js +21 -0
- package/dist/chunks/chunk-WGBTI7DS.js +61 -0
- package/dist/chunks/chunk-WOG7K3QJ.js +84 -0
- package/dist/chunks/chunk-X4HGOXPL.js +2207 -0
- package/dist/chunks/local-bridge.js +1296 -0
- package/dist/chunks/src-FUJGARUK.js +1978 -0
- package/dist/command-diagnostics.js +12 -0
- package/dist/directory-deployment.js +167 -0
- package/dist/effect-ci.js +43 -0
- package/dist/index.js +103 -0
- package/dist/paths.js +8 -0
- package/dist/source-changes.js +11 -0
- package/dist/task-cache.js +64 -0
- package/dist/types/command-diagnostics.d.ts +24 -0
- package/dist/types/directory-deployment.d.ts +25 -0
- package/dist/types/index.d.ts +787 -0
- package/dist/types/observers.d.ts +35 -0
- package/dist/types/paths.d.ts +4 -0
- package/dist/types/source-changes.d.ts +34 -0
- package/dist/types/task-cache.d.ts +6 -0
- package/dist/types/turbo-bridge.d.ts +33 -0
- package/dist/types/turbo.d.ts +6 -0
- package/dist/types/vite-plus.d.ts +15 -0
- package/dist/vite-plus.js +8 -0
- package/package.json +88 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eric Clemmons
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# effect-ci
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed CI workflows you run locally, from coding agents, or on your own
|
|
4
|
+
Cloudflare-hosted Effect CI.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm i -D effect-ci # or: npx effect-ci <command>
|
|
8
|
+
npx effect-ci list # package.json scripts / Vite+ tasks become actions
|
|
9
|
+
npx effect-ci run build
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Authored workflows import the SDK from this package:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// .cloudflare/ci/workflow.ts
|
|
16
|
+
import * as CI from "effect-ci"
|
|
17
|
+
|
|
18
|
+
export const checkout = CI.action("checkout", function* () {
|
|
19
|
+
const source = yield* CI.Source
|
|
20
|
+
return () => source.checkout()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const build = CI.action("build", () => function* () {
|
|
24
|
+
const workspace = yield* checkout()
|
|
25
|
+
const vp = yield* CI.PackageManager.VitePlus(workspace)
|
|
26
|
+
yield* vp.install()
|
|
27
|
+
return yield* vp.run("build")
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export default CI.workflow("app", function* () {
|
|
31
|
+
return yield* build()
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Remote host
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npx effect-ci login https://effect-ci.<you>.workers.dev # cf access login; remembers the host
|
|
39
|
+
npx effect-ci push # push HEAD to Cloudflare Artifacts and follow the run
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The host comes from `EFFECT_CI_REMOTE_URL` (shell, `.env`, `.env.local`), then
|
|
43
|
+
the host saved by `effect-ci login` (`~/.config/effect-ci/config.json`).
|
|
44
|
+
`login` uses the [`cf` CLI](https://www.npmjs.com/package/cf) (`cf access login`
|
|
45
|
+
/ `cf access token`) and falls back to `cloudflared` when `cf` is not installed.
|
|
46
|
+
|
|
47
|
+
Agents skip the browser with an Access service token:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
CF_ACCESS_CLIENT_ID=… CF_ACCESS_CLIENT_SECRET=… npx effect-ci push --format=json
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requires Node.js 24 or newer.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pathPatterns
|
|
3
|
+
} from "./chunk-U3DVQKHN.js";
|
|
4
|
+
|
|
5
|
+
// ../ci/src/source-changes.ts
|
|
6
|
+
import * as Cause from "effect/Cause";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Glob from "effect/Glob";
|
|
9
|
+
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
10
|
+
var sha = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/;
|
|
11
|
+
var unavailable = { status: "unknown", reason: "unavailable" };
|
|
12
|
+
var normalize = (value) => {
|
|
13
|
+
if (value?.status !== "known") return value?.status === "unknown" && ["unavailable", "no-baseline", "plan"].includes(value.reason) ? value : unavailable;
|
|
14
|
+
if (typeof value.base !== "string" || !value.base || value.base.length > 512 || typeof value.head !== "string" || !value.head || value.head.length > 512 || !Array.isArray(value.paths) || value.paths.length > 1e5 || value.paths.some((path) => typeof path !== "string" || !path || path.startsWith("/") || path.includes("\0") || path.split("/").some((part) => part === ".." || part === ".")) || value.paths.reduce((length, path) => length + path.length + 1, 0) > 1048576) return unavailable;
|
|
15
|
+
return { status: "known", base: value.base, head: value.head, paths: [...new Set(value.paths)].sort() };
|
|
16
|
+
};
|
|
17
|
+
function gitSourceChangesCommand(selected, revision = "HEAD") {
|
|
18
|
+
const target = selected.head ?? revision;
|
|
19
|
+
if (typeof selected.base !== "string" || typeof target !== "string" || !selected.base || !target || selected.base.length > 512 || target.length > 512 || /[\x00-\x1f]/.test(selected.base + target)) return void 0;
|
|
20
|
+
return [
|
|
21
|
+
// Avoid index refresh writes while inspecting committed source.
|
|
22
|
+
"dirty=$(git --no-optional-locks -c core.fsmonitor=false status --porcelain --untracked-files=normal)",
|
|
23
|
+
'test -z "$dirty"',
|
|
24
|
+
`base=$(git rev-parse --verify --end-of-options ${quote(selected.base + "^{commit}")})`,
|
|
25
|
+
`head=$(git rev-parse --verify --end-of-options ${quote(target + "^{commit}")})`,
|
|
26
|
+
"current=$(git rev-parse --verify HEAD)",
|
|
27
|
+
'test "$current" = "$head"',
|
|
28
|
+
...selected.mergeBase ? ['base=$(git merge-base "$base" "$head")'] : [],
|
|
29
|
+
`printf '%s\\0%s\\0' "$base" "$head"`,
|
|
30
|
+
'git --no-pager diff --no-ext-diff --no-textconv --no-relative --no-renames --name-only -z "$base" "$head" --'
|
|
31
|
+
].join(" && ");
|
|
32
|
+
}
|
|
33
|
+
function parseGitSourceChanges(result) {
|
|
34
|
+
if (result.exitCode !== 0 || result.stdout.length > 1048576) return unavailable;
|
|
35
|
+
const [base, head, ...paths] = result.stdout.split("\0");
|
|
36
|
+
if (!base || !head || !sha.test(base) || !sha.test(head) || paths.pop() !== "" || paths.length > 1e5) return unavailable;
|
|
37
|
+
return normalize({ status: "known", base, head, paths });
|
|
38
|
+
}
|
|
39
|
+
function makeSourceQueries(source, options) {
|
|
40
|
+
let sequence = 0;
|
|
41
|
+
const changes = (comparison) => {
|
|
42
|
+
const query = Effect.gen(function* () {
|
|
43
|
+
if (options.mode === "plan") return { status: "unknown", reason: "plan" };
|
|
44
|
+
const selected = comparison ?? options.event.comparison ?? (source.reference?.kind === "local" && !options.event.revision ? { base: "refs/remotes/origin/HEAD", mergeBase: true } : void 0);
|
|
45
|
+
if (source.changes) return normalize(yield* source.changes(selected));
|
|
46
|
+
if (!selected) return { status: "unknown", reason: "no-baseline" };
|
|
47
|
+
if (source.reference && source.reference.kind !== "git" && source.reference.kind !== "local") return unavailable;
|
|
48
|
+
const command = gitSourceChangesCommand(selected, options.event.revision);
|
|
49
|
+
if (!command) return unavailable;
|
|
50
|
+
const workspace = yield* source.checkout();
|
|
51
|
+
const result = yield* options.executor.execute({
|
|
52
|
+
workspace,
|
|
53
|
+
command,
|
|
54
|
+
workflowId: options.workflowId,
|
|
55
|
+
stepId: "$source-changes",
|
|
56
|
+
commandIndex: ++sequence,
|
|
57
|
+
options: { timeout: "30 seconds", retries: { limit: 0, delay: 0, backoff: "constant" } },
|
|
58
|
+
onOutput: () => {
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return parseGitSourceChanges(result);
|
|
62
|
+
});
|
|
63
|
+
return query.pipe(Effect.timeout("30 seconds"), Effect.catchCause((cause) => Cause.hasFails(cause) || Cause.hasDies(cause) ? Effect.succeed({ status: "unknown", reason: "unavailable" }) : Effect.failCause(cause)));
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
checkout: () => source.checkout(),
|
|
67
|
+
...source.reference ? { reference: source.reference } : {},
|
|
68
|
+
changes,
|
|
69
|
+
changed: (patterns, comparison) => Effect.suspend(() => {
|
|
70
|
+
const matchers = pathPatterns(patterns).map((pattern) => Glob.make(pattern, { dot: true }));
|
|
71
|
+
return changes(comparison).pipe(Effect.map((result) => result.status === "unknown" || result.paths.some((path) => matchers.some((pattern) => Glob.match(pattern, path)))));
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
gitSourceChangesCommand,
|
|
78
|
+
parseGitSourceChanges,
|
|
79
|
+
makeSourceQueries
|
|
80
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ../ci/src/paths.ts
|
|
2
|
+
function pathPatterns(patterns) {
|
|
3
|
+
const values = typeof patterns === "string" ? [patterns] : [...patterns];
|
|
4
|
+
if (!values.length || values.length > 64) throw Error("Provide between 1 and 64 path globs");
|
|
5
|
+
for (const pattern of values) {
|
|
6
|
+
if (!pattern || pattern.length > 4096 || pattern.startsWith("/") || pattern.split("/").some((part) => part === ".." || part === ".") || /[\\\x00-\x1f]/.test(pattern))
|
|
7
|
+
throw Error("Expected a relative Effect glob");
|
|
8
|
+
}
|
|
9
|
+
return [...new Set(values)].sort();
|
|
10
|
+
}
|
|
11
|
+
function pathPrefixes(patterns) {
|
|
12
|
+
return [...new Set(patterns.map((pattern) => {
|
|
13
|
+
const parts = pattern.split("/"), first = parts.findIndex((part) => /[?*{\[]/.test(part));
|
|
14
|
+
return (first < 0 ? parts : parts.slice(0, first)).join("/");
|
|
15
|
+
}))];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
pathPatterns,
|
|
20
|
+
pathPrefixes
|
|
21
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// ../ci/src/command-diagnostics.ts
|
|
2
|
+
var marker = "\n[effect-ci-command-error-v1]";
|
|
3
|
+
var commandDiagnosticLimit = 32768;
|
|
4
|
+
var bytes = (s) => new TextEncoder().encode(s).length;
|
|
5
|
+
var tail = (s, n) => {
|
|
6
|
+
const value = n === 0 ? "" : s.slice(-n);
|
|
7
|
+
return /^[\uDC00-\uDFFF]/.test(value) ? value.slice(1) : value;
|
|
8
|
+
};
|
|
9
|
+
var boundedCommandOutput = (stdout, stderr) => {
|
|
10
|
+
const out = tail(stdout, 8192), err = tail(stderr, 8192);
|
|
11
|
+
return { stdout: out, stderr: err, truncated: out.length !== stdout.length || err.length !== stderr.length };
|
|
12
|
+
};
|
|
13
|
+
var human = (d) => `Command failed (${d.exitCode}): ${d.command}${d.output.stderr || d.output.stdout ? `
|
|
14
|
+
${d.output.stderr || d.output.stdout}` : ""}`;
|
|
15
|
+
function plain(value, keys) {
|
|
16
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return false;
|
|
17
|
+
const actual = Reflect.ownKeys(value);
|
|
18
|
+
return actual.length === keys.length && actual.every((k) => typeof k === "string" && keys.includes(k)) && keys.every((k) => {
|
|
19
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
20
|
+
return d && "value" in d;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function valid(value) {
|
|
24
|
+
if (!plain(value, ["version", "stepId", "command", "cwd", "exitCode", "output"]) || value.version !== 1 || typeof value.stepId !== "string" || value.stepId.length > 4096 || typeof value.command !== "string" || value.command.length > 16384 || typeof value.cwd !== "string" || value.cwd.length > 8192 || typeof value.exitCode !== "number" || !Number.isSafeInteger(value.exitCode) || value.exitCode === 0 || !plain(value.output, ["stdout", "stderr", "truncated"])) return false;
|
|
25
|
+
return typeof value.output.stdout === "string" && value.output.stdout.length <= 8192 && typeof value.output.stderr === "string" && value.output.stderr.length <= 8192 && typeof value.output.truncated === "boolean";
|
|
26
|
+
}
|
|
27
|
+
function encodeCommandDiagnostics(value) {
|
|
28
|
+
if (!valid(value)) return void 0;
|
|
29
|
+
let d = value;
|
|
30
|
+
for (; ; ) {
|
|
31
|
+
const message = human(d) + marker + JSON.stringify(d);
|
|
32
|
+
if (bytes(message) <= commandDiagnosticLimit) return message;
|
|
33
|
+
if (!d.output.stdout.length && !d.output.stderr.length) return void 0;
|
|
34
|
+
d = { ...d, output: {
|
|
35
|
+
stdout: tail(d.output.stdout, Math.floor(d.output.stdout.length / 2)),
|
|
36
|
+
stderr: tail(d.output.stderr, Math.floor(d.output.stderr.length / 2)),
|
|
37
|
+
truncated: true
|
|
38
|
+
} };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function decodeCommandDiagnostics(message, expected = {}) {
|
|
42
|
+
if (typeof message !== "string" || message.length > commandDiagnosticLimit || bytes(message) > commandDiagnosticLimit) return void 0;
|
|
43
|
+
const at = message.lastIndexOf(marker);
|
|
44
|
+
if (at < 0) return void 0;
|
|
45
|
+
let d;
|
|
46
|
+
try {
|
|
47
|
+
d = JSON.parse(message.slice(at + marker.length));
|
|
48
|
+
} catch {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
if (!valid(d) || message.slice(0, at) !== human(d)) return void 0;
|
|
52
|
+
for (const k of ["stepId", "command", "cwd"]) if (expected[k] !== void 0 && expected[k] !== d[k]) return void 0;
|
|
53
|
+
return d;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
commandDiagnosticLimit,
|
|
58
|
+
boundedCommandOutput,
|
|
59
|
+
encodeCommandDiagnostics,
|
|
60
|
+
decodeCommandDiagnostics
|
|
61
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// ../ci/src/vite-plus.ts
|
|
2
|
+
var marker = (change) => change === "added" ? "+" : change === "removed" ? "-" : "\xB1";
|
|
3
|
+
var describeChange = (change) => {
|
|
4
|
+
switch (change.kind) {
|
|
5
|
+
case "file":
|
|
6
|
+
return `${marker(change.change)} ${change.path}`;
|
|
7
|
+
case "env":
|
|
8
|
+
return `${marker(change.change)} env ${change.name}`;
|
|
9
|
+
case "config":
|
|
10
|
+
return `\xB1 config ${change.setting}`;
|
|
11
|
+
default:
|
|
12
|
+
return `\xB1 ${change.kind}`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var describeStatus = (cache) => {
|
|
16
|
+
switch (cache?.status) {
|
|
17
|
+
case void 0:
|
|
18
|
+
return ": not a cached command";
|
|
19
|
+
case "hit":
|
|
20
|
+
return `: cached${cache.baseline ? ` (${cache.baseline.durationMs}ms saved)` : ""}`;
|
|
21
|
+
case "changed":
|
|
22
|
+
return " changes:";
|
|
23
|
+
case "unknown":
|
|
24
|
+
return " changes, before an earlier step writes files:";
|
|
25
|
+
case "noBaseline":
|
|
26
|
+
return ": no cached run yet";
|
|
27
|
+
case "disabled":
|
|
28
|
+
return ": caching off";
|
|
29
|
+
case "error":
|
|
30
|
+
return `: cache error: ${cache.message ?? "unreadable"}`;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var cacheLog = (body) => {
|
|
34
|
+
const plan = JSON.parse(body);
|
|
35
|
+
if (plan.version !== 1 || typeof plan.plan !== "object" || plan.plan === null) {
|
|
36
|
+
throw new Error("Expected a version 1 Vite+ run plan from `vp run --dry-run --json`");
|
|
37
|
+
}
|
|
38
|
+
const lines = [];
|
|
39
|
+
const visit = (tasks, prefix) => {
|
|
40
|
+
for (const [id, task] of Object.entries(tasks)) {
|
|
41
|
+
task.steps.forEach((step, index) => {
|
|
42
|
+
const label = `${prefix}${id}${task.steps.length === 1 ? "" : ` step ${index + 1}`}`;
|
|
43
|
+
if (step.plan) return visit(step.plan, `${label} \u203A `);
|
|
44
|
+
const cache = step.cache;
|
|
45
|
+
lines.push({ level: "Info", message: `vite+ ${label}${describeStatus(cache)}` });
|
|
46
|
+
for (const change of cache?.changes ?? []) lines.push({ level: "Info", message: ` ${describeChange(change)}` });
|
|
47
|
+
if (cache?.changesPartial) lines.push({ level: "Info", message: " and maybe more" });
|
|
48
|
+
for (const name of cache?.baseline?.fingerprint?.env ?? []) lines.push({ level: "Debug", message: ` input env ${name}` });
|
|
49
|
+
for (const [path, input] of Object.entries(cache?.baseline?.fingerprint?.inputs ?? {})) {
|
|
50
|
+
lines.push({ level: "Debug", message: ` input ${path}${input.type === "file" ? "" : ` (${input.type})`}` });
|
|
51
|
+
}
|
|
52
|
+
const outputs = cache?.baseline?.outputs;
|
|
53
|
+
if (outputs === "notDownloaded") lines.push({ level: "Debug", message: " outputs not downloaded" });
|
|
54
|
+
else for (const path of outputs ?? []) lines.push({ level: "Debug", message: ` output ${path}` });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
visit(plan.plan, "");
|
|
59
|
+
return lines;
|
|
60
|
+
};
|
|
61
|
+
var untracedHits = (body) => {
|
|
62
|
+
const plan = JSON.parse(body);
|
|
63
|
+
const labels = [];
|
|
64
|
+
const visit = (tasks, prefix) => {
|
|
65
|
+
for (const [id, task] of Object.entries(tasks)) {
|
|
66
|
+
task.steps.forEach((step, index) => {
|
|
67
|
+
const label = `${prefix}${id}${task.steps.length === 1 ? "" : ` step ${index + 1}`}`;
|
|
68
|
+
if (step.plan) return visit(step.plan, `${label} \u203A `);
|
|
69
|
+
if (step.cache?.status !== "hit") return;
|
|
70
|
+
const paths = Object.keys(step.cache.baseline?.fingerprint?.inputs ?? {});
|
|
71
|
+
if (!paths.some((path) => path !== "." && path !== "node_modules" && !path.startsWith("node_modules/"))) {
|
|
72
|
+
labels.push(label);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
visit(plan.plan, "");
|
|
78
|
+
return labels;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
cacheLog,
|
|
83
|
+
untracedHits
|
|
84
|
+
};
|