forked from pnp/pnpcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlist-nightly.ps1
35 lines (29 loc) · 1.26 KB
/
unlist-nightly.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
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 2.0
function CleanPackage {
param([string] $Package , [int] $VersionsToKeep, [string] $key)
# See https://docs.microsoft.com/en-us/nuget/api/search-autocomplete-service-resource for API details
$json = Invoke-WebRequest -Uri "https://api-v2v3search-0.nuget.org/autocomplete?id=$Package&prerelease=true" | ConvertFrom-Json
# Count the packages to unlist
$toUnlist = 0;
foreach ($version in $json.data) {
# Only automatically unlist for preview releases
if ($version.IndexOf("-") -gt -1) {
$toUnlist = $toUnlist + 1;
}
}
# Delete nightly versions
$unlisted = 0;
foreach ($version in $json.data) {
# Only automatically unlist for preview releases
if (($version.IndexOf("-") -gt -1) -and ($unlisted -lt ($toUnlist - $VersionsToKeep))) {
Write-Host "Unlisting $Package, version $version using key $($key.Substring(0,5))"
$unlisted = $unlisted + 1
nuget delete $Package $version $key -source https://api.nuget.org/v3/index.json -NonInteractive
}
}
}
$ApiKey = $("$env:NUGET_API_KEY")
CleanPackage "PnP.Core" 10 $ApiKey
CleanPackage "PnP.Core.Auth" 10 $ApiKey
CleanPackage "PnP.Framework" 10 $ApiKey