|
1 | | -# Copyright (c) Microsoft Corporation. All rights reserved. |
2 | | -# Licensed under the MIT License. |
3 | | - |
4 | | -<# |
5 | | -.Synopsis |
6 | | - Gets the latest production release version of the specified NuGet package. |
7 | | -
|
8 | | -.Description |
9 | | - Gets the NuGet package version of latest production release and compares the |
10 | | - version to the version set in the specified project file. If they match, this |
11 | | - script will fail and indicate that the version needs to be updated. |
12 | | -
|
13 | | -.Parameter packageName |
14 | | - Specifies the package name of the package. For example, 'microsoft.kiota.abstractions' |
15 | | - is a valid package name. |
16 | | -
|
17 | | -.Parameter projectPath |
18 | | - Specifies the path to the project file. |
19 | | -#> |
20 | | - |
21 | | -Param( |
22 | | - [parameter(Mandatory = $true)] |
23 | | - [string]$packageName, |
24 | | - |
25 | | - [parameter(Mandatory = $true)] |
26 | | - [string]$projectPath |
27 | | -) |
28 | | - |
29 | | -[xml]$xmlDoc = Get-Content $projectPath |
30 | | - |
31 | | -# Assumption: VersionPrefix is set in the first property group. |
32 | | -$versionPrefixString = $xmlDoc.Project.PropertyGroup[0].VersionPrefix |
33 | | -if($xmlDoc.Project.PropertyGroup[0].VersionSuffix){ |
34 | | - $versionPrefixString = $versionPrefixString + "-" + $xmlDoc.Project.PropertyGroup[0].VersionSuffix |
35 | | -} |
36 | | - |
37 | | - |
38 | | -# System.Version, get the version prefix. |
39 | | -$currentProjectVersion = [System.Management.Automation.SemanticVersion]"$versionPrefixString" |
40 | | - |
41 | | -# API is case-sensitive |
42 | | -$packageName = $packageName.ToLower() |
43 | | -$url = "https://api.nuget.org/v3/registration5-gz-semver2/$packageName/index.json" |
44 | | - |
45 | | -# Call the NuGet API for the package and get the current published version. |
46 | | -Try { |
47 | | - $nugetIndex = Invoke-RestMethod -Uri $url -Method Get |
48 | | -} |
49 | | -Catch { |
50 | | - if ($_.ErrorDetails.Message && $_.ErrorDetails.Message.Contains("The specified blob does not exist.")) { |
51 | | - Write-Host "No package exists. You will probably be publishing $packageName for the first time." |
52 | | - Exit # exit gracefully |
53 | | - } |
54 | | - |
55 | | - Write-Host $_ |
56 | | - Exit 1 |
57 | | -} |
58 | | - |
59 | | -$currentPublishedVersion = [System.Management.Automation.SemanticVersion]$nugetIndex.items[0].upper |
60 | | - |
61 | | -# Validate that the version number has been updated. |
62 | | -if ($currentProjectVersion -le $currentPublishedVersion) { |
63 | | - |
64 | | - Write-Error "The current published version number, $currentPublishedVersion, and the version number ` |
65 | | - in the csproj file, $currentProjectVersion, match. You must increment the version" |
66 | | -} |
67 | | -else { |
68 | | - Write-Host "Validated that the version has been updated from $currentPublishedVersion to $currentProjectVersion" -ForegroundColor Green |
69 | | -} |
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +<# |
| 5 | +.Synopsis |
| 6 | + Gets the latest production release version of the specified NuGet package. |
| 7 | +
|
| 8 | +.Description |
| 9 | + Gets the NuGet package version of latest production release and compares the |
| 10 | + version to the version set in the specified project file. If they match, this |
| 11 | + script will fail and indicate that the version needs to be updated. |
| 12 | +
|
| 13 | +.Parameter packageName |
| 14 | + Specifies the package name of the package. For example, 'microsoft.kiota.abstractions' |
| 15 | + is a valid package name. |
| 16 | +
|
| 17 | +.Parameter projectPath |
| 18 | + Specifies the path to the project file. |
| 19 | +#> |
| 20 | + |
| 21 | +Param( |
| 22 | + [parameter(Mandatory = $true)] |
| 23 | + [string]$packageName, |
| 24 | + |
| 25 | + [parameter(Mandatory = $true)] |
| 26 | + [string]$projectPath |
| 27 | +) |
| 28 | + |
| 29 | +[xml]$xmlDoc = Get-Content $projectPath |
| 30 | + |
| 31 | +# Assumption: Version is set in the first property group. |
| 32 | +$versionString = $xmlDoc.Project.PropertyGroup[0].Version |
| 33 | + |
| 34 | +# System.Version, get the version. |
| 35 | +$currentProjectVersion = [System.Management.Automation.SemanticVersion]"$versionString" |
| 36 | + |
| 37 | +# API is case-sensitive |
| 38 | +$packageName = $packageName.ToLower() |
| 39 | +$url = "https://api.nuget.org/v3/registration5-gz-semver2/$packageName/index.json" |
| 40 | + |
| 41 | +# Call the NuGet API for the package and get the current published version. |
| 42 | +Try { |
| 43 | + $nugetIndex = Invoke-RestMethod -Uri $url -Method Get |
| 44 | +} |
| 45 | +Catch { |
| 46 | + if ($_.ErrorDetails.Message && $_.ErrorDetails.Message.Contains("The specified blob does not exist.")) { |
| 47 | + Write-Host "No package exists. You will probably be publishing $packageName for the first time." |
| 48 | + Exit # exit gracefully |
| 49 | + } |
| 50 | + |
| 51 | + Write-Host $_ |
| 52 | + Exit 1 |
| 53 | +} |
| 54 | + |
| 55 | +$currentPublishedVersion = [System.Management.Automation.SemanticVersion]$nugetIndex.items[0].upper |
| 56 | + |
| 57 | +# Validate that the version number has been updated. |
| 58 | +if ($currentProjectVersion -le $currentPublishedVersion) { |
| 59 | + |
| 60 | + Write-Error "The current published version number, $currentPublishedVersion, and the version number ` |
| 61 | + in the csproj file, $currentProjectVersion, match. You must increment the version" |
| 62 | +} |
| 63 | +else { |
| 64 | + Write-Host "Validated that the version has been updated from $currentPublishedVersion to $currentProjectVersion" -ForegroundColor Green |
| 65 | +} |
0 commit comments