Skip to content

Commit 5540088

Browse files
committed
Add upgrade-packs.sh script & address PR review
This commit: - adds the scripts/upgrade-packs.sh script to provide a standard script for a common repo maintenance task; - updates the update-codeql.yml actions workflow in order to: - address PR review comments; - run the new upgrade-packs.sh script as a step in the workflow.
1 parent ae272ce commit 5540088

File tree

2 files changed

+128
-15
lines changed

2 files changed

+128
-15
lines changed

.github/workflows/update-codeql.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ jobs:
108108
run: |
109109
LATEST="${{ needs.detect-update.outputs.latest_version }}"
110110
echo "Updating all version-bearing files to ${LATEST}..."
111-
chmod +x ./scripts/update-release-version.sh
112111
./scripts/update-release-version.sh "${LATEST}"
113112
114113
- name: Update - Install CodeQL via GitHub CLI
@@ -128,17 +127,7 @@ jobs:
128127
echo "CodeQL version: $(codeql version --format=terse)"
129128
130129
- name: Update - Upgrade CodeQL pack lock files
131-
shell: bash
132-
run: |
133-
echo "Upgrading CodeQL pack lock files..."
134-
find . -name "qlpack.yml" -type f | sort | while read -r qlpack_file; do
135-
pack_dir=$(dirname "$qlpack_file")
136-
echo "Upgrading pack in directory: $pack_dir"
137-
cd "$pack_dir"
138-
codeql pack upgrade
139-
cd - > /dev/null
140-
done
141-
echo "Finished upgrading all CodeQL pack lock files"
130+
run: ./scripts/upgrade-packs.sh
142131

143132
- name: Update - Setup Node.js for CDS compilation
144133
uses: actions/setup-node@v6
@@ -148,9 +137,7 @@ jobs:
148137
cache-dependency-path: 'extractors/cds/tools/package-lock.json'
149138

150139
- name: Update - Compile CAP CDS files
151-
run: |
152-
chmod +x ./extractors/cds/tools/workflow/cds-compilation-for-actions.sh
153-
./extractors/cds/tools/workflow/cds-compilation-for-actions.sh
140+
run: ./extractors/cds/tools/workflow/cds-compilation-for-actions.sh
154141

155142
- name: Update - Run CodeQL unit tests
156143
env:

scripts/upgrade-packs.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
## upgrade-packs.sh
5+
## Upgrade CodeQL pack dependencies for packs in the codeql-sap-js repository.
6+
##
7+
## This script upgrades lock files for both source and test packs, installing
8+
## the latest compatible version of each dependency (ignoring existing lock files).
9+
##
10+
## Usage:
11+
## ./scripts/upgrade-packs.sh
12+
## ./scripts/upgrade-packs.sh --framework cap
13+
## ./scripts/upgrade-packs.sh --framework ui5
14+
15+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
17+
18+
FRAMEWORK=""
19+
20+
usage() {
21+
cat <<EOF
22+
Usage: $0 [OPTIONS]
23+
24+
Upgrade CodeQL pack dependencies for all packs in the repository.
25+
26+
OPTIONS:
27+
--framework <name> Upgrade packs only for the specified framework
28+
Valid values: cap, heuristic-models, ui5, ui5-webcomponents, xsjs
29+
-h, --help Show this help message
30+
31+
By default, the script upgrades packs for all frameworks.
32+
EOF
33+
}
34+
35+
while [[ $# -gt 0 ]]; do
36+
case $1 in
37+
--framework)
38+
if [[ $# -lt 2 || "${2-}" == -* ]]; then
39+
echo "Error: --framework requires a value" >&2
40+
usage >&2
41+
exit 1
42+
fi
43+
FRAMEWORK="$2"
44+
shift 2
45+
;;
46+
-h|--help)
47+
usage
48+
exit 0
49+
;;
50+
*)
51+
echo "Error: Unknown option $1" >&2
52+
usage >&2
53+
exit 1
54+
;;
55+
esac
56+
done
57+
58+
## Validate framework if provided
59+
VALID_FRAMEWORKS=("cap" "heuristic-models" "ui5" "ui5-webcomponents" "xsjs")
60+
if [[ -n "${FRAMEWORK}" ]]; then
61+
FRAMEWORK_VALID=false
62+
for valid_fw in "${VALID_FRAMEWORKS[@]}"; do
63+
if [[ "${FRAMEWORK}" == "${valid_fw}" ]]; then
64+
FRAMEWORK_VALID=true
65+
break
66+
fi
67+
done
68+
69+
if [[ "${FRAMEWORK_VALID}" == false ]]; then
70+
echo "Error: Invalid framework '${FRAMEWORK}'" >&2
71+
echo "Valid frameworks: ${VALID_FRAMEWORKS[*]}" >&2
72+
exit 1
73+
fi
74+
fi
75+
76+
cd "${REPO_ROOT}"
77+
78+
## Upgrade a single pack given its qlpack.yml directory
79+
upgrade_pack() {
80+
local pack_dir="$1"
81+
if [[ -d "${pack_dir}" ]]; then
82+
echo "INFO: Running 'codeql pack upgrade' for '${pack_dir}'..."
83+
codeql pack upgrade -- "${pack_dir}"
84+
else
85+
echo "WARNING: Directory '${pack_dir}' not found, skipping" >&2
86+
fi
87+
}
88+
89+
## Upgrade packs for a framework (all subdirectories that contain qlpack.yml)
90+
upgrade_framework() {
91+
local framework_path="$1"
92+
echo "Upgrading packs for: ${framework_path}"
93+
94+
# Find all qlpack.yml files under this framework and upgrade their packs
95+
find "${REPO_ROOT}/${framework_path}" -name "qlpack.yml" -type f | sort | while read -r qlpack_file; do
96+
local pack_dir
97+
pack_dir=$(dirname "${qlpack_file}")
98+
# Use relative path for cleaner output
99+
local rel_path="${pack_dir#${REPO_ROOT}/}"
100+
upgrade_pack "${rel_path}"
101+
done
102+
}
103+
104+
if [[ -n "${FRAMEWORK}" ]]; then
105+
case "${FRAMEWORK}" in
106+
heuristic-models)
107+
upgrade_framework "javascript/heuristic-models"
108+
;;
109+
ui5-webcomponents)
110+
upgrade_framework "javascript/frameworks/ui5-webcomponents"
111+
;;
112+
*)
113+
upgrade_framework "javascript/frameworks/${FRAMEWORK}"
114+
;;
115+
esac
116+
else
117+
echo "Upgrading packs for all frameworks..."
118+
upgrade_framework "javascript/frameworks/cap"
119+
upgrade_framework "javascript/frameworks/ui5"
120+
upgrade_framework "javascript/frameworks/ui5-webcomponents"
121+
upgrade_framework "javascript/frameworks/xsjs"
122+
upgrade_framework "javascript/heuristic-models"
123+
fi
124+
125+
echo ""
126+
echo "✅ All CodeQL pack lock files upgraded successfully."

0 commit comments

Comments
 (0)