Skip to content

Commit c6743c6

Browse files
Copilotdata-douser
andcommitted
Switch Windows workflow to use bash shell instead of PowerShell
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 7257dd8 commit c6743c6

File tree

1 file changed

+110
-132
lines changed

1 file changed

+110
-132
lines changed

.github/workflows/ql-unit-tests-windows.yml

Lines changed: 110 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -73,86 +73,81 @@ jobs:
7373

7474
- name: Setup CodeQL CLI
7575
id: setup-codeql
76-
shell: pwsh
76+
shell: bash
7777
run: |
7878
# Read CodeQL CLI version from qlt.conf.json
79-
$qltConfig = Get-Content "qlt.conf.json" | ConvertFrom-Json
80-
$cliVersion = $qltConfig.CodeQLCLI
79+
CLI_VERSION=$(grep -oP '"CodeQLCLI"\s*:\s*"\K[^"]+' qlt.conf.json)
8180
8281
# Ensure version has 'v' prefix for GitHub releases
83-
if (-not $cliVersion.StartsWith("v")) {
84-
$version = "v$cliVersion"
85-
} else {
86-
$version = $cliVersion
87-
}
82+
if [[ ! "$CLI_VERSION" =~ ^v ]]; then
83+
VERSION="v$CLI_VERSION"
84+
else
85+
VERSION="$CLI_VERSION"
86+
fi
8887
89-
Write-Host "Installing CodeQL CLI version: $version (from qlt.conf.json)"
88+
echo "Installing CodeQL CLI version: $VERSION (from qlt.conf.json)"
9089
9190
# Determine download URL for Windows
92-
$downloadUrl = "https://github.com/github/codeql-cli-binaries/releases/download/$version/codeql-win64.zip"
91+
DOWNLOAD_URL="https://github.com/github/codeql-cli-binaries/releases/download/$VERSION/codeql-win64.zip"
9392
9493
# Create installation directory
95-
$installDir = "$env:RUNNER_TOOL_CACHE\codeql"
96-
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
94+
INSTALL_DIR="$RUNNER_TOOL_CACHE/codeql"
95+
mkdir -p "$INSTALL_DIR"
9796
9897
# Download and extract CodeQL CLI
99-
$zipPath = "$env:RUNNER_TEMP\codeql.zip"
100-
Write-Host "Downloading from: $downloadUrl"
101-
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath
98+
ZIP_PATH="$RUNNER_TEMP/codeql.zip"
99+
echo "Downloading from: $DOWNLOAD_URL"
100+
curl -L -o "$ZIP_PATH" "$DOWNLOAD_URL"
102101
103-
Write-Host "Extracting CodeQL CLI to: $installDir"
104-
Expand-Archive -Path $zipPath -DestinationPath $installDir -Force
102+
echo "Extracting CodeQL CLI to: $INSTALL_DIR"
103+
unzip -q "$ZIP_PATH" -d "$INSTALL_DIR"
105104
106105
# Set up environment
107-
$codeqlPath = "$installDir\codeql"
108-
$codeqlExe = "$codeqlPath\codeql.exe"
106+
CODEQL_PATH="$INSTALL_DIR/codeql"
107+
CODEQL_EXE="$CODEQL_PATH/codeql.exe"
109108
110-
if (-not (Test-Path $codeqlExe)) {
111-
Write-Error "CodeQL executable not found at: $codeqlExe"
109+
if [ ! -f "$CODEQL_EXE" ]; then
110+
echo "Error: CodeQL executable not found at: $CODEQL_EXE"
112111
exit 1
113-
}
112+
fi
114113
115-
Write-Host "CodeQL executable: $codeqlExe"
114+
echo "CodeQL executable: $CODEQL_EXE"
116115
117116
# Add to PATH for subsequent steps
118-
echo "$codeqlPath" >> $env:GITHUB_PATH
119-
echo "CODEQL_HOME=$codeqlPath" >> $env:GITHUB_ENV
120-
echo "codeql-path=$codeqlPath" >> $env:GITHUB_OUTPUT
117+
echo "$CODEQL_PATH" >> $GITHUB_PATH
118+
echo "CODEQL_HOME=$CODEQL_PATH" >> $GITHUB_ENV
119+
echo "codeql-path=$CODEQL_PATH" >> $GITHUB_OUTPUT
121120
122121
# Verify installation
123-
& $codeqlExe --version
122+
"$CODEQL_EXE" --version
124123
125124
- name: Verify CodeQL Installation
126-
shell: pwsh
125+
shell: bash
127126
run: |
128-
Write-Host "CodeQL version:"
127+
echo "CodeQL version:"
129128
codeql --version
130129
131-
Write-Host ""
132-
Write-Host "CodeQL resolve languages:"
130+
echo ""
131+
echo "CodeQL resolve languages:"
133132
codeql resolve languages
134133
135134
- name: Install QL Packs
136-
shell: pwsh
135+
shell: bash
137136
run: |
138-
Write-Host "Installing QL packs from qlpack.yml files..."
137+
echo "Installing QL packs from qlpack.yml files..."
139138
140139
# Find all qlpack.yml files and install dependencies
141-
$qlpacks = Get-ChildItem -Path "javascript" -Filter "qlpack.yml" -Recurse
142-
143-
foreach ($qlpack in $qlpacks) {
144-
$dir = $qlpack.DirectoryName
145-
Write-Host "Installing packs for: $dir"
146-
Push-Location $dir
147-
try {
148-
codeql pack install
149-
} catch {
150-
Write-Warning "Failed to install packs in $dir : $_"
151-
}
152-
Pop-Location
153-
}
154-
155-
Write-Host "QL pack installation complete"
140+
find javascript -name "qlpack.yml" | while read qlpack; do
141+
dir=$(dirname "$qlpack")
142+
echo "Installing packs for: $dir"
143+
pushd "$dir" > /dev/null
144+
if ! codeql pack install; then
145+
echo "Warning: Failed to install packs in $dir"
146+
fi
147+
popd > /dev/null
148+
done
149+
150+
echo "QL pack installation complete"
156151
157152
- name: Setup Node.js for CDS compilation
158153
uses: actions/setup-node@v6
@@ -162,129 +157,112 @@ jobs:
162157
cache-dependency-path: 'extractors/cds/tools/package-lock.json'
163158

164159
- name: Verify Node.js and npm tools
165-
shell: pwsh
160+
shell: bash
166161
run: |
167-
Write-Host "Node.js version: $(node --version)"
168-
Write-Host "npm version: $(npm --version)"
169-
Write-Host "npx version: $(npx --version)"
162+
echo "Node.js version: $(node --version)"
163+
echo "npm version: $(npm --version)"
164+
echo "npx version: $(npx --version)"
170165
171166
# Verify npx can access @sap/cds-dk
172-
Write-Host "Testing npx access to @sap/cds-dk..."
173-
try {
174-
npx --yes --package @sap/cds-dk@latest cds --version
175-
} catch {
176-
Write-Host "CDS will be installed per-project as needed"
177-
}
167+
echo "Testing npx access to @sap/cds-dk..."
168+
if ! npx --yes --package @sap/cds-dk@latest cds --version 2>/dev/null; then
169+
echo "CDS will be installed per-project as needed"
170+
fi
178171
179172
- name: Compile CAP CDS files
180-
shell: cmd
173+
shell: bash
181174
run: |
182-
REM Use the dedicated CDS compilation script that follows the same logic
183-
REM as the CDS extractor's resolveCdsVersions function
184-
call extractors\cds\tools\workflow\cds-compilation-for-actions.cmd
175+
# Use the dedicated CDS compilation script that follows the same logic
176+
# as the CDS extractor's resolveCdsVersions function
177+
./extractors/cds/tools/workflow/cds-compilation-for-actions.sh
185178
186179
- name: Run CodeQL unit tests
187180
id: run-tests
188-
shell: pwsh
181+
shell: bash
189182
env:
190183
LGTM_INDEX_XML_MODE: all
191184
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
192185
run: |
193-
Write-Host "Running CodeQL unit tests for: ${{ matrix.test_suite }}"
186+
echo "Running CodeQL unit tests for: ${{ matrix.test_suite }}"
194187
195188
# Create results directory
196-
$resultsDir = Join-Path $env:RUNNER_TEMP "test-results"
197-
New-Item -ItemType Directory -Force -Path $resultsDir | Out-Null
189+
RESULTS_DIR="$RUNNER_TEMP/test-results"
190+
mkdir -p "$RESULTS_DIR"
198191
199192
# Get the test path for this matrix job
200-
$testPath = "${{ matrix.test_path }}"
193+
TEST_PATH="${{ matrix.test_path }}"
201194
202195
# Check if test path exists
203-
if (-not (Test-Path $testPath)) {
204-
Write-Host "⚠️ Test path does not exist: $testPath"
205-
Write-Host "Skipping tests for this suite"
196+
if [ ! -d "$TEST_PATH" ]; then
197+
echo "⚠️ Test path does not exist: $TEST_PATH"
198+
echo "Skipping tests for this suite"
206199
exit 0
207-
}
200+
fi
208201
209202
# Use CodeQL's strict test discovery to find valid tests
210-
Write-Host "Resolving tests with strict test discovery in: $testPath"
203+
echo "Resolving tests with strict test discovery in: $TEST_PATH"
211204
212-
$resolveOutputFile = Join-Path $resultsDir "resolve-output.txt"
213-
$resolveErrorFile = Join-Path $resultsDir "resolve-errors.txt"
205+
RESOLVE_OUTPUT_FILE="$RESULTS_DIR/resolve-output.txt"
206+
RESOLVE_ERROR_FILE="$RESULTS_DIR/resolve-errors.txt"
214207
215208
# Run codeql resolve tests with strict discovery
216-
$resolveProcess = Start-Process -FilePath "codeql" `
217-
-ArgumentList @("resolve", "tests", "--strict-test-discovery", "--format=text", "--", $testPath) `
218-
-Wait `
219-
-PassThru `
220-
-NoNewWindow `
221-
-RedirectStandardOutput $resolveOutputFile `
222-
-RedirectStandardError $resolveErrorFile
223-
224-
# Check if resolve succeeded
225-
if ($resolveProcess.ExitCode -ne 0) {
226-
Write-Host "❌ Failed to resolve tests"
227-
if (Test-Path $resolveErrorFile) {
228-
Get-Content $resolveErrorFile | Write-Host
229-
}
230-
exit $resolveProcess.ExitCode
231-
}
209+
if ! codeql resolve tests --strict-test-discovery --format=text -- "$TEST_PATH" > "$RESOLVE_OUTPUT_FILE" 2> "$RESOLVE_ERROR_FILE"; then
210+
echo "❌ Failed to resolve tests"
211+
if [ -f "$RESOLVE_ERROR_FILE" ]; then
212+
cat "$RESOLVE_ERROR_FILE"
213+
fi
214+
exit 1
215+
fi
232216
233217
# Read discovered test directories
234-
$testDirs = @()
235-
if (Test-Path $resolveOutputFile) {
236-
$testDirs = Get-Content $resolveOutputFile | Where-Object { $_.Trim() -ne "" }
237-
}
238-
239-
if ($testDirs.Count -eq 0) {
240-
Write-Host "⚠️ No valid test directories found in: $testPath"
241-
Write-Host "Skipping tests for this suite"
218+
TEST_DIRS=()
219+
if [ -f "$RESOLVE_OUTPUT_FILE" ]; then
220+
while IFS= read -r line; do
221+
if [ -n "$line" ]; then
222+
TEST_DIRS+=("$line")
223+
fi
224+
done < "$RESOLVE_OUTPUT_FILE"
225+
fi
226+
227+
if [ ${#TEST_DIRS[@]} -eq 0 ]; then
228+
echo "⚠️ No valid test directories found in: $TEST_PATH"
229+
echo "Skipping tests for this suite"
242230
exit 0
243-
}
231+
fi
244232
245-
Write-Host "Found $($testDirs.Count) valid test directory(ies):"
246-
$testDirs | ForEach-Object { Write-Host " - $_" }
247-
Write-Host ""
233+
echo "Found ${#TEST_DIRS[@]} valid test directory(ies):"
234+
printf " - %s\n" "${TEST_DIRS[@]}"
235+
echo ""
248236
249237
# Run tests using codeql test run
250-
Write-Host "Running: codeql test run --format=text -- $($testDirs -join ' ')"
238+
echo "Running: codeql test run --format=text -- ${TEST_DIRS[*]}"
251239
252-
$outputFile = Join-Path $resultsDir "test-output.txt"
253-
$errorFile = Join-Path $resultsDir "test-errors.txt"
254-
255-
# Build argument list for codeql test run
256-
$codeqlArgs = @("test", "run", "--format=text", "--")
257-
$codeqlArgs += $testDirs
240+
OUTPUT_FILE="$RESULTS_DIR/test-output.txt"
241+
ERROR_FILE="$RESULTS_DIR/test-errors.txt"
258242
259243
# Run tests and capture output
260-
$testProcess = Start-Process -FilePath "codeql" `
261-
-ArgumentList $codeqlArgs `
262-
-Wait `
263-
-PassThru `
264-
-NoNewWindow `
265-
-RedirectStandardOutput $outputFile `
266-
-RedirectStandardError $errorFile
244+
set +e
245+
codeql test run --format=text -- "${TEST_DIRS[@]}" > "$OUTPUT_FILE" 2> "$ERROR_FILE"
246+
TEST_EXIT_CODE=$?
247+
set -e
267248
268249
# Display output
269-
if (Test-Path $outputFile) {
270-
Get-Content $outputFile | Write-Host
271-
}
272-
273-
if (Test-Path $errorFile) {
274-
$errors = Get-Content $errorFile
275-
if ($errors) {
276-
Write-Host "Standard Error Output:"
277-
$errors | Write-Host
278-
}
279-
}
250+
if [ -f "$OUTPUT_FILE" ]; then
251+
cat "$OUTPUT_FILE"
252+
fi
253+
254+
if [ -f "$ERROR_FILE" ] && [ -s "$ERROR_FILE" ]; then
255+
echo "Standard Error Output:"
256+
cat "$ERROR_FILE"
257+
fi
280258
281259
# Check exit code
282-
if ($testProcess.ExitCode -ne 0) {
283-
Write-Host "❌ Tests failed with exit code: $($testProcess.ExitCode)"
284-
exit $testProcess.ExitCode
285-
}
260+
if [ $TEST_EXIT_CODE -ne 0 ]; then
261+
echo "❌ Tests failed with exit code: $TEST_EXIT_CODE"
262+
exit $TEST_EXIT_CODE
263+
fi
286264
287-
Write-Host "✅ Tests completed successfully"
265+
echo "✅ Tests completed successfully"
288266
289267
- name: Upload test results
290268
if: ${{ always() }}

0 commit comments

Comments
 (0)