-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.sh
More file actions
executable file
·271 lines (231 loc) · 7.03 KB
/
Copy pathapp.sh
File metadata and controls
executable file
·271 lines (231 loc) · 7.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
usage() {
cat <<'EOF'
Usage:
./app.sh --build
./app.sh --release
EOF
}
log() {
printf '[onui] %s\n' "$1"
}
fail() {
printf '[onui] ERROR: %s\n' "$1" >&2
exit 1
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"
}
node_major() {
node -p "process.versions.node.split('.')[0]"
}
current_version() {
node -p "require('./package.json').version"
}
next_patch_version() {
node -e "const p=require('./package.json');const [a,b,c]=p.version.split('.').map(Number);console.log([a,b,c+1].join('.'));"
}
preflight_common() {
require_cmd node
require_cmd pnpm
require_cmd git
require_cmd zip
local major
major="$(node_major)"
if [ "$major" -lt 20 ]; then
fail "Node 20+ required. Found Node $(node -v)"
fi
}
assert_clean_tree() {
[ -z "$(git status --porcelain)" ] || fail "Release requires a clean git working tree."
}
assert_main_branch() {
local branch
branch="$(git rev-parse --abbrev-ref HEAD)"
[ "$branch" = "main" ] || fail "Release must run on main. Current branch: $branch"
}
assert_gh_auth() {
require_cmd gh
gh auth status >/dev/null 2>&1 || fail "GitHub CLI is not authenticated. Run: gh auth login"
}
sync_version() {
local version="$1"
node scripts/release/sync-version.mjs "$version"
}
run_build_pipeline() {
log "Installing dependencies"
pnpm install --frozen-lockfile
log "Building @onui/core"
pnpm --filter @onui/core run build
log "Building @onui/extension"
pnpm --filter @onui/extension run build
log "Building @onui/mcp-server"
pnpm --filter @onui/mcp-server run build
log "Running MCP tests"
pnpm --filter @onui/mcp-server run test
log "Running MCP doctor smoke check (warnings allowed)"
local report
report="$(node packages/mcp-server/dist/bin/onui-cli.js doctor --json || true)"
printf '%s\n' "$report" | node -e '
const fs = require("node:fs");
const input = fs.readFileSync(0, "utf8").trim();
const report = JSON.parse(input);
if (report.status === "error") process.exit(1);
' || fail "MCP doctor reported error status."
}
sha256_file() {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$1"
else
shasum -a 256 "$1"
fi
}
package_artifacts() {
local version="$1"
local artifacts_dir="artifacts/v${version}"
local ext_dist_dir="packages/extension/dist"
local ext_firefox_dist_dir="packages/extension/dist-firefox"
local mcp_bundle_dir
local sh_template="scripts/install/install.sh.template"
local ps_template="scripts/install/install.ps1.template"
[ -d "$ext_dist_dir" ] || fail "Missing extension dist at $ext_dist_dir"
[ -d "$ext_firefox_dist_dir" ] || fail "Missing Firefox extension dist at $ext_firefox_dist_dir"
[ -f "$sh_template" ] || fail "Missing installer template: $sh_template"
[ -f "$ps_template" ] || fail "Missing installer template: $ps_template"
log "Packaging artifacts into $artifacts_dir"
rm -rf "$artifacts_dir"
mkdir -p "$artifacts_dir"
local unpacked_zip="$artifacts_dir/onui-extension-unpacked-v${version}.zip"
local cws_zip="$artifacts_dir/onui-chrome-web-store-v${version}.zip"
local edge_zip="$artifacts_dir/onui-edge-add-ons-v${version}.zip"
local firefox_zip="$artifacts_dir/onui-firefox-add-ons-v${version}.zip"
local mcp_bundle_zip="$artifacts_dir/onui-mcp-bundle-v${version}.zip"
local install_sh="$artifacts_dir/install.sh"
local install_ps1="$artifacts_dir/install.ps1"
local firefox_tmp_dir
(
cd "$ext_dist_dir"
zip -qr "../../../$unpacked_zip" .
)
firefox_tmp_dir="$(mktemp -d)"
cp -R "$ext_firefox_dist_dir/." "$firefox_tmp_dir/"
rm -rf "$firefox_tmp_dir/.vite"
(
cd "$firefox_tmp_dir"
zip -qr "$ROOT_DIR/$firefox_zip" .
)
rm -rf "$firefox_tmp_dir"
local tmp_dir
tmp_dir="$(mktemp -d)"
cp -R "$ext_dist_dir/." "$tmp_dir/"
rm -rf "$tmp_dir/.vite"
node -e "
const fs = require('node:fs');
const p = '$tmp_dir/manifest.json';
const m = JSON.parse(fs.readFileSync(p, 'utf8'));
delete m.key;
fs.writeFileSync(p, JSON.stringify(m, null, 2) + '\n', 'utf8');
"
(
cd "$tmp_dir"
zip -qr "$ROOT_DIR/$cws_zip" .
zip -qr "$ROOT_DIR/$edge_zip" .
)
rm -rf "$tmp_dir"
mcp_bundle_dir="$(mktemp -d)"
pnpm --filter @onui/mcp-server --prod deploy "$mcp_bundle_dir/mcp"
if [ -d "$mcp_bundle_dir/mcp/node_modules/.pnpm/node_modules" ]; then
mkdir -p "$mcp_bundle_dir/mcp/node_modules_flat"
cp -RL "$mcp_bundle_dir/mcp/node_modules/.pnpm/node_modules/." "$mcp_bundle_dir/mcp/node_modules_flat/" 2>/dev/null || true
rm -rf "$mcp_bundle_dir/mcp/node_modules"
mv "$mcp_bundle_dir/mcp/node_modules_flat" "$mcp_bundle_dir/mcp/node_modules"
fi
(
cd "$mcp_bundle_dir/mcp"
zip -qr "$ROOT_DIR/$mcp_bundle_zip" .
)
rm -rf "$mcp_bundle_dir"
sed "s/__VERSION__/${version}/g" "$sh_template" > "$install_sh"
sed "s/__VERSION__/${version}/g" "$ps_template" > "$install_ps1"
chmod +x "$install_sh"
{
sha256_file "$unpacked_zip"
sha256_file "$cws_zip"
sha256_file "$edge_zip"
sha256_file "$firefox_zip"
sha256_file "$mcp_bundle_zip"
sha256_file "$install_sh"
sha256_file "$install_ps1"
} > "$artifacts_dir/checksums.txt"
log "Artifacts created:"
ls -1 "$artifacts_dir"
}
release_to_github() {
local version="$1"
local tag="v${version}"
local artifacts_dir="artifacts/v${version}"
log "Committing version bump"
git add \
package.json \
packages/core/package.json \
packages/extension/package.json \
packages/mcp-server/package.json \
packages/extension/manifest.json \
packages/extension/src/popup/components/Popup.tsx \
packages/mcp-server/src/mcp/server.ts \
packages/mcp-server/src/doctor/checks/mcp-runtime.ts
git commit -m "chore(release): ${tag}"
log "Tagging release ${tag}"
git tag "$tag"
log "Pushing commit and tag"
git push origin main
git push origin "$tag"
log "Creating GitHub release ${tag}"
gh release create "$tag" \
"$artifacts_dir/onui-extension-unpacked-v${version}.zip" \
"$artifacts_dir/onui-chrome-web-store-v${version}.zip" \
"$artifacts_dir/onui-edge-add-ons-v${version}.zip" \
"$artifacts_dir/onui-firefox-add-ons-v${version}.zip" \
"$artifacts_dir/onui-mcp-bundle-v${version}.zip" \
"$artifacts_dir/install.sh" \
"$artifacts_dir/install.ps1" \
"$artifacts_dir/checksums.txt" \
--title "$tag" \
--generate-notes
}
main() {
if [ "$#" -ne 1 ]; then
usage
exit 1
fi
case "$1" in
--build)
preflight_common
local version
version="$(current_version)"
run_build_pipeline
package_artifacts "$version"
;;
--release)
preflight_common
assert_clean_tree
assert_main_branch
assert_gh_auth
local version
version="$(next_patch_version)"
log "Bumping version to $version"
sync_version "$version"
run_build_pipeline
package_artifacts "$version"
release_to_github "$version"
;;
*)
usage
exit 1
;;
esac
}
main "$@"