-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextract-test-databases.sh
More file actions
executable file
·151 lines (132 loc) · 4.46 KB
/
extract-test-databases.sh
File metadata and controls
executable file
·151 lines (132 loc) · 4.46 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
#!/usr/bin/env bash
set -euo pipefail
## Parse command line arguments
LANGUAGE=""
SCOPE=""
usage() {
cat << EOF
Usage: $0 [OPTIONS]
Extract test databases for CodeQL queries associated with the MCP server.
By default, only a minimal set of databases for client integration tests is
pre-extracted (currently: javascript/examples only). This is not an
exhaustive list of databases the integration test suite may use; additional
databases may be extracted on demand, so full extraction is rarely needed.
OPTIONS:
--scope <scope> Extract databases for a specific use case
Valid values:
integration - Only databases needed by client integration tests (default)
all - All test databases for all languages
--language <lang> Extract databases only for the specified language (implies --scope all)
Valid values: actions, cpp, csharp, go, java, javascript, python, ruby, rust, swift
-h, --help Show this help message
EOF
}
while [[ $# -gt 0 ]]; do
case $1 in
--language)
LANGUAGE="$2"
shift 2
;;
--scope)
SCOPE="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Error: Unknown option $1" >&2
usage >&2
exit 1
;;
esac
done
## Validate scope if provided
if [ -n "${SCOPE}" ]; then
case "${SCOPE}" in
integration|all) ;;
*)
echo "Error: Invalid scope '${SCOPE}'" >&2
echo "Valid scopes: integration, all" >&2
exit 1
;;
esac
fi
## Validate language if provided
VALID_LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby" "rust" "swift")
if [ -n "${LANGUAGE}" ]; then
LANGUAGE_VALID=false
for valid_lang in "${VALID_LANGUAGES[@]}"; do
if [ "${LANGUAGE}" = "${valid_lang}" ]; then
LANGUAGE_VALID=true
break
fi
done
if [ "${LANGUAGE_VALID}" = false ]; then
echo "Error: Invalid language '${LANGUAGE}'" >&2
echo "Valid languages: ${VALID_LANGUAGES[*]}" >&2
exit 1
fi
fi
## Get the directory of this script.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
## Get the root directory of the repository.
REPO_ROOT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
## Explicitly set the cwd to the REPO_ROOT_DIR.
cd "${REPO_ROOT_DIR}"
## Define a function to extract test databases for a given directory
extract_test_databases() {
local _base_dir="$1"
if [ ! -d "${_base_dir}/test" ]; then
echo "INFO: No test directory found at ${_base_dir}/test, skipping..."
return 0
fi
echo "INFO: Extracting test databases in '${_base_dir}/test' directory..."
# Find all test directories (those containing .qlref files)
while IFS= read -r -d '' test_dir; do
test_dir_name=$(basename "${test_dir}")
echo "INFO: Extracting test database for ${test_dir}..."
# Check if .testproj already exists
if [ -d "${test_dir}/${test_dir_name}.testproj" ]; then
echo "INFO: Database already exists at ${test_dir}/${test_dir_name}.testproj, skipping extraction..."
else
# Extract the test database
codeql test extract "${test_dir}" || {
echo "WARNING: Failed to extract database for ${test_dir}, continuing..."
}
fi
done < <(find "${_base_dir}/test" -mindepth 1 -maxdepth 1 -type d -print0)
}
## Extract test databases based on scope and language filters.
##
## Default (no flags): only databases needed by client integration tests
## (currently just server/ql/javascript/examples).
## --scope all: all languages × examples + tools.
## --language: filter to a single language (implies --scope all).
# --language implies --scope all for that language
if [ -n "${LANGUAGE}" ]; then
echo "Extracting test databases for language: ${LANGUAGE}"
# Special handling for JavaScript which has both examples and tools
if [ "${LANGUAGE}" = "javascript" ]; then
extract_test_databases "server/ql/javascript/examples"
fi
if [ -d "server/ql/${LANGUAGE}/tools" ]; then
extract_test_databases "server/ql/${LANGUAGE}/tools"
fi
elif [ "${SCOPE}" = "all" ]; then
echo "Extracting test databases for all languages..."
for lang in "${VALID_LANGUAGES[@]}"; do
# Special handling for JavaScript which has both examples and tools
if [ "${lang}" = "javascript" ]; then
extract_test_databases "server/ql/javascript/examples"
fi
if [ -d "server/ql/${lang}/tools" ]; then
extract_test_databases "server/ql/${lang}/tools"
fi
done
else
echo "Extracting test databases for integration tests only..."
extract_test_databases "server/ql/javascript/examples"
fi
echo "INFO: Test database extraction complete!"