Skip to content

Commit f2d8922

Browse files
authored
macOS: Cache only the latest version of CodeQL (#8420)
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 5c4b424 commit f2d8922

File tree

4 files changed

+35
-105
lines changed

4 files changed

+35
-105
lines changed
Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,28 @@
11
#!/bin/bash -e -o pipefail
22
source ~/utils/utils.sh
33

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

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

43-
# Download and name both CodeQL bundles.
44-
codeql_bundle_versions=("${codeql_bundle_version}" "${prior_codeql_bundle_version}")
45-
codeql_tag_names=("${codeql_tag_name}" "${prior_codeql_tag_name}")
15+
codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64"
16+
mkdir -p "$codeql_toolcache_path"
4617

47-
for index in "${!codeql_bundle_versions[@]}"; do
48-
bundle_version="${codeql_bundle_versions[$index]}"
49-
bundle_tag_name="${codeql_tag_names[$index]}"
50-
51-
echo "Downloading CodeQL bundle $bundle_version..."
52-
download_with_retries "https://github.com/github/codeql-action/releases/download/$bundle_tag_name/codeql-bundle.tar.gz" "/tmp" "codeql-bundle.tar.gz"
53-
codeql_archive="/tmp/codeql-bundle.tar.gz"
18+
echo "Unpacking the downloaded CodeQL bundle archive..."
19+
tar -xzf "$codeql_archive" -C "$codeql_toolcache_path"
5420

55-
codeql_toolcache_path="$AGENT_TOOLSDIRECTORY/CodeQL/$bundle_version/x64"
56-
mkdir -p "$codeql_toolcache_path"
21+
# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is
22+
# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
23+
touch "$codeql_toolcache_path/pinned-version"
5724

58-
echo "Unpacking the downloaded CodeQL bundle archive..."
59-
tar -xzf "$codeql_archive" -C "$codeql_toolcache_path"
25+
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
26+
touch "$codeql_toolcache_path.complete"
6027

61-
# We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
62-
if [[ "$bundle_version" == "$codeql_bundle_version" ]]; then
63-
touch "$codeql_toolcache_path/pinned-version"
64-
fi
65-
66-
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
67-
touch "$codeql_toolcache_path.complete"
68-
done
69-
70-
invoke_tests "Common" "CodeQLBundles"
28+
invoke_tests "Common" "CodeQL Bundle"

images/macos/software-report/SoftwareReport.Common.psm1

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,13 @@ function Build-MiscellaneousEnvironmentTable {
608608
}
609609
}
610610

611-
function Get-CodeQLBundleVersions {
612-
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
613-
$CodeQLVersionPaths = Get-ChildItem $CodeQLVersionsWildcard
614-
$CodeQlVersions=@()
615-
foreach ($CodeQLVersionPath in $CodeQLVersionPaths) {
616-
$FullCodeQLVersionPath = $CodeQLVersionPath | Select-Object -Expand FullName
617-
$CodeQLPath = Join-Path $FullCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
618-
$CodeQLVersion = & $CodeQLPath version --quiet
619-
$CodeQLVersions += $CodeQLVersion
620-
}
621-
return $CodeQLVersions
611+
612+
function Get-CodeQLBundleVersion {
613+
$CodeQLVersionWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
614+
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcard | Select-Object -First 1 -Expand FullName
615+
$CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
616+
$CodeQLVersion = & $CodeQLPath version --quiet
617+
return $CodeQLVersion
622618
}
623619

624620
function Get-ColimaVersion {

images/macos/software-report/SoftwareReport.Generator.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if (-not $os.IsVenturaArm64) {
172172
$tools.AddToolVersion("Cabal", $(Get-CabalVersion))
173173
}
174174
$tools.AddToolVersion("Cmake", $(Get-CmakeVersion))
175-
$tools.AddToolVersion("CodeQL Action Bundles", $(Get-CodeQLBundleVersions))
175+
$tools.AddToolVersion("CodeQL Action Bundle", $(Get-CodeQLBundleVersion))
176176
if ($os.IsMonterey) {
177177
$tools.AddToolVersion("Colima", $(Get-ColimaVersion))
178178
}

images/macos/tests/Common.Tests.ps1

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,39 +129,15 @@ Describe "VirtualBox" -Skip:($os.IsBigSur -or $os.IsVentura -or $os.IsVenturaArm
129129
}
130130
}
131131

132-
Describe "CodeQLBundles" {
133-
It "Latest CodeQL Bundle" {
134-
$CodeQLVersionWildcards = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
135-
$LatestCodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcards | Sort-Object -Property { [SemVer]$_.name } -Descending | Select-Object -First 1 -Expand FullName
136-
$LatestCodeQLPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
137-
"$LatestCodeQLPath version --quiet" | Should -ReturnZeroExitCode
138-
139-
$LatestCodeQLPacksPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
140-
$LatestCodeQLPacksPath | Should -Exist
141-
}
142-
143-
It "Prior CodeQL Bundle" {
144-
$CodeQLVersionWildcards = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
145-
$PriorCodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcards | Sort-Object -Property { [SemVer]$_.name } -Descending | Select-Object -Last 1 -Expand FullName
146-
$PriorCodeQLPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
147-
"$PriorCodeQLPath version --quiet" | Should -ReturnZeroExitCode
148-
149-
$PriorCodeQLPacksPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
150-
$PriorCodeQLPacksPath | Should -Exist
151-
}
152-
153-
It "Latest and Prior CodeQL Bundles are unique" {
154-
$CodeQLVersionWildcards = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
155-
156-
$LatestCodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcards | Sort-Object -Property { [SemVer]$_.name } -Descending | Select-Object -First 1 -Expand FullName
157-
$LatestCodeQLPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
158-
$LatestCodeQLVersion = & $LatestCodeQLPath version --quiet
159-
160-
$PriorCodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcards | Sort-Object -Property { [SemVer]$_.name } -Descending | Select-Object -Last 1 -Expand FullName
161-
$PriorCodeQLPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
162-
$PriorCodeQLVersion = & $PriorCodeQLPath version --quiet
163-
164-
$LatestCodeQLVersion | Should -Not -Match $PriorCodeQLVersion
132+
Describe "CodeQL Bundle" {
133+
It "Is installed" {
134+
$CodeQLVersionWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
135+
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionWildcard | Select-Object -First 1 -Expand FullName
136+
$CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql"
137+
"$CodeQLPath version --quiet" | Should -ReturnZeroExitCode
138+
139+
$CodeQLPacksPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
140+
$CodeQLPacksPath | Should -Exist
165141
}
166142
}
167143

0 commit comments

Comments
 (0)