2022-08-15 19:36:32 +02:00
|
|
|
#!/bin/bash -e -o pipefail
|
2023-11-28 02:25:03 +01:00
|
|
|
################################################################################
|
|
|
|
|
## File: install-codeql-bundle.sh
|
|
|
|
|
## Desc: Install CodeQL bundle
|
|
|
|
|
################################################################################
|
|
|
|
|
|
2022-08-15 19:36:32 +02:00
|
|
|
source ~/utils/utils.sh
|
|
|
|
|
|
2025-04-04 14:29:50 +02:00
|
|
|
# Retrieve the latest major version of the CodeQL Action to use in the base URL for downloading the bundle.
|
2025-04-25 11:43:01 -07:00
|
|
|
[ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}")
|
|
|
|
|
releases=$(curl "${authString[@]}" -s "https://api.github.com/repos/github/codeql-action/releases")
|
2025-04-04 14:29:50 +02:00
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
codeql_action_latest_major_version=$(echo "$releases" |
|
|
|
|
|
jq -r '.[].tag_name' |
|
|
|
|
|
grep -E '^v[0-9]' |
|
|
|
|
|
sort -nr |
|
|
|
|
|
head -n 1 |
|
|
|
|
|
sed -E 's/^v([0-9]+).*/\1/')
|
|
|
|
|
if [ -z "$codeql_action_latest_major_version" ]; then
|
|
|
|
|
echo "Error: Unable to find the latest major version of the CodeQL Action."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
# Retrieve the CLI version of the latest CodeQL bundle.
|
2025-04-21 15:16:01 -07:00
|
|
|
defaults_json_path=$(download_with_retry "https://raw.githubusercontent.com/github/codeql-action/v$codeql_action_latest_major_version/src/defaults.json")
|
2025-04-04 14:30:44 +02:00
|
|
|
bundle_version=$(jq -r '.cliVersion' "$defaults_json_path")
|
2023-10-17 21:18:48 +01:00
|
|
|
bundle_tag_name="codeql-bundle-v$bundle_version"
|
2022-08-15 19:36:32 +02:00
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
echo "Downloading CodeQL bundle $bundle_version..."
|
|
|
|
|
# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run
|
|
|
|
|
# different operating systems within containers.
|
2025-06-23 08:05:29 +00:00
|
|
|
archive_path=$(download_with_retry "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle-osx64.tar.gz")
|
2022-08-15 19:36:32 +02:00
|
|
|
|
2024-01-09 14:47:31 +01:00
|
|
|
codeql_toolcache_path=$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64
|
2025-04-04 14:30:44 +02:00
|
|
|
mkdir -p "$codeql_toolcache_path"
|
2022-08-15 19:36:32 +02:00
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
echo "Unpacking the downloaded CodeQL bundle archive..."
|
2025-04-04 14:30:44 +02:00
|
|
|
tar -xzf "$archive_path" -C "$codeql_toolcache_path"
|
2022-08-15 19:36:32 +02:00
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is
|
|
|
|
|
# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
|
2025-04-04 14:30:44 +02:00
|
|
|
touch "$codeql_toolcache_path/pinned-version"
|
2022-08-15 19:36:32 +02:00
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
|
2025-04-04 14:30:44 +02:00
|
|
|
touch "$codeql_toolcache_path.complete"
|
2022-08-17 11:06:58 +02:00
|
|
|
|
2023-10-17 21:18:48 +01:00
|
|
|
invoke_tests "Common" "CodeQL Bundle"
|