-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathversion.sh
More file actions
executable file
·280 lines (252 loc) · 8.16 KB
/
version.sh
File metadata and controls
executable file
·280 lines (252 loc) · 8.16 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
272
273
274
275
276
277
278
279
280
#!/usr/bin/env bash
# version.sh — set the version of every ObjectiveAI package (and inter-package
# dependency reference) to a single value. Touches Rust crates, Python
# packages, JS packages, .NET csproj, and the runner subpackages. Skips
# lockfiles (Cargo.lock, pnpm-lock.yaml) — those regenerate on next build.
#
# Usage:
# bash version.sh <new-version>
# Example:
# bash version.sh 2.1.0
set -euo pipefail
if [ "$#" -ne 1 ] || [ -z "${1:-}" ]; then
echo "Usage: $0 <new-version>" >&2
echo "Example: $0 2.1.0" >&2
exit 1
fi
NEW_VERSION="$1"
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ---------------------------------------------------------------------------
# Primitives
# ---------------------------------------------------------------------------
# Everything is awk-based so the script is portable between GNU and BSD
# toolchains (macOS sed's `-i` flag and GNU sed's `0,/pat/` range syntax
# don't agree).
# Rewrite the first line matching $pat with the literal replacement $repl.
# If no match is found, the file is left unchanged (no error).
first_line_replace() {
local file="$1"
local pat="$2"
local repl="$3"
local tmp
tmp=$(mktemp)
awk -v pat="$pat" -v repl="$repl" '
!done && $0 ~ pat { print repl; done=1; next }
{ print }
' "$file" > "$tmp"
mv "$tmp" "$file"
}
# On each line matching $line_pat, replace every occurrence of $token_pat
# with $token_repl. Other lines pass through unchanged.
inline_substitute() {
local file="$1"
local line_pat="$2"
local token_pat="$3"
local token_repl="$4"
local tmp
tmp=$(mktemp)
awk -v lp="$line_pat" -v tp="$token_pat" -v tr="$token_repl" '
$0 ~ lp { gsub(tp, tr) }
{ print }
' "$file" > "$tmp"
mv "$tmp" "$file"
}
# Insert $insert_line right after the first line matching $pat. Idempotent
# guard left to the caller — this always inserts if the anchor matches.
insert_after_first() {
local file="$1"
local pat="$2"
local insert_line="$3"
local tmp
tmp=$(mktemp)
awk -v pat="$pat" -v ins="$insert_line" '
{ print }
!done && $0 ~ pat { print ins; done=1 }
' "$file" > "$tmp"
mv "$tmp" "$file"
}
# ---------------------------------------------------------------------------
# Per-file-type updaters
# ---------------------------------------------------------------------------
# Cargo.toml / pyproject.toml [package|project] version.
# Convention in our repo: the first `^version = "..."` line is the package
# version. Third-party dependency version specs never appear at column 0
# without a leading `= {` so this targets the right line.
set_toml_package_version() {
local file="$1"
first_line_replace "$file" \
'^version = "[^"]+"' \
"version = \"$NEW_VERSION\""
}
# Inter-package Cargo.toml dependency version pins.
# Matches lines like:
# objectiveai = { path = "..", version = "X.Y.Z", ... }
# objectiveai-api = { version = "X.Y.Z", ... }
# objectiveai-cli = { ... }
# ...and rewrites the `version = "..."` token inside.
set_cargo_objectiveai_deps() {
local file="$1"
inline_substitute "$file" \
'^objectiveai(-[a-zA-Z0-9_-]+)?[[:space:]]*=' \
'version = "[0-9][^"]*"' \
"version = \"$NEW_VERSION\""
}
# Root "version": "..." in a package.json. Relies on the standard layout
# where "version" is the first occurrence in the file (right after "name").
set_package_json_version() {
local file="$1"
first_line_replace "$file" \
'^[[:space:]]*"version":[[:space:]]*"[^"]+"' \
" \"version\": \"$NEW_VERSION\","
}
# Ensure a package.json has a "version" field; insert one right after "name"
# if missing.
ensure_package_json_version() {
local file="$1"
if grep -q '^[[:space:]]*"version":' "$file"; then
set_package_json_version "$file"
else
insert_after_first "$file" \
'^[[:space:]]*"name":' \
" \"version\": \"$NEW_VERSION\","
fi
}
# .csproj <Version>...</Version>
set_csproj_version() {
local file="$1"
inline_substitute "$file" \
'<Version>' \
'<Version>[^<]*</Version>' \
"<Version>$NEW_VERSION</Version>"
}
# `objectiveai==X.Y.Z` lines in a pip requirements.txt. Other entries in the
# file (including non-pinned ones, comments, and unrelated packages) pass
# through untouched. Spec stays `==NEW_VERSION`.
set_requirements_objectiveai_pin() {
local file="$1"
inline_substitute "$file" \
'^objectiveai[[:space:]]*==' \
'==[0-9][^[:space:]]*' \
"==$NEW_VERSION"
}
# `"objectiveai==X.Y.Z"` entries inside a pyproject.toml [project.dependencies]
# array (or any line that quotes an objectiveai pin). The token regex stops at
# the closing quote/comma so trailing TOML punctuation isn't consumed. Lines
# without an objectiveai pin pass through untouched, including unrelated deps
# like `objectiveai-foo==X` (the `-foo` breaks the `objectiveai==` boundary).
set_pyproject_objectiveai_dep_pin() {
local file="$1"
inline_substitute "$file" \
'objectiveai[[:space:]]*==' \
'==[0-9][^",[:space:]]*' \
"==$NEW_VERSION"
}
# __version__ = "..." in a Python file. If absent, insert one right after
# `from __future__ import annotations` (every runner has that line) with a
# blank line before it for PEP 8 readability.
ensure_py_module_version() {
local file="$1"
if grep -q '^__version__ = ' "$file"; then
first_line_replace "$file" \
'^__version__ = ' \
"__version__ = \"$NEW_VERSION\""
else
local tmp
tmp=$(mktemp)
awk -v ver="$NEW_VERSION" '
{ print }
!done && /^from __future__ import annotations/ {
print ""
printf "__version__ = \"%s\"\n", ver
done=1
}
' "$file" > "$tmp"
mv "$tmp" "$file"
fi
}
# ---------------------------------------------------------------------------
# File lists
# ---------------------------------------------------------------------------
CARGO_TOMLS=(
objectiveai-api/Cargo.toml
objectiveai-cli/Cargo.toml
objectiveai-cli/builder/Cargo.toml
objectiveai-json-schema/builder/Cargo.toml
objectiveai-mcp-cli/Cargo.toml
objectiveai-mcp-filesystem/Cargo.toml
objectiveai-mcp-proxy/Cargo.toml
objectiveai-mcp-proxy/test-upstream/Cargo.toml
objectiveai-rs/Cargo.toml
objectiveai-rs-cffi/Cargo.toml
objectiveai-rs-macros/Cargo.toml
objectiveai-rs-pyo3/Cargo.toml
objectiveai-rs-wasm-js/Cargo.toml
objectiveai-viewer/src-tauri/Cargo.toml
)
PYPROJECT_TOMLS=(
objectiveai-py/pyproject.toml
objectiveai-cocoindex/pyproject.toml
)
PACKAGE_JSONS=(
objectiveai-js/package.json
objectiveai-function-tree/package.json
objectiveai-viewer/package.json
)
CSPROJS=(
objectiveai-dotnet/ObjectiveAI/ObjectiveAI.csproj
)
PY_RUNNER_MAINS=(
objectiveai-claude-agent-sdk-runner/main.py
objectiveai-codex-sdk-runner/main.py
)
# pip requirements.txt files that pin `objectiveai==X.Y.Z`.
REQUIREMENTS_TXTS=(
objectiveai-cocoindex/requirements.txt
)
# ---------------------------------------------------------------------------
# Apply
# ---------------------------------------------------------------------------
update() {
local kind="$1"
local rel="$2"
local file="$REPO_ROOT/$rel"
if [ ! -f "$file" ]; then
echo " skip $rel (not found)"
return
fi
echo " $kind $rel"
case "$kind" in
cargo)
set_toml_package_version "$file"
set_cargo_objectiveai_deps "$file"
;;
pypro)
set_toml_package_version "$file"
set_pyproject_objectiveai_dep_pin "$file"
;;
pkg)
set_package_json_version "$file"
;;
pkg+)
ensure_package_json_version "$file"
;;
csproj)
set_csproj_version "$file"
;;
pyrun)
ensure_py_module_version "$file"
;;
reqs)
set_requirements_objectiveai_pin "$file"
;;
esac
}
echo "Setting version to $NEW_VERSION"
for rel in "${CARGO_TOMLS[@]}"; do update cargo "$rel"; done
for rel in "${PYPROJECT_TOMLS[@]}"; do update pypro "$rel"; done
for rel in "${PACKAGE_JSONS[@]}"; do update pkg "$rel"; done
for rel in "${CSPROJS[@]}"; do update csproj "$rel"; done
for rel in "${PY_RUNNER_MAINS[@]}"; do update pyrun "$rel"; done
for rel in "${REQUIREMENTS_TXTS[@]}"; do update reqs "$rel"; done
echo
echo "Done. Cargo.lock and pnpm-lock.yaml will refresh on next build."