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+
5+ outputs :
6+ codeql-cli-version :
7+ description : " The version of the CodeQL CLI that was installed or retrieved from cache"
8+ value : ${{ steps.codeql-version.outputs.codeql-cli-version }}
9+
10+ runs :
11+ using : composite
12+ steps :
13+ - name : " CodeQL Version"
14+ id : codeql-version
15+ shell : bash
16+ run : |
17+ echo "Reading CodeQL CLI version from .codeqlversion file."
18+ CODEQL_CLI_VERSION=$(cat ./.codeqlversion)
19+ echo "CODEQL_CLI_VERSION=${CODEQL_CLI_VERSION}" >> $GITHUB_ENV
20+ echo "codeql-cli-version=${CODEQL_CLI_VERSION}" >> $GITHUB_OUTPUT
21+
22+ - name : Cache CodeQL
23+ id : cache-codeql
24+ uses : actions/cache@v4
25+ with :
26+ # A list of files, directories, and wildcard patterns to cache and restore
27+ path : ${{github.workspace}}/codeql_home
28+ # An explicit key for restoring and saving the cache
29+ key : codeql-home-${{ steps.codeql-version.outputs.codeql-cli-version }}
30+
31+ - name : Install CodeQL
32+ id : install-codeql
33+ if : steps.cache-codeql.outputs.cache-hit != 'true'
34+ shell : bash
35+ env :
36+ GITHUB_TOKEN : ${{ github.token }}
37+ CODEQL_HOME : ${{ github.workspace }}/codeql_home
38+ CODEQL_CLI_VERSION : ${{ steps.codeql-version.outputs.codeql-cli-version }}
39+ run : |
40+ echo "Installing CodeQL CLI v${CODEQL_CLI_VERSION}."
41+
42+ mkdir -p $CODEQL_HOME
43+ echo "Change directory to $CODEQL_HOME"
44+ pushd $CODEQL_HOME
45+
46+ echo "Downloading CodeQL CLI v${CODEQL_CLI_VERSION}."
47+ gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
48+
49+ echo "Unzipping CodeQL CLI."
50+ unzip -q codeql-linux64.zip
51+
52+ popd
53+ echo "Done."
54+ echo "codeql-cli-version=${CODEQL_CLI_VERSION}" >> $GITHUB_OUTPUT
55+
56+ - name : Add CodeQL to the PATH
57+ shell : bash
58+ env :
59+ CODEQL_HOME : ${{ github.workspace }}/codeql_home
60+ run : |
61+ echo "Adding CodeQL CLI to the PATH."
62+ echo "$CODEQL_HOME/codeql" >> $GITHUB_PATH
0 commit comments