返回 CodeWhale
update-homebrew-tap.sh
根目录 / .github / scripts / update-homebrew-tap.sh
1 #!/usr/bin/env bash
2 # Update the Homebrew tap after a release.
3 #
4 # The tap GitHub repo is still Hmbown/homebrew-deepseek-tui until Hunter
5 # renames it. The formula users type is `codewhale`. The legacy
6 # `deepseek-tui` formula stays as a deprecated alias for one overlap release.
7 #
8 # Expected environment:
9 # TAG – git tag, e.g. "v0.8.31"
10 # MANIFEST – path to codewhale-artifacts-sha256.txt
11 # TAP_REPO – owner/repo of the Homebrew tap
12 # TOKEN – PAT with contents:write on TAP_REPO (required unless
13 # FORMULA_OUTPUT renders locally for contract tests)
14 # FORMULA_OUTPUT – optional local render path used by contract tests
15 # FORMULA_LEGACY_OUTPUT – optional local render path for the alias formula
16
17 set -euo pipefail
18
19 : "${TAG:?}"
20 : "${MANIFEST:?}"
21 : "${TAP_REPO:?}"
22
23 if [ -z "${TOKEN:-}" ] && [ -z "${FORMULA_OUTPUT:-}" ]; then
24 echo "::error::No Homebrew tap token (TOKEN) configured; refusing to skip the tap update." >&2
25 exit 1
26 fi
27
28 VERSION="${TAG#v}"
29
30 die() { echo "::error::${1}" >&2; exit 1; }
31
32 sha() {
33 local file="${1:?}"
34 local val
35 val="$(awk -v f="${file}" '$2 == f {print $1; exit}' "${MANIFEST}")"
36 if [ -z "${val}" ]; then
37 die "Missing binary in checksum manifest: ${file}"
38 fi
39 echo "${val}"
40 }
41
42 # --- read checksums ---------------------------------------------------
43
44 # One compiled runtime exposed under the two supported command names.
45 SHA_COD_MACOS_ARM="$(sha codewhale-macos-arm64)"
46 SHA_CODEW_MACOS_ARM="$(sha codew-macos-arm64)"
47 SHA_COD_MACOS_X64="$(sha codewhale-macos-x64)"
48 SHA_CODEW_MACOS_X64="$(sha codew-macos-x64)"
49 SHA_COD_LINUX_ARM="$(sha codewhale-linux-arm64)"
50 SHA_CODEW_LINUX_ARM="$(sha codew-linux-arm64)"
51 SHA_COD_LINUX_X64="$(sha codewhale-linux-x64)"
52 SHA_CODEW_LINUX_X64="$(sha codew-linux-x64)"
53 readonly SHA_COD_MACOS_ARM SHA_CODEW_MACOS_ARM
54 readonly SHA_COD_MACOS_X64 SHA_CODEW_MACOS_X64
55 readonly SHA_COD_LINUX_ARM SHA_CODEW_LINUX_ARM
56 readonly SHA_COD_LINUX_X64 SHA_CODEW_LINUX_X64
57
58 # --- temp dirs --------------------------------------------------------
59
60 FORMULA_FILE="$(mktemp)"
61 LEGACY_FILE="$(mktemp)"
62 TAP_DIR="$(mktemp -d)"
63 trap 'rm -rf "${TAP_DIR}" "${FORMULA_FILE}" "${LEGACY_FILE}"' EXIT
64
65 readonly BASE_URL="https://github.com/codewhale-hq/CodeWhale/releases/download/${TAG}"
66
67 render_formula() {
68 local class_name="${1:?}"
69 local extra_header="${2:-}"
70 cat << EOF
71 class ${class_name} < Formula
72 desc "Agentic terminal for open-source and open-weight coding models"
73 homepage "https://github.com/codewhale-hq/CodeWhale"
74 version "${VERSION}"
75 license "MIT"
76 depends_on "node"
77 ${extra_header}
78 on_macos do
79 if Hardware::CPU.arm?
80 url "${BASE_URL}/codewhale-macos-arm64", using: :nounzip
81 sha256 "${SHA_COD_MACOS_ARM}"
82 resource "codew" do
83 url "${BASE_URL}/codew-macos-arm64", using: :nounzip
84 sha256 "${SHA_CODEW_MACOS_ARM}"
85 end
86 else
87 url "${BASE_URL}/codewhale-macos-x64", using: :nounzip
88 sha256 "${SHA_COD_MACOS_X64}"
89 resource "codew" do
90 url "${BASE_URL}/codew-macos-x64", using: :nounzip
91 sha256 "${SHA_CODEW_MACOS_X64}"
92 end
93 end
94 end
95
96 on_linux do
97 if Hardware::CPU.arm?
98 url "${BASE_URL}/codewhale-linux-arm64", using: :nounzip
99 sha256 "${SHA_COD_LINUX_ARM}"
100 resource "codew" do
101 url "${BASE_URL}/codew-linux-arm64", using: :nounzip
102 sha256 "${SHA_CODEW_LINUX_ARM}"
103 end
104 else
105 url "${BASE_URL}/codewhale-linux-x64", using: :nounzip
106 sha256 "${SHA_COD_LINUX_X64}"
107 resource "codew" do
108 url "${BASE_URL}/codew-linux-x64", using: :nounzip
109 sha256 "${SHA_CODEW_LINUX_X64}"
110 end
111 end
112 end
113
114 def install
115 bin.install Dir["*"].first => "codewhale"
116 resource("codew").stage { bin.install Dir["*"].first => "codew" }
117 end
118
119 test do
120 system "#{bin}/codewhale", "--version"
121 system "#{bin}/codew", "--version"
122 end
123 end
124 EOF
125 }
126
127 render_formula "Codewhale" "" > "${FORMULA_FILE}"
128 render_formula "DeepseekTui" " deprecate! date: \"2026-08-14\", because: \"renamed to codewhale\"
129 " > "${LEGACY_FILE}"
130
131 if [ -n "${FORMULA_OUTPUT:-}" ]; then
132 cp "${FORMULA_FILE}" "${FORMULA_OUTPUT}"
133 echo "Rendered Homebrew formula to ${FORMULA_OUTPUT}"
134 if [ -n "${FORMULA_LEGACY_OUTPUT:-}" ]; then
135 cp "${LEGACY_FILE}" "${FORMULA_LEGACY_OUTPUT}"
136 echo "Rendered legacy Homebrew formula to ${FORMULA_LEGACY_OUTPUT}"
137 fi
138 exit 0
139 fi
140
141 # --- push to tap repo --------------------------------------------------
142
143 ENCODED_TOKEN="$(printf '%s' "${TOKEN}" | python3 -c 'import sys,urllib.parse;print(urllib.parse.quote(sys.stdin.read(),safe=""))')"
144 TAP_URL="https://x-access-token:${ENCODED_TOKEN}@github.com/${TAP_REPO}.git"
145
146 git clone --depth 1 "${TAP_URL}" "${TAP_DIR}"
147
148 mkdir -p "${TAP_DIR}/Formula"
149 cp "${FORMULA_FILE}" "${TAP_DIR}/Formula/codewhale.rb"
150 cp "${LEGACY_FILE}" "${TAP_DIR}/Formula/deepseek-tui.rb"
151
152 cd "${TAP_DIR}"
153 git config user.name "github-actions[bot]"
154 git config user.email "github-actions[bot]@users.noreply.github.com"
155
156 git add Formula/codewhale.rb Formula/deepseek-tui.rb
157
158 if git diff --cached --quiet; then
159 echo "Formula unchanged (already at ${VERSION}); nothing to push."
160 exit 0
161 fi
162
163 git commit -m "chore: bump formula to ${VERSION}
164
165 Automated update from the release workflow."
166
167 git push origin HEAD:main
168 echo "Pushed formula update to ${TAP_REPO} (v${VERSION})"
169
169 lines BASH