Skip to content

Commit 511240b

Browse files
committed
Fix attempt for codeql-path-tests job
1 parent bd064b7 commit 511240b

File tree

2 files changed

+22
-51
lines changed

2 files changed

+22
-51
lines changed

.github/actions/setup-codeql-environment/action.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: 'Setup CodeQL Environment with Languages'
22
description: 'Install and configure CodeQL CLI via GitHub CLI extension and language-specific tools with optimized caching'
33

44
inputs:
5+
add-to-path:
6+
description: 'Whether to install the CodeQL stub to PATH and set CODEQL_HOME/CODEQL_PATH environment variables. Set to false when you need only the gh-codeql extension installed (e.g. for CODEQL_PATH tests that manage PATH themselves).'
7+
required: false
8+
default: 'true'
59
install-language-runtimes:
610
description: 'Whether to install language-specific runtimes and build tools'
711
required: false
@@ -136,7 +140,13 @@ runs:
136140
exit 1
137141
fi
138142
139-
# Create a directory for the CodeQL stub and install it there
143+
echo "✅ GitHub CLI CodeQL extension installed successfully"
144+
145+
# Install the CodeQL stub to PATH (skipped when add-to-path is false)
146+
- name: Install CodeQL stub to PATH
147+
if: inputs.add-to-path == 'true'
148+
shell: bash
149+
run: |
140150
CODEQL_STUB_DIR="$HOME/.local/bin"
141151
mkdir -p "$CODEQL_STUB_DIR"
142152
@@ -147,7 +157,7 @@ runs:
147157
export PATH="$CODEQL_STUB_DIR:$PATH"
148158
echo "PATH=$PATH" >> "$GITHUB_ENV"
149159
150-
echo "✅ GitHub CLI CodeQL extension installed successfully"
160+
echo "✅ CodeQL stub installed to PATH"
151161
152162
# On Windows, gh codeql install-stub creates a bash script which is not
153163
# discoverable by Node.js child_process.spawn() or execFile(), since
@@ -157,7 +167,7 @@ runs:
157167
# This workaround can be removed once github/gh-codeql#21 is merged,
158168
# which adds native Windows support to install-stub.
159169
- name: Add CodeQL binary directory to PATH (Windows)
160-
if: runner.os == 'Windows'
170+
if: runner.os == 'Windows' && inputs.add-to-path == 'true'
161171
shell: bash
162172
run: |
163173
echo "🔧 Locating actual codeql.exe binary for Windows compatibility..."
@@ -193,6 +203,7 @@ runs:
193203
echo "✅ Added CodeQL binary directory to PATH for Windows"
194204
195205
- name: Setup CodeQL environment variables
206+
if: inputs.add-to-path == 'true'
196207
id: setup-codeql-env
197208
shell: bash
198209
run: |
@@ -243,6 +254,7 @@ runs:
243254
244255
# Verify CodeQL installation
245256
- name: Verify `codeql` CLI installation
257+
if: inputs.add-to-path == 'true'
246258
shell: bash
247259
run: |
248260
echo "=== CodeQL Installation Verification ==="

.github/workflows/client-integration-tests.yml

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -169,53 +169,11 @@ jobs:
169169
- name: CODEQL_PATH Tests - Build server bundle
170170
run: npm run bundle -w server
171171

172-
- name: CODEQL_PATH Tests - Cache gh-codeql extension (Unix)
173-
if: runner.os != 'Windows'
174-
uses: actions/cache@v4
175-
with:
176-
path: ~/.local/share/gh-codeql
177-
key: codeql-path-tests-${{ runner.os }}-${{ hashFiles('.codeql-version') }}
178-
179-
- name: CODEQL_PATH Tests - Cache gh-codeql extension (Windows)
180-
if: runner.os == 'Windows'
181-
uses: actions/cache@v4
172+
- name: CODEQL_PATH Tests - Setup CodeQL environment
173+
uses: ./.github/actions/setup-codeql-environment
182174
with:
183-
path: ~\AppData\Local\GitHub\gh-codeql
184-
key: codeql-path-tests-${{ runner.os }}-${{ hashFiles('.codeql-version') }}
185-
186-
- name: CODEQL_PATH Tests - Install CodeQL CLI via gh codeql
187-
id: install-codeql
188-
shell: bash
189-
env:
190-
GH_TOKEN: ${{ github.token }}
191-
run: |
192-
CODEQL_VERSION=$(tr -d '[:space:]' < .codeql-version | sed 's/^v//')
193-
echo "Installing CodeQL CLI version: $CODEQL_VERSION"
194-
195-
# Check if the gh-codeql extension is already installed
196-
if ! gh extension list | grep -q "github/gh-codeql"; then
197-
echo "Installing gh-codeql extension..."
198-
gh extension install github/gh-codeql
199-
else
200-
echo "gh-codeql extension is already installed"
201-
fi
202-
203-
# Verify the extension is available before using it
204-
if ! gh codeql version &>/dev/null; then
205-
echo "::error::gh codeql extension is not working properly"
206-
exit 1
207-
fi
208-
209-
gh codeql set-version "$CODEQL_VERSION"
210-
211-
INSTALLED=$(gh codeql version --format=terse)
212-
if [[ "$INSTALLED" != "$CODEQL_VERSION" ]]; then
213-
echo "::error::Version mismatch: installed=$INSTALLED expected=$CODEQL_VERSION"
214-
exit 1
215-
fi
216-
217-
echo "✅ CodeQL CLI $INSTALLED installed via gh-codeql"
218-
echo "codeql-version=$CODEQL_VERSION" >> "$GITHUB_OUTPUT"
175+
add-to-path: false
176+
install-language-runtimes: false
219177

220178
## Locate the real CodeQL binary (not the gh-codeql bash stub).
221179
## The stub delegates to `gh codeql` and works from bash, but Node.js
@@ -250,13 +208,14 @@ jobs:
250208
251209
# Verify the binary works and reports the expected version
252210
ACTUAL=$("$CODEQL_BINARY" version --format=terse 2>/dev/null)
253-
EXPECTED="${{ steps.install-codeql.outputs.codeql-version }}"
211+
EXPECTED=$(codeql version --format=terse 2>/dev/null)
254212
if [[ "$ACTUAL" != "$EXPECTED" ]]; then
255213
echo "::error::Binary version mismatch: got '$ACTUAL', expected '$EXPECTED'"
256214
exit 1
257215
fi
258216
259217
echo "✅ CodeQL binary verified: $CODEQL_BINARY (version $ACTUAL)"
218+
echo "codeql-version=$ACTUAL" >> "$GITHUB_OUTPUT"
260219
echo "codeql-binary=$CODEQL_BINARY" >> "$GITHUB_OUTPUT"
261220
262221
## Build a PATH that excludes every directory containing 'codeql'.
@@ -316,6 +275,6 @@ jobs:
316275
echo "" >> $GITHUB_STEP_SUMMARY
317276
echo "| Detail | Value |" >> $GITHUB_STEP_SUMMARY
318277
echo "| ------ | ----- |" >> $GITHUB_STEP_SUMMARY
319-
echo "| CodeQL Version | ${{ steps.install-codeql.outputs.codeql-version }} |" >> $GITHUB_STEP_SUMMARY
278+
echo "| CodeQL Version | ${{ steps.locate-codeql.outputs.codeql-version }} |" >> $GITHUB_STEP_SUMMARY
320279
echo "| CodeQL Binary | \`${{ steps.locate-codeql.outputs.codeql-binary }}\` |" >> $GITHUB_STEP_SUMMARY
321280
echo "| OS | ${{ matrix.os }} |" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)