[Windows] Cache only the latest version of CodeQL (#8421)
* Windows: Cache only the latest version of CodeQL 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. * Break Windows tests down into separate assertions * List contents of bundle after extracting
This commit is contained in:
@@ -3,75 +3,34 @@
|
|||||||
## Desc: Install the CodeQL CLI Bundle to the toolcache.
|
## Desc: Install the CodeQL CLI Bundle to the toolcache.
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles.
|
# Retrieve the CLI version of the latest CodeQL bundle.
|
||||||
$Defaults = (Invoke-RestMethod "https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json")
|
$Defaults = (Invoke-RestMethod "https://raw.githubusercontent.com/github/codeql-action/v2/src/defaults.json")
|
||||||
$CodeQLTagName = $Defaults.bundleVersion
|
$CliVersion = $Defaults.cliVersion
|
||||||
$CodeQLCliVersion = $Defaults.cliVersion
|
$TagName = "codeql-bundle-v" + $CliVersion
|
||||||
$PriorCodeQLTagName = $Defaults.priorBundleVersion
|
|
||||||
$PriorCodeQLCliVersion = $Defaults.priorCliVersion
|
|
||||||
|
|
||||||
# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`.
|
Write-Host "Downloading CodeQL bundle $($CliVersion)..."
|
||||||
if ($CodeQLTagName.split("-")[-1].StartsWith("v")) {
|
# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run
|
||||||
# Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version.
|
# different operating systems within containers.
|
||||||
# We don't need to include the tag name in the toolcache version number because it's derivable
|
$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz"
|
||||||
# from the CLI version.
|
$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName
|
||||||
$CodeQLBundleVersion = $CodeQLCliVersion
|
|
||||||
} elseif ($CodeQLTagName.split("-")[-1] -match "^\d+$") {
|
|
||||||
# Tag name of the format `codeql-bundle-YYYYMMDD`.
|
|
||||||
# We need to include the tag name in the toolcache version number because it can't be derived
|
|
||||||
# from the CLI version.
|
|
||||||
$CodeQLBundleVersion = $CodeQLCliVersion + "-" + $CodeQLTagName.split("-")[-1]
|
|
||||||
} else {
|
|
||||||
Write-Error "Unrecognised current CodeQL bundle tag name: $CodeQLTagName. Could not compute toolcache version number."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
if ($PriorCodeQLTagName.split("-")[-1].StartsWith("v")) {
|
|
||||||
# Tag name of the format `codeql-bundle-vx.y.z`, where x.y.z is the CLI version.
|
|
||||||
# We don't need to include the tag name in the toolcache version number because it's derivable
|
|
||||||
# from the CLI version.
|
|
||||||
$PriorCodeQLBundleVersion = $PriorCodeQLCliVersion
|
|
||||||
} elseif ($PriorCodeQLTagName.split("-")[-1] -match "^\d+$") {
|
|
||||||
# Tag name of the format `codeql-bundle-YYYYMMDD`.
|
|
||||||
# We need to include the tag name in the toolcache version number because it can't be derived
|
|
||||||
# from the CLI version.
|
|
||||||
$PriorCodeQLBundleVersion = $PriorCodeQLCliVersion + "-" + $PriorCodeQLTagName.split("-")[-1]
|
|
||||||
} else {
|
|
||||||
Write-Error "Unrecognised prior CodeQL bundle tag name: $PriorCodeQLTagName. Could not compute toolcache version number."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
$Bundles = @(
|
$CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $CliVersion | Join-Path -ChildPath "x64"
|
||||||
[PSCustomObject]@{
|
New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null
|
||||||
TagName=$CodeQLTagName;
|
|
||||||
BundleVersion=$CodeQLBundleVersion;
|
|
||||||
},
|
|
||||||
[PSCustomObject]@{
|
|
||||||
TagName=$PriorCodeQLTagName;
|
|
||||||
BundleVersion=$PriorCodeQLBundleVersion;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
foreach ($Bundle in $Bundles) {
|
Write-Host "Unpacking the downloaded CodeQL bundle archive..."
|
||||||
Write-Host "Downloading CodeQL bundle $($Bundle.BundleVersion)..."
|
Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath
|
||||||
$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($Bundle.TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz"
|
$UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar"
|
||||||
$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName
|
Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath
|
||||||
|
|
||||||
$CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $Bundle.BundleVersion | Join-Path -ChildPath "x64"
|
Write-Host "CodeQL bundle at $($CodeQLToolcachePath) contains the following directories:"
|
||||||
New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null
|
Get-ChildItem -Path $CodeQLToolcachePath -Depth 2
|
||||||
|
|
||||||
Write-Host "Unpacking the downloaded CodeQL bundle archive..."
|
# Touch a file to indicate to the CodeQL Action that this bundle shipped with the toolcache. This is
|
||||||
Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath
|
# to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
|
||||||
$UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar"
|
New-Item -ItemType file (Join-Path $CodeQLToolcachePath -ChildPath "pinned-version")
|
||||||
Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath
|
|
||||||
|
|
||||||
# We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
|
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
|
||||||
if ($Bundle.BundleVersion -eq $CodeQLBundleVersion) {
|
New-Item -ItemType file "$CodeQLToolcachePath.complete"
|
||||||
New-Item -ItemType file (Join-Path $CodeQLToolcachePath -ChildPath "pinned-version")
|
|
||||||
}
|
|
||||||
|
|
||||||
# Touch a file to indicate to the toolcache that setting up CodeQL is complete.
|
|
||||||
New-Item -ItemType file "$CodeQLToolcachePath.complete"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Test that the tools have been extracted successfully.
|
# Test that the tools have been extracted successfully.
|
||||||
Invoke-PesterTests -TestFile "Tools" -TestName "CodeQLBundles"
|
Invoke-PesterTests -TestFile "Tools" -TestName "CodeQL Bundle"
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ $tools.AddToolVersion("Bazelisk", $(Get-BazeliskVersion))
|
|||||||
$tools.AddToolVersion("Bicep", $(Get-BicepVersion))
|
$tools.AddToolVersion("Bicep", $(Get-BicepVersion))
|
||||||
$tools.AddToolVersion("Cabal", $(Get-CabalVersion))
|
$tools.AddToolVersion("Cabal", $(Get-CabalVersion))
|
||||||
$tools.AddToolVersion("CMake", $(Get-CMakeVersion))
|
$tools.AddToolVersion("CMake", $(Get-CMakeVersion))
|
||||||
$tools.AddToolVersion("CodeQL Action Bundles", $(Get-CodeQLBundleVersions))
|
$tools.AddToolVersion("CodeQL Action Bundle", $(Get-CodeQLBundleVersion))
|
||||||
$tools.AddToolVersion("Docker", $(Get-DockerVersion))
|
$tools.AddToolVersion("Docker", $(Get-DockerVersion))
|
||||||
$tools.AddToolVersion("Docker Compose v1", $(Get-DockerComposeVersion))
|
$tools.AddToolVersion("Docker Compose v1", $(Get-DockerComposeVersion))
|
||||||
$tools.AddToolVersion("Docker Compose v2", $(Get-DockerComposeVersionV2))
|
$tools.AddToolVersion("Docker Compose v2", $(Get-DockerComposeVersionV2))
|
||||||
|
|||||||
@@ -42,17 +42,12 @@ function Get-CMakeVersion {
|
|||||||
return $cmakeVersion
|
return $cmakeVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-CodeQLBundleVersions {
|
function Get-CodeQLBundleVersion {
|
||||||
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
||||||
$CodeQLVersionPaths = Get-ChildItem $CodeQLVersionsWildcard
|
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Select-Object -First 1 -Expand FullName
|
||||||
$CodeQlVersions=@()
|
$CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
||||||
foreach ($CodeQLVersionPath in $CodeQLVersionPaths) {
|
$CodeQLVersion = & $CodeQLPath version --quiet
|
||||||
$FullCodeQLVersionPath = $CodeQLVersionPath | Select-Object -Expand FullName
|
return $CodeQLVersion
|
||||||
$CodeQLPath = Join-Path $FullCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
|
||||||
$CodeQLVersion = & $CodeQLPath version --quiet
|
|
||||||
$CodeQLVersions += $CodeQLVersion
|
|
||||||
}
|
|
||||||
return $CodeQLVersions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-DockerVersion {
|
function Get-DockerVersion {
|
||||||
|
|||||||
@@ -21,41 +21,25 @@ Describe "Bazel" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "CodeQLBundles" {
|
Describe "CodeQL Bundle" {
|
||||||
It "Latest CodeQL Bundle" {
|
It "Single distribution installed" {
|
||||||
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
||||||
$LatestCodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -First 1 -Expand FullName
|
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Should -HaveCount 1
|
||||||
$LatestCodeQLPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
|
||||||
"$LatestCodeQLPath version --quiet" | Should -ReturnZeroExitCode
|
|
||||||
|
|
||||||
$LatestCodeQLPacksPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
|
|
||||||
$LatestCodeQLPacksPath | Should -Exist
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Prior CodeQL Bundle" {
|
It "Contains CodeQL executable" {
|
||||||
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
||||||
$PriorCodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -Last 1 -Expand FullName
|
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -First 1 -Expand FullName
|
||||||
$PriorCodeQLPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
$CodeQLPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
||||||
"$PriorCodeQLPath version --quiet" | Should -ReturnZeroExitCode
|
"$CodeQLPath version --quiet" | Should -ReturnZeroExitCode
|
||||||
|
|
||||||
$PriorCodeQLPacksPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
|
|
||||||
$PriorCodeQLPacksPath | Should -Exist
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Latest and Prior CodeQL Bundles are unique" {
|
It "Contains CodeQL packs" {
|
||||||
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
$CodeQLVersionsWildcard = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath "*"
|
||||||
|
$CodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -First 1 -Expand FullName
|
||||||
$LatestCodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -First 1 -Expand FullName
|
$CodeQLPacksPath = Join-Path $CodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "qlpacks"
|
||||||
$LatestCodeQLPath = Join-Path $LatestCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
$CodeQLPacksPath | Should -Exist
|
||||||
$LatestCodeQLVersion = & $LatestCodeQLPath version --quiet
|
|
||||||
|
|
||||||
$PriorCodeQLVersionPath = Get-ChildItem $CodeQLVersionsWildcard | Sort-Object -Descending | Select-Object -Last 1 -Expand FullName
|
|
||||||
$PriorCodeQLPath = Join-Path $PriorCodeQLVersionPath -ChildPath "x64" | Join-Path -ChildPath "codeql" | Join-Path -ChildPath "codeql.exe"
|
|
||||||
$PriorCodeQLVersion = & $PriorCodeQLPath version --quiet
|
|
||||||
|
|
||||||
$LatestCodeQLVersion | Should -Not -Match $PriorCodeQLVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "R" {
|
Describe "R" {
|
||||||
|
|||||||
Reference in New Issue
Block a user