Skip to content

Commit d3871a8

Browse files
authored
Merge pull request #87 from GitHubSecurityLab/ci/installcodeql
Install a specific CodeQL version.
2 parents 7110e6e + 54132d4 commit d3871a8

File tree

2 files changed

+68
-29
lines changed

2 files changed

+68
-29
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Setup CodeQL CLI
2+
description: |
3+
Install a CodeQL CLI or re-use an existing one from the cache and it to the path.
4+
inputs:
5+
codeql-cli-version:
6+
description: |
7+
The version of the CodeQL CLI to be downloaded.
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Cache CodeQL
13+
id: cache-codeql
14+
uses: actions/cache@v4
15+
with:
16+
# A list of files, directories, and wildcard patterns to cache and restore
17+
path: ${{github.workspace}}/codeql_home
18+
# An explicit key for restoring and saving the cache
19+
key: codeql-home-${{ inputs.codeql-cli-version }}
20+
21+
- name: Install CodeQL
22+
if: steps.cache-codeql.outputs.cache-hit != 'true'
23+
shell: bash
24+
env:
25+
GITHUB_TOKEN: ${{ github.token }}
26+
CODEQL_HOME: ${{ github.workspace }}/codeql_home
27+
CODEQL_CLI_VERSION: ${{ inputs.codeql-cli-version }}
28+
run: |
29+
mkdir -p $CODEQL_HOME
30+
echo "Change directory to $CODEQL_HOME"
31+
pushd $CODEQL_HOME
32+
33+
echo "Downloading CodeQL CLI v${CODEQL_CLI_VERSION}."
34+
gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
35+
36+
echo "Unzipping CodeQL CLI."
37+
unzip -q codeql-linux64.zip
38+
39+
popd
40+
echo "Done."
41+
42+
- name: Add CodeQL to the PATH
43+
shell: bash
44+
env:
45+
CODEQL_HOME: ${{ github.workspace }}/codeql_home
46+
run: |
47+
echo "Adding CodeQL CLI to the PATH."
48+
echo "$CODEQL_HOME/codeql" >> $GITHUB_PATH

.github/workflows/ci.yml

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
branches: [ main ]
66
workflow_dispatch:
77

8+
env:
9+
CODEQL_CLI_VERSION: 2.19.2
10+
811
jobs:
912
compile-and-test:
1013
runs-on: ubuntu-latest
@@ -25,15 +28,12 @@ jobs:
2528
src:
2629
- '${{ matrix.language }}/**'
2730
28-
- name: Initialize CodeQL
31+
- name: Setup CodeQL
2932
if: steps.changes.outputs.src == 'true'
30-
run: |
31-
VERSION="$(find "${{ runner.tool_cache }}/CodeQL/" -maxdepth 1 -mindepth 1 -type d -print \
32-
| sort \
33-
| tail -n 1 \
34-
| tr -d '\n')"
35-
echo "$VERSION/x64/codeql" >> $GITHUB_PATH
36-
33+
uses: ./.github/actions/install-codeql
34+
with:
35+
codeql-cli-version: ${{ env.CODEQL_CLI_VERSION }}
36+
3737
- name: Install Packs
3838
if: steps.changes.outputs.src == 'true'
3939
env:
@@ -171,14 +171,11 @@ jobs:
171171
src:
172172
- '${{ matrix.language }}/ext/**'
173173
174-
- name: Initialize CodeQL
174+
- name: Setup CodeQL
175175
if: steps.changes.outputs.src == 'true'
176-
run: |
177-
VERSION="$(find "${{ runner.tool_cache }}/CodeQL/" -maxdepth 1 -mindepth 1 -type d -print \
178-
| sort \
179-
| tail -n 1 \
180-
| tr -d '\n')"
181-
echo "$VERSION/x64/codeql" >> $GITHUB_PATH
176+
uses: ./.github/actions/install-codeql
177+
with:
178+
codeql-cli-version: ${{ env.CODEQL_CLI_VERSION }}
182179

183180
- name: Install Packs
184181
if: steps.changes.outputs.src == 'true'
@@ -209,14 +206,11 @@ jobs:
209206
src:
210207
- '${{ matrix.language }}/ext-library-sources/**'
211208
212-
- name: Initialize CodeQL
209+
- name: Setup CodeQL
213210
if: steps.changes.outputs.src == 'true'
214-
run: |
215-
VERSION="$(find "${{ runner.tool_cache }}/CodeQL/" -maxdepth 1 -mindepth 1 -type d -print \
216-
| sort \
217-
| tail -n 1 \
218-
| tr -d '\n')"
219-
echo "$VERSION/x64/codeql" >> $GITHUB_PATH
211+
uses: ./.github/actions/install-codeql
212+
with:
213+
codeql-cli-version: ${{ env.CODEQL_CLI_VERSION }}
220214

221215
- name: Install CodeQL
222216
if: steps.changes.outputs.src == 'true'
@@ -240,14 +234,11 @@ jobs:
240234
src:
241235
- 'configs/**'
242236
243-
- name: Initialize CodeQL
237+
- name: Setup CodeQL
244238
if: steps.changes.outputs.src == 'true'
245-
run: |
246-
VERSION="$(find "${{ runner.tool_cache }}/CodeQL/" -maxdepth 1 -mindepth 1 -type d -print \
247-
| sort \
248-
| tail -n 1 \
249-
| tr -d '\n')"
250-
echo "$VERSION/x64/codeql" >> $GITHUB_PATH
239+
uses: ./.github/actions/install-codeql
240+
with:
241+
codeql-cli-version: ${{ env.CODEQL_CLI_VERSION }}
251242

252243
- name: "Check Configurations"
253244
if: steps.changes.outputs.src == 'true'

0 commit comments

Comments
 (0)