From 385913a4552915be25d3f85da83d1390c64e16db Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 16 May 2023 16:43:38 +0100 Subject: [PATCH 1/3] Windows: Simplify CodeQL toolcache version when tagged using semver --- .../Installers/Install-CodeQLBundle.ps1 | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 index 6c0aeecf8a7b..b04e5b1b8312 100644 --- a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 +++ b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 @@ -3,16 +3,36 @@ ## Desc: Install the CodeQL CLI Bundle to the toolcache. ################################################################################ -# Retrieve the name of the CodeQL bundle preferred by the Action (in the format codeql-bundle-YYYYMMDD). +# Retrieve the CLI versions and bundle tags of the latest two CodeQL bundles. $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 -# Convert the tag names to bundles with a version number (x.y.z-YYYYMMDD). -$CodeQLBundleVersion = $CodeQLCliVersion + "-" + $CodeQLTagName.split("-")[-1] -$PriorCodeQLBundleVersion = $PriorCodeQLCliVersion + "-" + $PriorCodeQLTagName.split("-")[-1] +# 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 +} else { + # 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] +} +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 +} else { + # 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] +} $Bundles = @( [PSCustomObject]@{ From c376b90ba5784bdf9a0411ec19ff862ae996cb9a Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Fri, 19 May 2023 13:43:39 +0100 Subject: [PATCH 2/3] Windows: Error if unsupported CodeQL bundle tag name --- images/win/scripts/Installers/Install-CodeQLBundle.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 index b04e5b1b8312..dad3717bd64a 100644 --- a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 +++ b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 @@ -16,22 +16,28 @@ if ($CodeQLTagName.split("-")[-1].StartsWith("v")) { # We don't need to include the tag name in the toolcache version number because it's derivable # from the CLI version. $CodeQLBundleVersion = $CodeQLCliVersion -} else { +} 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 -} else { +} 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 = @( From 92ec15f0e593ea5db6b38aaaf694c001c62799af Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 23 May 2023 18:34:58 +0100 Subject: [PATCH 3/3] Windows: Fix typos --- images/win/scripts/Installers/Install-CodeQLBundle.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 index dad3717bd64a..7a063cc2e04c 100644 --- a/images/win/scripts/Installers/Install-CodeQLBundle.ps1 +++ b/images/win/scripts/Installers/Install-CodeQLBundle.ps1 @@ -30,7 +30,7 @@ if ($PriorCodeQLTagName.split("-")[-1].StartsWith("v")) { # 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+$")) { +} 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.