|
| 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