Skip to content

Commit 2674b23

Browse files
committed
feat(ts): add aptBase() factory for cross-toolchain apt sharing
1 parent b80b54e commit 2674b23

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

dsls/harmont-ts/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export {
2121
} from "./triggers.js";
2222
export { pipeline, type PipelineIR, type PipelineOptions } from "./pipeline.js";
2323
export { target, clearTargetCache } from "./target.js";
24+
export { aptBase } from "./toolchains/shared.js";
2425
export { renderEnvelope, type PipelineDefinition } from "./envelope.js";

dsls/harmont-ts/src/toolchains/shared.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export function nodeInstallCmd(version: string): string {
1212
return `curl -fsSL https://deb.nodesource.com/setup_${major}.x | bash - && apt-get install -y nodejs`;
1313
}
1414

15+
export function aptBase(opts: {
16+
packages: readonly string[];
17+
image?: string;
18+
label?: string;
19+
}): Step {
20+
return scratch({ image: opts.image }).sh(aptInstallCmd(opts.packages), {
21+
label: opts.label ?? ":apt: base",
22+
cache: ttl(APT_TTL_SECONDS),
23+
});
24+
}
25+
1526
export function makeInstallChain(opts: {
1627
aptPackages: readonly string[];
1728
installCmd: string;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, expect, it } from "vitest";
2+
import { aptBase } from "../../src/toolchains/shared.js";
3+
import { rust } from "../../src/toolchains/rust.js";
4+
import { uv } from "../../src/toolchains/py/uv.js";
5+
import { pipeline } from "../../src/pipeline.js";
6+
7+
describe("aptBase", () => {
8+
it("creates a step with apt-get install", () => {
9+
const base = aptBase({ packages: ["curl", "ca-certificates"] });
10+
expect(base._cmd).toContain(
11+
"apt-get update && apt-get install -y curl ca-certificates",
12+
);
13+
});
14+
15+
it("default label is :apt: base", () => {
16+
const base = aptBase({ packages: ["curl"] });
17+
expect(base._label).toBe(":apt: base");
18+
});
19+
20+
it("accepts custom label", () => {
21+
const base = aptBase({ packages: ["curl"], label: ":lock: deps" });
22+
expect(base._label).toBe(":lock: deps");
23+
});
24+
25+
it("shared across rust and python toolchains", () => {
26+
const base = aptBase({
27+
packages: [
28+
"curl",
29+
"ca-certificates",
30+
"build-essential",
31+
"pkg-config",
32+
"libssl-dev",
33+
"python3",
34+
"python3-venv",
35+
],
36+
});
37+
const r = rust({ base });
38+
const p = uv({ path: "dsls/harmont-py", base });
39+
const ir = pipeline(r.build(), p.test(), { defaultImage: "ubuntu:24.04" });
40+
const cmds = ir.graph.nodes.map(
41+
(n: { step: { cmd: string } }) => n.step.cmd,
42+
);
43+
const aptSteps = cmds.filter((c: string) => c.includes("apt-get install"));
44+
expect(aptSteps).toHaveLength(1);
45+
});
46+
});

0 commit comments

Comments
 (0)