mirror of
https://github.com/actions/runner-images.git
synced 2025-12-29 13:17:53 +08:00
[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.
|
||||
################################################################################
|
||||
|
||||
# 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")
|
||||
$CodeQLTagName = $Defaults.bundleVersion
|
||||
$CodeQLCliVersion = $Defaults.cliVersion
|
||||
$PriorCodeQLTagName = $Defaults.priorBundleVersion
|
||||
$PriorCodeQLCliVersion = $Defaults.priorCliVersion
|
||||
$CliVersion = $Defaults.cliVersion
|
||||
$TagName = "codeql-bundle-v" + $CliVersion
|
||||
|
||||
# Compute the toolcache version number for each bundle. This is either `x.y.z` or `x.y.z-YYYYMMDD`.
|
||||
if ($CodeQLTagName.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.
|
||||
$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
|
||||
}
|
||||
Write-Host "Downloading CodeQL bundle $($CliVersion)..."
|
||||
# Note that this is the all-platforms CodeQL bundle, to support scenarios where customers run
|
||||
# different operating systems within containers.
|
||||
$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz"
|
||||
$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName
|
||||
|
||||
$Bundles = @(
|
||||
[PSCustomObject]@{
|
||||
TagName=$CodeQLTagName;
|
||||
BundleVersion=$CodeQLBundleVersion;
|
||||
},
|
||||
[PSCustomObject]@{
|
||||
TagName=$PriorCodeQLTagName;
|
||||
BundleVersion=$PriorCodeQLBundleVersion;
|
||||
}
|
||||
)
|
||||
$CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $CliVersion | Join-Path -ChildPath "x64"
|
||||
New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null
|
||||
|
||||
foreach ($Bundle in $Bundles) {
|
||||
Write-Host "Downloading CodeQL bundle $($Bundle.BundleVersion)..."
|
||||
$CodeQLBundlePath = Start-DownloadWithRetry -Url "https://github.com/github/codeql-action/releases/download/$($Bundle.TagName)/codeql-bundle.tar.gz" -Name "codeql-bundle.tar.gz"
|
||||
$DownloadDirectoryPath = (Get-Item $CodeQLBundlePath).Directory.FullName
|
||||
Write-Host "Unpacking the downloaded CodeQL bundle archive..."
|
||||
Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath
|
||||
$UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar"
|
||||
Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath
|
||||
|
||||
$CodeQLToolcachePath = Join-Path $Env:AGENT_TOOLSDIRECTORY -ChildPath "CodeQL" | Join-Path -ChildPath $Bundle.BundleVersion | Join-Path -ChildPath "x64"
|
||||
New-Item -Path $CodeQLToolcachePath -ItemType Directory -Force | Out-Null
|
||||
Write-Host "CodeQL bundle at $($CodeQLToolcachePath) contains the following directories:"
|
||||
Get-ChildItem -Path $CodeQLToolcachePath -Depth 2
|
||||
|
||||
Write-Host "Unpacking the downloaded CodeQL bundle archive..."
|
||||
Extract-7Zip -Path $CodeQLBundlePath -DestinationPath $DownloadDirectoryPath
|
||||
$UnGzipedCodeQLBundlePath = Join-Path $DownloadDirectoryPath "codeql-bundle.tar"
|
||||
Extract-7Zip -Path $UnGzipedCodeQLBundlePath -DestinationPath $CodeQLToolcachePath
|
||||
# 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.
|
||||
New-Item -ItemType file (Join-Path $CodeQLToolcachePath -ChildPath "pinned-version")
|
||||
|
||||
# We only pin the latest version in the toolcache, to support overriding the CodeQL version specified in defaults.json on GitHub Enterprise.
|
||||
if ($Bundle.BundleVersion -eq $CodeQLBundleVersion) {
|
||||
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"
|
||||
}
|
||||
# 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.
|
||||
Invoke-PesterTests -TestFile "Tools" -TestName "CodeQLBundles"
|
||||
Invoke-PesterTests -TestFile "Tools" -TestName "CodeQL Bundle"
|
||||
|
||||
Reference in New Issue
Block a user