Skip to content

Commit dd0680d

Browse files
committed
Fixes for actions workflow failures 2
1 parent bc9f8a8 commit dd0680d

File tree

2 files changed

+107
-11
lines changed

2 files changed

+107
-11
lines changed

.github/workflows/internal-validate-cli-outputs.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,53 @@ on:
99
- 'main'
1010
workflow_dispatch:
1111

12+
env:
13+
# Global configuration
14+
DOTNET_VERSION: '6.0.x'
15+
BUILD_CONFIGURATION: Debug
16+
1217
jobs:
1318
validate-cli-outputs:
14-
name: Validate CLI End-to-End
19+
name: Validate CodeQlToolkit `query generate new-query` subcommand
1520
runs-on: ubuntu-latest
16-
21+
1722
steps:
1823
- name: Checkout repository
1924
uses: actions/checkout@v4
2025

2126
- name: Setup .NET
2227
uses: actions/setup-dotnet@v4
2328
with:
24-
dotnet-version: '6.0.x'
29+
dotnet-version: ${{ env.DOTNET_VERSION }}
2530

2631
- name: Restore dependencies
2732
run: dotnet restore
2833

29-
- name: Build
30-
run: dotnet build -c Debug --no-restore
34+
- name: Build project
35+
run: dotnet build -c ${{ env.BUILD_CONFIGURATION }} --no-restore
36+
37+
- name: Set test directory
38+
run: echo "TEST_DIR=${{ runner.temp }}/qlt-cli-e2e-test" >> $GITHUB_ENV
39+
40+
- name: Prepare test environment
41+
run: |
42+
# Create test directory
43+
mkdir -p "$TEST_DIR"
44+
45+
# Copy configuration file
46+
cp example/qlt.conf.json "$TEST_DIR"
47+
48+
- name: Install `codeql` CLI via CodeQLToolkit
49+
run: dotnet run --project src/CodeQLToolkit.Core -- codeql run install --base "$TEST_DIR"
3150

3251
- name: Run end-to-end CLI validation
3352
run: ./scripts/validate-cli-e2e.sh
34-
env:
35-
# Use a temporary directory in the runner
36-
TEST_DIR: ${{ runner.temp }}/qlt-cli-e2e-test
3753

3854
- name: Upload test artifacts on failure
3955
if: failure()
4056
uses: actions/upload-artifact@v4
4157
with:
4258
name: cli-validation-artifacts
43-
path: |
44-
${{ runner.temp }}/qlt-cli-e2e-test/**
59+
path: ${{ runner.temp }}/qlt-cli-e2e-test/**
4560
if-no-files-found: warn
4661
retention-days: 3

scripts/validate-cli-e2e.sh

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,62 @@ log_error() {
4242
echo -e "${RED}[ERROR]${NC} $1"
4343
}
4444

45+
# Find CodeQL CLI executable path
46+
find_codeql_cli() {
47+
local cli_path=""
48+
49+
# Try common installation paths
50+
local common_paths=(
51+
"$HOME/.codeql/codeql-cli_v2.22.4/codeql/codeql"
52+
"$HOME/.codeql/codeql-bundle-v2.22.4/codeql/codeql"
53+
"$HOME/.codeql/distributions/codeql-cli_v2.22.4/codeql/codeql"
54+
"$HOME/.codeql/distributions/codeql-bundle-v2.22.4/codeql/codeql"
55+
"$(which codeql 2>/dev/null)"
56+
)
57+
58+
for path in "${common_paths[@]}"; do
59+
if [[ -f "$path" && -x "$path" ]]; then
60+
cli_path="$path"
61+
break
62+
fi
63+
done
64+
65+
# If not found in common paths, try to find it dynamically
66+
if [[ -z "$cli_path" ]]; then
67+
cli_path=$(find "$HOME/.codeql" -name "codeql" -type f -executable 2>/dev/null | head -1)
68+
fi
69+
70+
echo "$cli_path"
71+
}
72+
73+
# Get detailed compilation errors for a specific query file
74+
get_detailed_compilation_errors() {
75+
local query_file="$1"
76+
local codeql_cli="$2"
77+
78+
if [[ -z "$codeql_cli" || ! -f "$codeql_cli" ]]; then
79+
log_warning "CodeQL CLI not found, cannot get detailed compilation errors"
80+
return 1
81+
fi
82+
83+
if [[ ! -f "$query_file" ]]; then
84+
log_error "Query file not found: $query_file"
85+
return 1
86+
fi
87+
88+
log_info "Getting detailed compilation errors for: $(basename "$query_file")"
89+
90+
# Run codeql query compile with verbose output
91+
local compile_output
92+
if compile_output=$("$codeql_cli" query compile --check-only -- "$query_file" 2>&1); then
93+
log_info "Query compiled successfully (unexpected since validation failed)"
94+
echo "$compile_output"
95+
else
96+
log_error "Detailed compilation errors:"
97+
echo "$compile_output"
98+
fi
99+
}
100+
45101
# Cleanup function
46102
cleanup_at_start() {
47103
if [[ -d "$TEST_DIR" ]]; then
@@ -266,8 +322,33 @@ validate_language() {
266322
# Check if there are actual errors (not just deprecation warnings)
267323
if [[ $validation_exit_code -ne 0 ]]; then
268324
# Check if the failures are only deprecation warnings about assume_small_delta
269-
if echo "$validation_output" | grep -v "pragma 'assume_small_delta' is deprecated" | grep -q -E "(ERROR|FAILURE|Failed to|Error:|Compilation failed)"; then
325+
if echo "$validation_output" | grep -v "pragma 'assume_small_delta' is deprecated" | grep -q -E "(ERROR|FAILURE|Failed|Error:|Compilation failed|Fatal error)"; then
270326
log_error "Query validation failed for $language with actual errors"
327+
328+
# Try to get detailed compilation errors for failed queries
329+
log_info "Attempting to get detailed compilation errors..."
330+
local codeql_cli
331+
codeql_cli=$(find_codeql_cli)
332+
333+
if [[ -n "$codeql_cli" ]]; then
334+
# Find all query files for this language and check them individually
335+
local lang_dir="$language/testpack-$language"
336+
local src_dir="$lang_dir/src"
337+
338+
if [[ -d "$src_dir" ]]; then
339+
# Use find to get query files (compatible with older bash)
340+
while IFS= read -r -d '' query_file; do
341+
log_info "Checking individual query: $(basename "$query_file")"
342+
get_detailed_compilation_errors "$query_file" "$codeql_cli"
343+
echo "---"
344+
done < <(find "$src_dir" -name "*.ql" -type f -print0)
345+
else
346+
log_warning "Source directory not found: $src_dir"
347+
fi
348+
else
349+
log_warning "CodeQL CLI not found, cannot provide detailed compilation errors"
350+
fi
351+
271352
return 1
272353
else
273354
log_info "Query validation completed for $language (only deprecation warnings in standard library)"

0 commit comments

Comments
 (0)