forked from Kindest13/kiota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-vscode-releases.ps1
81 lines (78 loc) · 3.08 KB
/
update-vscode-releases.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[CmdletBinding(DefaultParameterSetName = 'Local')]
param (
[string]
[Parameter(Mandatory = $true, ParameterSetName = 'Local')]
[Parameter(Mandatory = $true, ParameterSetName = 'Online')]
$version,
[string]
[Parameter(Mandatory = $true, ParameterSetName = 'Local')]
[Parameter(Mandatory = $true, ParameterSetName = 'Online')]
$filePath,
[string]
[Parameter(Mandatory = $true, ParameterSetName = 'Local')]
[Parameter(Mandatory = $false, ParameterSetName = 'Online')]
$binaryFolderPath = "",
[switch]
[Parameter(Mandatory = $false, ParameterSetName = 'Online')]
$online
)
$version = $version.TrimStart("v")
$packageJson = Get-Content $filePath | ConvertFrom-Json
$packageJson.kiotaVersion = $version
$fragments = $version.Split("-preview.")
$versionParts = $fragments[0].Split(".")
$updatedPatchVersion = $versionParts[2].TrimStart("0")
if ($version -like "*-preview.*") {
$sequenceNumber = $fragments[1].Substring(8).TrimStart("0")
if ($sequenceNumber.Length -eq 1) {
$sequenceNumber = "0$sequenceNumber"
}
# regardless of the release channel, the highest version is the one that will be used
# for that reason, we make sure we have the same number of digits for patch versions regardless of the release channel
# and we max out the lower weight digits for the release version
# the new patch version will be following this format ppyyMMddss
# where
# pp is the patch version without heading zeros
# yyMMdd is the current date
# ss is the sequence number from ADO build arguably that maxes us to 99 previews per day
$updatedPatchVersion += (Get-Date).ToString("yyMMdd") + $sequenceNumber
}
else {
if ($updatedPatchVersion -eq "1") {
$updatedPatchVersion = "100000002"
}
elseif ([string]::IsNullOrWhiteSpace($updatedPatchVersion)) {
$updatedPatchVersion = "100000001"
}
}
$extensionVersion = $versionParts[0] + "." + $versionParts[1] + "." + $updatedPatchVersion
$packageJson.version = $extensionVersion
$runtimeDependencies = $packageJson.runtimeDependencies
if ($online) {
Write-Warning "Downloading binaries from GitHub."
$binaryFolderPath = Join-Path ($Env:TEMP ?? $PWD) ".kiota-vscode-$version" # $Env:TEMP is not available on GitHub Actions
New-Item -ItemType Directory -Force -Path $binaryFolderPath
foreach ($runtimeDependency in $runtimeDependencies) {
try {
$url = "https://github.com/microsoft/kiota/releases/download/v$version/$($runtimeDependency.platformId).zip"
Invoke-WebRequest -Uri $url -OutFile "$binaryFolderPath/$($runtimeDependency.platformId).zip"
}
catch {
Write-Warning "Could not download $url"
}
}
}
foreach ($runtimeDependency in $runtimeDependencies) {
$binPath = Join-Path -Path $binaryFolderPath -ChildPath "$($runtimeDependency.platformId).zip"
if (Test-Path $binPath) {
$runtimeDependency.sha256 = (Get-FileHash $binPath -Algorithm SHA256).Hash
}
else {
$runtimeDependency.sha256 = "placeholder"
Write-Warning "Could not find file $binPath"
}
}
Set-Content $filePath ($packageJson | ConvertTo-Json -Depth 10)
if ($online) {
Remove-Item -Recurse -Force $binaryFolderPath
}