Skip to content

Commit ded86ef

Browse files
authored
[Windows] Always use the latest major version of CodeQL Action (#11947)
* [Windows] Always use the latest major version of CodeQL Action * Add missing `v` to CodeQL bundle URL
1 parent f346a37 commit ded86ef

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

images/windows/scripts/build/Install-CodeQLBundle.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,28 @@
33
## Desc: Install the CodeQL CLI Bundle to the toolcache.
44
################################################################################
55

6+
# Retrieve the latest major version of the CodeQL Action to use in the base URL for downloading the bundle.
7+
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/github/codeql-action/releases"
8+
9+
# Get the release tags starting with v[0-9] and sort them in descending order, then parse the first one to get the major version.
10+
$latestTag = $releases.tag_name |
11+
Where-Object { $_ -match '^v[0-9]' } |
12+
Sort-Object { [version]($_ -replace '^v','') } -Descending |
13+
Select-Object -First 1
14+
15+
if ([string]::IsNullOrEmpty($latestTag)) {
16+
Write-Error "Error: Unable to find the latest major version of the CodeQL Action."
17+
exit 1
18+
}
19+
if ($latestTag -match '^v([0-9]+)') {
20+
$codeqlActionLatestMajorVersion = $matches[1]
21+
} else {
22+
Write-Error "Error: Unable to parse the major version from the latest tag."
23+
exit 1
24+
}
25+
626
# Retrieve the CLI version of the latest CodeQL bundle.
7-
$defaults = (Invoke-RestMethod "https://raw.githubusercontent.com/github/codeql-action/v3/src/defaults.json")
27+
$defaults = (Invoke-RestMethod "https://raw.githubusercontent.com/github/codeql-action/v$($codeqlActionLatestMajorVersion)/src/defaults.json")
828
$cliVersion = $defaults.cliVersion
929
$tagName = "codeql-bundle-v" + $cliVersion
1030

0 commit comments

Comments
 (0)