forked from pnp/powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnlist-Nightly.ps1
51 lines (37 loc) · 1.69 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 2.0
function UnlistNightlies {
param([string] $Package)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
$entries = GetEntries "https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PnP.PowerShell'"
$sorted = $entries | Sort-Object -Property Version -Descending
# Get the nightly releases
$nightlies = $sorted | Where-Object { $null -ne $_.Version.PreReleaseLabel }
# mark the latest 50 nightlies as unlisted
$tounlist = $nightlies | Select-Object -First 50 -Skip 10
$key = $("$env:POWERSHELLGALLERY_API_KEY")
foreach ($entry in $tounlist) {
Write-host "Entry to be deleted - $($entry.Version.ToString())"
nuget delete "package/PnP.PowerShell" $entry.version.ToString() -ApiKey $key -Source https://www.powershellgallery.com/api/v2 -NonInteractive
}
}
function GetEntries([string] $url) {
$entries = New-Object System.Collections.Generic.List[System.Object]
$result = Invoke-WebRequest -Uri $url
$xml = [xml]$result
foreach ($entry in $xml.feed.entry) {
$newEntry = [PSCustomObject]@{
Id = $entry.id
Version = [System.Management.Automation.SemanticVersion]$entry.properties.version
}
$entries.Add($newEntry)
}
$nextLink = $xml.feed.link | Where-Object { $_.rel -eq "next" }
if ($null -ne $nextLink) {
$extraEntries = GetEntries $nextLink.href
$entries.AddRange($extraEntries)
}
return $entries
}
Write-host "Starting cleanup old nightlies job"
UnlistNightlies "PnP.PowerShell"