Skip to content

Commit 25fc134

Browse files
authored
Merge pull request #45 from echohello-dev/codex/issue-17-homebrew-formula
feat(release): add homebrew formula packaging
2 parents 60888c3 + e3bcdee commit 25fc134

9 files changed

Lines changed: 239 additions & 2 deletions

File tree

‎.mise.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ run = "mise run test"
1515

1616
[tasks.build]
1717
run = "mise run install && bun scripts/build-release.ts"
18+
19+
[tasks.render-homebrew-formula]
20+
run = "mise run install && bun scripts/render-homebrew-formula.ts"

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Skillet installs, discovers, and updates `SKILL.md`-based skills across supporte
99
| Method | Command / Source | Status |
1010
| --- | --- | --- |
1111
| Binary release | Download from GitHub Releases | Planned |
12-
| Homebrew | `brew install skillet` | Planned |
12+
| Homebrew | `brew install skillet` | Configured |
1313
| Chocolatey | `choco install skillet` | Planned |
1414
| winget | `winget install skillet` | Planned |
1515
| npm / npx | `npx skillet ...` | Planned |
@@ -138,3 +138,7 @@ mise run ci
138138
```
139139

140140
AGENTS instructions live in `AGENTS.md`.
141+
142+
Distribution docs:
143+
144+
- Homebrew: `docs/distribution/homebrew.md`

‎docs/distribution/homebrew.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Homebrew Distribution
2+
3+
Skillet ships a Homebrew formula for direct `brew install` on macOS.
4+
5+
## Release Flow
6+
7+
1. Build release artifacts and checksums.
8+
2. Render `packaging/homebrew/skillet.rb` from checksums.
9+
3. Publish GitHub release assets for the same version.
10+
4. Push formula update to the tap repository.
11+
12+
## Commands
13+
14+
```bash
15+
mise run build
16+
bun scripts/write-checksums.ts
17+
mise run render-homebrew-formula -- --version <version>
18+
```
19+
20+
The renderer expects:
21+
22+
- `dist/skillet-darwin-arm64`
23+
- `dist/skillet-darwin-x64`
24+
- `dist/SHA256SUMS`
25+
26+
Install instructions for users:
27+
28+
```bash
29+
brew tap echohello-dev/tap
30+
brew install skillet
31+
```

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"scripts": {
1010
"dev": "bun src/cli.ts",
1111
"test": "vitest run",
12-
"build": "bun scripts/build-release.ts"
12+
"build": "bun scripts/build-release.ts",
13+
"render:homebrew": "bun scripts/render-homebrew-formula.ts"
1314
},
1415
"dependencies": {
1516
"cac": "^6.7.14",

‎packaging/homebrew/skillet.rb‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Skillet < Formula
2+
desc "Portable CLI for managing agent skills"
3+
homepage "https://github.com/echohello-dev/skillet"
4+
version "0.0.0"
5+
6+
on_arm do
7+
url "https://github.com/echohello-dev/skillet/releases/download/v0.0.0/skillet-darwin-arm64"
8+
sha256 "6942db0202df2fa04c2f6a2a17ce62930d7045bb7cc775a8dd3aff33125fac5c"
9+
end
10+
11+
on_intel do
12+
url "https://github.com/echohello-dev/skillet/releases/download/v0.0.0/skillet-darwin-x64"
13+
sha256 "9105b2738cac79fb96d45694d62946d20cf819838dd3448ebdbcfb5243e1c6e1"
14+
end
15+
16+
def install
17+
artifact = Hardware::CPU.arm? ? "skillet-darwin-arm64" : "skillet-darwin-x64"
18+
bin.install artifact => "skillet"
19+
end
20+
21+
test do
22+
assert_match "skillet/", shell_output("#{bin}/skillet --version")
23+
end
24+
end

‎scripts/render-homebrew-formula.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import { parseSha256Sums } from "../src/distribution/checksums";
4+
import { renderHomebrewFormula } from "../src/distribution/homebrew";
5+
6+
function main(): void {
7+
const args = process.argv.slice(2);
8+
const version = readArg(args, "--version") ?? readVersionFromPackageJson();
9+
const checksumsPath = path.resolve(readArg(args, "--checksums") ?? "dist/SHA256SUMS");
10+
const outputPath = path.resolve(readArg(args, "--output") ?? "packaging/homebrew/skillet.rb");
11+
const releaseUrlBase =
12+
readArg(args, "--release-url-base") ??
13+
`https://github.com/echohello-dev/skillet/releases/download/v${version}`;
14+
15+
if (!fs.existsSync(checksumsPath)) {
16+
throw new Error(`Checksums file not found: ${checksumsPath}`);
17+
}
18+
19+
const checksums = parseSha256Sums(fs.readFileSync(checksumsPath, "utf8"));
20+
const formula = renderHomebrewFormula({ version, releaseUrlBase, checksumsByArtifact: checksums });
21+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
22+
fs.writeFileSync(outputPath, formula);
23+
console.log(`Wrote Homebrew formula to ${outputPath}`);
24+
}
25+
26+
function readArg(args: string[], name: string): string | undefined {
27+
for (let i = 0; i < args.length; i += 1) {
28+
const token = args[i];
29+
if (token === name) {
30+
const next = args[i + 1];
31+
if (!next || next.startsWith("--")) {
32+
throw new Error(`Missing value for ${name}`);
33+
}
34+
return next;
35+
}
36+
37+
const prefix = `${name}=`;
38+
if (token.startsWith(prefix)) {
39+
const value = token.slice(prefix.length);
40+
if (value.length === 0) {
41+
throw new Error(`Missing value for ${name}`);
42+
}
43+
return value;
44+
}
45+
}
46+
47+
return undefined;
48+
}
49+
50+
function readVersionFromPackageJson(): string {
51+
const packageJsonPath = path.resolve("package.json");
52+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as { version?: string };
53+
if (!packageJson.version || packageJson.version.length === 0) {
54+
throw new Error("package.json version is missing");
55+
}
56+
57+
return packageJson.version;
58+
}
59+
60+
main();

‎src/distribution/checksums.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function parseSha256Sums(contents: string): Map<string, string> {
2+
const checksums = new Map<string, string>();
3+
4+
for (const rawLine of contents.split(/\r?\n/)) {
5+
const line = rawLine.trim();
6+
if (line.length === 0) {
7+
continue;
8+
}
9+
10+
const match = /^([a-fA-F0-9]{64})\s{2}(.+)$/.exec(line);
11+
if (!match) {
12+
throw new Error(`Invalid SHA256SUMS line: ${rawLine}`);
13+
}
14+
15+
checksums.set(match[2], match[1].toLowerCase());
16+
}
17+
18+
return checksums;
19+
}

‎src/distribution/homebrew.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const DARWIN_ARM64_ARTIFACT = "skillet-darwin-arm64";
2+
const DARWIN_X64_ARTIFACT = "skillet-darwin-x64";
3+
4+
export type HomebrewFormulaOptions = {
5+
version: string;
6+
releaseUrlBase: string;
7+
checksumsByArtifact: Map<string, string>;
8+
};
9+
10+
export function renderHomebrewFormula(options: HomebrewFormulaOptions): string {
11+
const arm64Sha = requireChecksum(options.checksumsByArtifact, DARWIN_ARM64_ARTIFACT);
12+
const x64Sha = requireChecksum(options.checksumsByArtifact, DARWIN_X64_ARTIFACT);
13+
const releaseUrlBase = options.releaseUrlBase.replace(/\/+$/, "");
14+
15+
return `class Skillet < Formula
16+
desc "Portable CLI for managing agent skills"
17+
homepage "https://github.com/echohello-dev/skillet"
18+
version "${options.version}"
19+
20+
on_arm do
21+
url "${releaseUrlBase}/${DARWIN_ARM64_ARTIFACT}"
22+
sha256 "${arm64Sha}"
23+
end
24+
25+
on_intel do
26+
url "${releaseUrlBase}/${DARWIN_X64_ARTIFACT}"
27+
sha256 "${x64Sha}"
28+
end
29+
30+
def install
31+
artifact = Hardware::CPU.arm? ? "${DARWIN_ARM64_ARTIFACT}" : "${DARWIN_X64_ARTIFACT}"
32+
bin.install artifact => "skillet"
33+
end
34+
35+
test do
36+
assert_match "skillet/", shell_output("#{bin}/skillet --version")
37+
end
38+
end
39+
`;
40+
}
41+
42+
function requireChecksum(checksumsByArtifact: Map<string, string>, artifactName: string): string {
43+
const checksum = checksumsByArtifact.get(artifactName);
44+
if (!checksum) {
45+
throw new Error(`Missing checksum for artifact: ${artifactName}`);
46+
}
47+
48+
return checksum;
49+
}
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 { parseSha256Sums } from "../../src/distribution/checksums";
3+
import { renderHomebrewFormula } from "../../src/distribution/homebrew";
4+
5+
describe("parseSha256Sums", () => {
6+
it("parses checksum lines into a map", () => {
7+
const checksums = parseSha256Sums(
8+
[
9+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa skillet-darwin-arm64",
10+
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb skillet-darwin-x64",
11+
].join("\n"),
12+
);
13+
14+
expect(checksums.get("skillet-darwin-arm64")).toBe(
15+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
16+
);
17+
expect(checksums.get("skillet-darwin-x64")).toBe(
18+
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
19+
);
20+
});
21+
});
22+
23+
describe("renderHomebrewFormula", () => {
24+
it("renders an arch-aware formula", () => {
25+
const checksums = new Map<string, string>([
26+
["skillet-darwin-arm64", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
27+
["skillet-darwin-x64", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"],
28+
]);
29+
30+
const formula = renderHomebrewFormula({
31+
version: "1.2.3",
32+
releaseUrlBase: "https://github.com/echohello-dev/skillet/releases/download/v1.2.3",
33+
checksumsByArtifact: checksums,
34+
});
35+
36+
expect(formula).toContain('version "1.2.3"');
37+
expect(formula).toContain(
38+
'url "https://github.com/echohello-dev/skillet/releases/download/v1.2.3/skillet-darwin-arm64"',
39+
);
40+
expect(formula).toContain(
41+
'url "https://github.com/echohello-dev/skillet/releases/download/v1.2.3/skillet-darwin-x64"',
42+
);
43+
expect(formula).toContain('sha256 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"');
44+
expect(formula).toContain('sha256 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"');
45+
});
46+
});

0 commit comments

Comments
 (0)