[Windows] Update Kotlin install (#4645)

This commit is contained in:
Nikolay Frolov
2021-12-08 10:39:42 +03:00
committed by GitHub
parent 7450e2dabe
commit 07a22999fe
6 changed files with 45 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ Export-ModuleMember -Function @(
'Choco-Install'
'Send-RequestToCocolateyPackages'
'Get-LatestChocoPackageVersion'
'Get-GitHubPackageDownloadUrl'
'Extract-7Zip'
'Get-CommandResult'
'Get-WhichTool'

View File

@@ -559,3 +559,30 @@ function Invoke-SBWithRetry {
}
}
}
function Get-GitHubPackageDownloadUrl {
param (
[string]$RepoOwner,
[string]$RepoName,
[string]$BinaryName,
[string]$Version,
[string]$UrlFilter,
[boolean]$IsPrerelease = $false,
[int]$SearchInCount = 100
)
if ($Version -eq "latest") {
$Version = "*"
}
$json = Invoke-RestMethod -Uri "https://api.github.com/repos/${RepoOwner}/${RepoName}/releases?per_page=${SearchInCount}"
$versionToDownload = ($json.Where{ $_.prerelease -eq $IsPrerelease }.tag_name |
Select-String -Pattern "\d+.\d+.\d+").Matches.Value |
Where-Object {$_ -Like "${Version}.*" -or $_ -eq ${Version}} |
Sort-Object {[version]$_} |
Select-Object -Last 1
$UrlFilter = $UrlFilter -replace "{BinaryName}",$BinaryName -replace "{Version}",$versionToDownload
$downloadUrl = $json.assets.browser_download_url -like $UrlFilter
return $downloadUrl
}

View File

@@ -4,9 +4,11 @@
################################################################################
# Install Kotlin
$url = "https://api.github.com/repos/JetBrains/kotlin/releases/latest"
[System.String] $kotlinLatest = (Invoke-RestMethod -Uri $url).assets.browser_download_url -match "kotlin-compiler"
$kotlinInstallerPath = Start-DownloadWithRetry -Url $kotlinLatest -Name "kotlin-compiler.zip"
$kotlinVersion = (Get-ToolsetContent).kotlin.version
$kotlinBinaryName = (Get-ToolsetContent).kotlin.binary_name
$kotlinDownloadUrl = Get-GitHubPackageDownloadUrl -RepoOwner "JetBrains" -RepoName "kotlin" -BinaryName $kotlinBinaryName -Version $kotlinVersion -UrlFilter "*{BinaryName}-{Version}.zip"
$kotlinInstallerPath = Start-DownloadWithRetry -Url $kotlinDownloadUrl -Name "$kotlinBinaryName.zip"
Write-Host "Expand Kotlin archive"
$kotlinPath = "C:\tools"

View File

@@ -435,5 +435,9 @@
},
"postgresql": {
"version": "14"
},
"kotlin": {
"version": "latest",
"binary_name": "kotlin-compiler"
}
}

View File

@@ -467,5 +467,9 @@
},
"postgresql": {
"version": "14"
},
"kotlin": {
"version": "latest",
"binary_name": "kotlin-compiler"
}
}

View File

@@ -318,5 +318,9 @@
},
"postgresql": {
"version": "14"
},
"kotlin": {
"version": "latest",
"binary_name": "kotlin-compiler"
}
}