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.

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