Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

45 linesCodeBlameRaw
1// Generate a tap formula from a verified release manifest. Does not publish.
2import assert from "node:assert/strict";
3import { readFileSync, writeFileSync } from "node:fs";
4import { pathToFileURL } from "node:url";
5
6export function homebrewFormula(manifest) {
7 assert.match(manifest.version, /^\d+\.\d+\.\d+$/, "A stable release is required");
8 const blocks = ["macos", "linux"].map((os) => {
9 const architectures = [["arm", "arm64"], ["intel", "x64"]].map(([arch, platform]) => {
10 const name = `g1t-${os}-${platform}`;
11 const file = manifest.files[`${os}-${platform}`];
12 assert.equal(file?.name, name, `Missing or invalid ${name}`);
13 assert.match(file.sha256, /^[a-f0-9]{64}$/, `Invalid checksum for ${name}`);
14 return ` on_${arch} do\n url "https://g1t.sh/downloads/cli/${manifest.version}/${name}", using: :nounzip\n sha256 "${file.sha256}"\n end`;
15 });
16 return ` on_${os} do\n${architectures.join("\n")}\n end`;
17 });
18 return `# Generated by scripts/cli-homebrew.mjs from a verified release manifest.
19class G1t < Formula
20 desc "Work with g1t repositories, issues and pull requests"
21 homepage "https://g1t.sh"
22 version "${manifest.version}"
23 license "MIT"
24
25${blocks.join("\n\n")}
26
27 def install
28 os = OS.mac? ? "macos" : "linux"
29 arch = Hardware::CPU.arm? ? "arm64" : "x64"
30 bin.install "g1t-#{os}-#{arch}" => "g1t"
31 end
32
33 test do
34 assert_match version.to_s, shell_output("#{bin}/g1t --version")
35 assert_match "Usage:", shell_output("#{bin}/g1t issue --help")
36 end
37end
38`;
39}
40
41if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
42 const [, , manifest, destination] = process.argv;
43 assert.ok(manifest && destination, "usage: node scripts/cli-homebrew.mjs VERIFIED_MANIFEST FORMULA.rb");
44 writeFileSync(destination, homebrewFormula(JSON.parse(readFileSync(manifest, "utf8"))));
45}