Skip to content

Commit fa18860

Browse files
authored
Linux: Cache only the latest version of CodeQL (#8419)
Previously, we cached two versions since we prioritized hitting the toolcache over landing new releases quicker. However after experimenting with this, we have decided to prioritize getting new releases into customers' hands more quickly.
1 parent b3852fe commit fa18860

File tree

4 files changed

+24
-84
lines changed

4 files changed

+24
-84
lines changed

images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ $tools.AddToolVersion("Bazelisk", $(Get-BazeliskVersion))
103103
$tools.AddToolVersion("Bicep", $(Get-BicepVersion))
104104
$tools.AddToolVersion("Buildah", $(Get-BuildahVersion))
105105
$tools.AddToolVersion("CMake", $(Get-CMakeVersion))
106-
$tools.AddToolVersion("CodeQL Action Bundles", $(Get-CodeQLBundleVersions))
106+
$tools.AddToolVersion("CodeQL Action Bundle", $(Get-CodeQLBundleVersion))
107107
$tools.AddToolVersion("Docker Amazon ECR Credential Helper", $(Get-DockerAmazonECRCredHelperVersion))
108108
$tools.AddToolVersion("Docker Compose v1", $(Get-DockerComposeV1Version))
109109
$tools.AddToolVersion("Docker Compose v2", $(Get-DockerComposeV2Version))

images/linux/scripts/SoftwareReport/SoftwareReport.Tools.psm1

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,12 @@ function Get-BicepVersion {
3030
return $Matches.Version
3131
}
3232

33-
function Get-CodeQLBundleVersions {
33+
function Get-CodeQLBundleVersion {
3434
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
35-
$CodeQLVersionPaths = Get-ChildItem $CodeQLVersionsWildcard
36-
$CodeQlVersions=@()
37-
foreach ($CodeQLVersionPath in $CodeQLVersionPaths) {
38-
$FullCodeQLVersionPath = $CodeQLVersionPath | Select-Object -Expand FullName
39-
$CodeQLPath = Join-Path $FullCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
40-
$CodeQLVersion = & $CodeQLPath version --quiet
41-
$CodeQLVersions += $CodeQLVersion
42-
}
43-
return $CodeQLVersions
35+
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Select-Object -First 1 -Expand FullName
36+
$CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
37+
$CodeQLVersion = & $CodeQLPath version --quiet
38+
return $CodeQLVersion
4439
}
4540

4641
function Get-PodManVersion {

images/linux/scripts/installers/codeql-bundle.sh

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,26 @@
66

77
source $HELPER_SCRIPTS/install.sh
88

9-
# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles.
9+
# Retrieve the CLI version of the latest CodeQL bundle.
1010
base_url="$(curl -fsSL https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json)"
11-
codeql_tag_name="$(echo "$base_url" | jq -r '.bundleVersion')"
12-
codeql_cli_version="$(echo "$base_url" | jq -r '.cliVersion')"
13-
prior_codeql_tag_name="$(echo "$base_url" | jq -r '.priorBundleVersion')"
14-
prior_codeql_cli_version="$(echo "$base_url" | jq -r '.priorCliVersion')"
11+
bundle_version="$(echo "$base_url" | jq -r '.cliVersion')"
12+
bundle_tag_name="codeql-bundle-v$bundle_version"
1513

16-
# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`.
17-
if [[ "${codeql_tag_name##*-}" == "v"* ]]; then
18-
# Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version.
19-
# We don't need to include the tag name in the toolcache version number because it's derivable
20-
# from the CLI version.
21-
codeql_bundle_version="$codeql_cli_version"
22-
elif [[ "${codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then
23-
# Tag name of the format `codeql-bundle-YYYYMMDD`.
24-
# We need to include the tag name in the toolcache version number because it can't be derived
25-
# from the CLI version.
26-
codeql_bundle_version="$codeql_cli_version-${codeql_tag_name##*-}"
27-
else
28-
echo "Unrecognised current CodeQL bundle tag name: $codeql_tag_name." \
29-
"Could not compute toolcache version number."
30-
exit 1
31-
fi
32-
if [[ "${prior_codeql_tag_name##*-}" == "v"* ]]; then
33-
# Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version.
34-
# We don't need to include the tag name in the toolcache version number because it's derivable
35-
# from the CLI version.
36-
prior_codeql_bundle_version="$prior_codeql_cli_version"
37-
elif [[ "${prior_codeql_tag_name##*-}" =~ ^[0-9]+$ ]]; then
38-
# Tag name of the format `codeql-bundle-YYYYMMDD`.
39-
# We need to include the tag name in the toolcache version number because it can't be derived
40-
# from the CLI version.
41-
prior_codeql_bundle_version="$prior_codeql_cli_version-${prior_codeql_tag_name##*-}"
42-
else
43-
echo "Unrecognised prior CodeQL bundle tag name: $prior_codeql_tag_name." \
44-
"Could not compute toolcache version number."
45-
exit 1
46-
fi
14+
echo "Downloading CodeQL bundle $bundle_version..."
15+
# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run
16+
# different operating systems within containers.
17+
download_with_retries "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle.tar.gz" "/tmp" "codeql-bundle.tar.gz"
18+
codeql_archive="/tmp/codeql-bundle.tar.gz"
4719

48-
# Download and name both CodeQL bundles.
49-
codeql_bundle_versions=("${codeql_bundle_version}" "${prior_codeql_bundle_version}")
50-
codeql_tag_names=("${codeql_tag_name}" "${prior_codeql_tag_name}")
20+
codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64"
21+
mkdir -p "$codeql_toolcache_path"
5122

52-
for index in "${!codeql_bundle_versions[@]}"; do
53-
bundle_version="${codeql_bundle_versions[$index]}"
54-
bundle_tag_name="${codeql_tag_names[$index]}"
55-
56-
echo "Downloading CodeQL bundle $bundle_version..."
57-
download_with_retries "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle.tar.gz" "/tmp" "codeql-bundle.tar.gz"
58-
codeql_archive="/tmp/codeql-bundle.tar.gz"
23+
echo "Unpacking the downloaded CodeQL bundle archive..."
24+
tar -xzf "$codeql_archive" -C "$codeql_toolcache_path"
5925

60-
codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64"
61-
mkdir -p "$codeql_toolcache_path"
26+
# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is
27+
# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
28+
touch "$codeql_toolcache_path/pinned-version"
6229

63-
echo "Unpacking the downloaded CodeQL bundle archive..."
64-
tar -xzf "$codeql_archive" -C "$codeql_toolcache_path"
65-
66-
# We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
67-
if [[ "$bundle_version" == "$codeql_bundle_version" ]]; then
68-
touch "$codeql_toolcache_path/pinned-version"
69-
fi
70-
71-
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
72-
touch "$codeql_toolcache_path.complete"
73-
done
30+
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
31+
touch "$codeql_toolcache_path.complete"

images/linux/scripts/tests/Toolset.Tests.ps1

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,7 @@ Describe "Toolset" {
6060
}
6161
}
6262
}
63-
64-
# Validate that there are two versions of CodeQL included.
65-
if ($toolName -eq "CodeQL") {
66-
$foundPriorVersion = Get-Item $expectedVersionPath `
67-
| Sort-Object -Property {[SemVer]$_.name} -Descending `
68-
| Select-Object -Last 1
69-
$foundPriorVersionPath = Join-Path $foundPriorVersion $tool.arch
70-
71-
$priorExecutablePath = Join-Path $foundPriorVersionPath "codeql/codeql"
72-
It "Validate prior version of codeql/codeql" -TestCases @{PriorExecutablePath = $priorExecutablePath} {
73-
$PriorExecutablePath | Should -Exist
74-
}
75-
}
7663
}
7764
}
7865
}
79-
}
66+
}

0 commit comments

Comments
 (0)