-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupdate-release-version.sh
More file actions
executable file
·400 lines (355 loc) · 13.5 KB
/
update-release-version.sh
File metadata and controls
executable file
·400 lines (355 loc) · 13.5 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/usr/bin/env bash
set -euo pipefail
## update-release-version.sh
## Deterministically updates the release version across all version-bearing files
## in the codeql-sap-js repository.
##
## Version-bearing files (15 qlpack.yml files):
## javascript/frameworks/cap/ext/qlpack.yml
## javascript/frameworks/cap/lib/qlpack.yml
## javascript/frameworks/cap/src/qlpack.yml
## javascript/frameworks/cap/test/qlpack.yml
## javascript/frameworks/ui5/ext/qlpack.yml
## javascript/frameworks/ui5/lib/qlpack.yml
## javascript/frameworks/ui5/src/qlpack.yml
## javascript/frameworks/ui5/test/qlpack.yml
## javascript/frameworks/ui5-webcomponents/test/qlpack.yml
## javascript/frameworks/xsjs/ext/qlpack.yml
## javascript/frameworks/xsjs/lib/qlpack.yml
## javascript/frameworks/xsjs/src/qlpack.yml
## javascript/frameworks/xsjs/test/qlpack.yml
## javascript/heuristic-models/ext/qlpack.yml
## javascript/heuristic-models/tests/qlpack.yml
##
## Additionally updates:
## - Internal dependency references within qlpack.yml files
## that reference other packs in this repository (e.g., ^X.Y.Z constraints).
## - qlt.conf.json (CodeQLCLI, CodeQLStandardLibrary, CodeQLCLIBundle)
## using the base version (X.Y.Z) derived by stripping any pre-release suffix.
##
## Usage:
## ./scripts/update-release-version.sh <new-version>
## ./scripts/update-release-version.sh --check [<expected-version>]
##
## Examples:
## ./scripts/update-release-version.sh 2.4.0
## ./scripts/update-release-version.sh 2.4.0-rc1
## ./scripts/update-release-version.sh --check
## ./scripts/update-release-version.sh --check 2.4.0
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
## All qlpack.yml file paths relative to repo root
QLPACK_FILES=(
"javascript/frameworks/cap/ext/qlpack.yml"
"javascript/frameworks/cap/lib/qlpack.yml"
"javascript/frameworks/cap/src/qlpack.yml"
"javascript/frameworks/cap/test/qlpack.yml"
"javascript/frameworks/ui5/ext/qlpack.yml"
"javascript/frameworks/ui5/lib/qlpack.yml"
"javascript/frameworks/ui5/src/qlpack.yml"
"javascript/frameworks/ui5/test/qlpack.yml"
"javascript/frameworks/ui5-webcomponents/test/qlpack.yml"
"javascript/frameworks/xsjs/ext/qlpack.yml"
"javascript/frameworks/xsjs/lib/qlpack.yml"
"javascript/frameworks/xsjs/src/qlpack.yml"
"javascript/frameworks/xsjs/test/qlpack.yml"
"javascript/heuristic-models/ext/qlpack.yml"
"javascript/heuristic-models/tests/qlpack.yml"
)
## Pack names that belong to this repository (for updating internal dependency refs)
INTERNAL_PACKS=(
"advanced-security/javascript-sap-cap-models"
"advanced-security/javascript-sap-cap-all"
"advanced-security/javascript-sap-cap-queries"
"advanced-security/javascript-sap-ui5-models"
"advanced-security/javascript-sap-ui5-all"
"advanced-security/javascript-sap-ui5-queries"
"advanced-security/javascript-sap-xsjs-models"
"advanced-security/javascript-sap-xsjs-all"
"advanced-security/javascript-sap-xsjs-queries"
"advanced-security/javascript-heuristic-models"
)
usage() {
cat <<EOF
Usage: $0 <new-version>
$0 --check [<expected-version>]
Deterministically updates the release version across all version-bearing files.
ARGUMENTS:
<new-version> The new version to set (e.g., 2.4.0 or 2.4.0-alpha).
The 'v' prefix is optional and will be normalized.
Supports pre-release suffixes: -alpha, -beta, -rc1, etc.
OPTIONS:
--check [<version>] Check version consistency across all files.
If <version> is provided, also validates that all
files match the expected version.
--dry-run Show what would be changed without modifying files.
-h, --help Show this help message.
EXAMPLES:
$0 2.4.0 Update all files to version 2.4.0
$0 2.4.0-alpha Update all files to pre-release version 2.4.0-alpha
$0 v2.4.0 Same as above (v prefix is stripped automatically)
$0 --check Verify all version-bearing files are consistent
$0 --check 2.4.0 Verify all files contain version 2.4.0
$0 --dry-run 2.4.0 Preview changes without writing files
EOF
}
## Collect all version-bearing files and their current versions
collect_versions() {
local versions=()
for qlpack_file in "${QLPACK_FILES[@]}"; do
local full_path="${REPO_ROOT}/${qlpack_file}"
if [[ -f "${full_path}" ]]; then
local pack_version
pack_version=$(grep -m1 "^version:" "${full_path}" | awk '{print $2}')
if [[ -z "${pack_version}" ]]; then
echo "ERROR: ${qlpack_file} is missing a 'version:' field" >&2
return 1
fi
versions+=("${qlpack_file}|${pack_version}")
else
echo "ERROR: ${qlpack_file} not found" >&2
return 1
fi
done
printf '%s\n' "${versions[@]}"
}
## Check version consistency
check_versions() {
local expected_version="${1:-}"
local all_consistent=true
local first_version=""
local file_count=0
echo "=== Version Consistency Check ==="
echo ""
local version_output
if ! version_output=$(collect_versions); then
echo "❌ Failed to collect versions" >&2
return 1
fi
while IFS='|' read -r file version; do
file_count=$((file_count + 1))
if [[ -z "${first_version}" ]]; then
first_version="${version}"
fi
if [[ -n "${expected_version}" ]]; then
if [[ "${version}" == "${expected_version}" ]]; then
echo " ✅ ${file}: ${version}"
else
echo " ❌ ${file}: ${version} (expected ${expected_version})"
all_consistent=false
fi
else
if [[ "${version}" == "${first_version}" ]]; then
echo " ✅ ${file}: ${version}"
else
echo " ❌ ${file}: ${version} (differs from ${first_version})"
all_consistent=false
fi
fi
done <<< "${version_output}"
## Also check qlt.conf.json consistency
local qlt_config="${REPO_ROOT}/qlt.conf.json"
if [[ -f "${qlt_config}" ]]; then
local cli_version
cli_version=$(grep -o '"CodeQLCLI":[[:space:]]*"[^"]*"' "${qlt_config}" | grep -o '"[^"]*"$' | tr -d '"')
## Derive expected base version: strip pre-release suffix from first_version or expected_version
local check_base="${expected_version:-${first_version}}"
check_base="${check_base%%-*}"
if [[ "${cli_version}" == "${check_base}" ]]; then
echo " ✅ qlt.conf.json: CodeQLCLI ${cli_version}"
else
echo " ❌ qlt.conf.json: CodeQLCLI ${cli_version} (expected ${check_base})"
all_consistent=false
fi
fi
echo ""
echo "Checked ${file_count} version-bearing files + qlt.conf.json."
if [[ "${all_consistent}" == true ]]; then
if [[ -n "${expected_version}" ]]; then
echo "✅ All files match expected version: ${expected_version}"
else
echo "✅ All files are consistent at version: ${first_version}"
fi
return 0
else
echo "❌ Version inconsistency detected!"
return 1
fi
}
## Validate version format (X.Y.Z or X.Y.Z-suffix)
validate_version() {
local version="$1"
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
echo "ERROR: Invalid version format '${version}'" >&2
echo "Expected format: X.Y.Z or X.Y.Z-suffix (e.g., 2.4.0, 2.4.0-alpha, 2.4.0-rc1)" >&2
return 1
fi
}
## Update a qlpack.yml file's version field using sed
update_pack_version() {
local file="$1"
local new_version="$2"
sed -i.bak "s/^version:[[:space:]]*.*/version: ${new_version}/" "${file}"
rm -f "${file}.bak"
}
## Update qlt.conf.json with the base version (suffix stripped)
## e.g., 2.4.0-alpha -> CodeQLCLI: "2.4.0", CodeQLStandardLibrary: "codeql-cli/v2.4.0", etc.
update_qlt_config() {
local new_version="$1"
local dry_run="${2:-false}"
local qlt_config="${REPO_ROOT}/qlt.conf.json"
# Derive the base version by stripping any pre-release suffix
local base_version="${new_version%%-*}"
if [[ ! -f "${qlt_config}" ]]; then
echo "WARNING: qlt.conf.json not found, skipping" >&2
return 0
fi
if [[ "${dry_run}" == true ]]; then
echo " [DRY RUN] qlt.conf.json: CodeQLCLI -> ${base_version}"
return 0
fi
# Use jq for reliable JSON manipulation (learned from update-codeql.yml)
if command -v jq &>/dev/null; then
jq --arg cli_version "${base_version}" \
--arg std_lib "codeql-cli/v${base_version}" \
--arg bundle "codeql-bundle-v${base_version}" \
'.CodeQLCLI = $cli_version | .CodeQLStandardLibrary = $std_lib | .CodeQLCLIBundle = $bundle' \
"${qlt_config}" > "${qlt_config}.tmp" && mv "${qlt_config}.tmp" "${qlt_config}"
else
# Fallback to sed if jq is not available
local tmp_file
tmp_file=$(mktemp)
sed \
-e "s/\"CodeQLCLI\":[[:space:]]*\"[^\"]*\"/\"CodeQLCLI\": \"${base_version}\"/" \
-e "s/\"CodeQLStandardLibrary\":[[:space:]]*\"[^\"]*\"/\"CodeQLStandardLibrary\": \"codeql-cli\/v${base_version}\"/" \
-e "s/\"CodeQLCLIBundle\":[[:space:]]*\"[^\"]*\"/\"CodeQLCLIBundle\": \"codeql-bundle-v${base_version}\"/" \
"${qlt_config}" > "${tmp_file}"
mv "${tmp_file}" "${qlt_config}"
fi
echo " ✅ qlt.conf.json: CodeQLCLI -> ${base_version}"
}
## Update internal dependency references in a qlpack.yml file
## Handles all YAML key-value formats used across qlpack files:
## e.g., advanced-security/javascript-sap-cap-models: "^2.3.0" -> "^2.4.0"
## e.g., advanced-security/javascript-sap-cap-models: "2.3.0" -> "2.4.0"
## e.g., "advanced-security/javascript-heuristic-models": "2.3.0" -> ... (quoted key)
## and advanced-security/javascript-heuristic-models: 2.3.0 -> 2.4.0
update_internal_deps() {
local file="$1"
local old_version="$2"
local new_version="$3"
# Escape dots in the old version (e.g., '2.3.0' -> '2\.3\.0') for use in sed regex
local escaped_old_version
escaped_old_version=$(printf '%s' "${old_version}" | sed 's/\./\\./g')
for pack_name in "${INTERNAL_PACKS[@]}"; do
# Update quoted caret-prefixed versions: "^X.Y.Z" (pack name optionally quoted)
sed -i.bak "s|\"\\{0,1\\}${pack_name}\"\\{0,1\\}: \"\\^${escaped_old_version}\"|${pack_name}: \"^${new_version}\"|g" "${file}"
rm -f "${file}.bak"
# Update quoted exact versions: "X.Y.Z" (pack name optionally quoted)
sed -i.bak "s|\"\\{0,1\\}${pack_name}\"\\{0,1\\}: \"${escaped_old_version}\"|${pack_name}: \"${new_version}\"|g" "${file}"
rm -f "${file}.bak"
# Update unquoted exact versions: X.Y.Z (pack name optionally quoted)
sed -i.bak "s|\"\\{0,1\\}${pack_name}\"\\{0,1\\}: ${escaped_old_version}$|${pack_name}: ${new_version}|g" "${file}"
rm -f "${file}.bak"
done
}
## Update all version-bearing files
update_versions() {
local new_version="$1"
local dry_run="${2:-false}"
local updated_count=0
echo "=== Updating Release Version to ${new_version} ==="
echo ""
# Determine the current version from the first qlpack.yml file
local current_version=""
local first_file="${REPO_ROOT}/${QLPACK_FILES[0]}"
if [[ -f "${first_file}" ]]; then
current_version=$(grep -m1 "^version:" "${first_file}" | awk '{print $2}')
fi
if [[ -z "${current_version}" ]]; then
echo "ERROR: Could not determine current version from ${QLPACK_FILES[0]}" >&2
return 1
fi
echo " Current version: ${current_version}"
echo " New version: ${new_version}"
echo ""
if [[ "${current_version}" == "${new_version}" ]]; then
echo "ℹ️ Version is already ${new_version}. Nothing to update."
return 0
fi
## Update all qlpack.yml files
for qlpack_file in "${QLPACK_FILES[@]}"; do
local full_path="${REPO_ROOT}/${qlpack_file}"
if [[ -f "${full_path}" ]]; then
local old_version
old_version=$(grep -m1 "^version:" "${full_path}" | awk '{print $2}')
if [[ "${dry_run}" == true ]]; then
echo " [DRY RUN] ${qlpack_file}: ${old_version} -> ${new_version}"
else
update_pack_version "${full_path}" "${new_version}"
update_internal_deps "${full_path}" "${current_version}" "${new_version}"
echo " ✅ ${qlpack_file}: ${old_version} -> ${new_version}"
fi
updated_count=$((updated_count + 1))
fi
done
## Update qlt.conf.json
update_qlt_config "${new_version}" "${dry_run}"
echo ""
if [[ "${dry_run}" == true ]]; then
echo "Would update ${updated_count} qlpack files + qlt.conf.json. (Dry run — no files modified)"
else
echo "Updated ${updated_count} qlpack files + qlt.conf.json to version ${new_version}."
echo ""
echo "Next steps:"
echo " 1. Run 'codeql pack upgrade' on all packs to update lock files"
echo " 2. Run CodeQL unit tests to validate the changes"
echo " 3. Commit the changes and tag with 'v${new_version}'"
fi
}
## Parse arguments
CHECK_MODE=false
DRY_RUN=false
NEW_VERSION=""
while [[ $# -gt 0 ]]; do
case $1 in
--check)
CHECK_MODE=true
shift
## Optional expected version argument
if [[ $# -gt 0 && ! "$1" =~ ^-- ]]; then
NEW_VERSION="${1#v}"
shift
fi
;;
--dry-run)
DRY_RUN=true
shift
;;
-h|--help)
usage
exit 0
;;
-*)
echo "Error: Unknown option $1" >&2
usage >&2
exit 1
;;
*)
NEW_VERSION="${1#v}" ## Strip optional v prefix
shift
;;
esac
done
if [[ "${CHECK_MODE}" == true ]]; then
check_versions "${NEW_VERSION}"
exit $?
fi
if [[ -z "${NEW_VERSION}" ]]; then
echo "Error: No version specified" >&2
echo "" >&2
usage >&2
exit 1
fi
validate_version "${NEW_VERSION}"
update_versions "${NEW_VERSION}" "${DRY_RUN}"