66
77source ~ /utils/utils.sh
88
9+ # Retrieve the latest major version of the CodeQL Action to use in the base URL for downloading the bundle.
10+ [ -n " $API_PAT " ] && authString=(-H " Authorization: token ${API_PAT} " )
11+ releases=$( curl " ${authString[@]} " -s " https://api.github.com/repos/github/codeql-action/releases" )
12+
13+ # Get the release tags starting with v[0-9] and sort them in descending order, then parse the first one to get the major version.
14+ codeql_action_latest_major_version=$( echo " $releases " |
15+ jq -r ' .[].tag_name' |
16+ grep -E ' ^v[0-9]' |
17+ sort -nr |
18+ head -n 1 |
19+ sed -E ' s/^v([0-9]+).*/\1/' )
20+ if [ -z " $codeql_action_latest_major_version " ]; then
21+ echo " Error: Unable to find the latest major version of the CodeQL Action."
22+ exit 1
23+ fi
24+
925# Retrieve the CLI version of the latest CodeQL bundle.
10- defaults_json_path=$( download_with_retry https://raw.githubusercontent.com/github/codeql-action/v3 /src/defaults.json)
11- bundle_version=$( jq -r ' .cliVersion' $defaults_json_path )
26+ defaults_json_path=$( download_with_retry " https://raw.githubusercontent.com/github/codeql-action/v $codeql_action_latest_major_version /src/defaults.json" )
27+ bundle_version=$( jq -r ' .cliVersion' " $defaults_json_path " )
1228bundle_tag_name=" codeql-bundle-v$bundle_version "
1329
1430echo " Downloading CodeQL bundle $bundle_version ..."
@@ -17,16 +33,16 @@ echo "Downloading CodeQL bundle $bundle_version..."
1733archive_path=$( download_with_retry " https://github.com/github/codeql-action/releases/download/$bundle_tag_name /codeql-bundle.tar.gz" )
1834
1935codeql_toolcache_path=$AGENT_TOOLSDIRECTORY /CodeQL/$bundle_version /x64
20- mkdir -p $codeql_toolcache_path
36+ mkdir -p " $codeql_toolcache_path "
2137
2238echo " Unpacking the downloaded CodeQL bundle archive..."
23- tar -xzf $archive_path -C $codeql_toolcache_path
39+ tar -xzf " $archive_path " -C " $codeql_toolcache_path "
2440
2541# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is
2642# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
27- touch $codeql_toolcache_path /pinned-version
43+ touch " $codeql_toolcache_path /pinned-version"
2844
2945# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
30- touch $codeql_toolcache_path .complete
46+ touch " $codeql_toolcache_path .complete"
3147
3248invoke_tests " Common" " CodeQL Bundle"
0 commit comments