Skip to content

Commit 6c75e55

Browse files
committed
Updated nightly cleanup script
1 parent 7b848d3 commit 6c75e55

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

build/Unlist-Nightly.ps1

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
11
$ErrorActionPreference = "Stop"
22
Set-StrictMode -Version 2.0
33

4-
function CleanPackage {
4+
function UnlistNightlies {
55
param([string] $Package)
66
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
7-
$xml = Invoke-WebRequest -Uri "https://www.powershellgallery.com/api/v2/Search()?`$orderby=Id&`$skip=0&`$top=50&searchTerm='$Package'&targetFramework=''&includePrerelease=true"
8-
9-
$result = [xml] $xml
10-
11-
# There are other packages not owned by us that contain this string.
12-
$entries = $result.feed.entry | Where-Object{$_.properties.Id -eq "PnP.PowerShell"}
7+
8+
$entries = GetEntries "https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PnP.PowerShell'"
139

14-
$sortedEntries = $entries | Sort-Object -Property @{Expression = {[System.Management.Automation.SemanticVersion]::Parse($_.properties.version)}; Descending=$false} | Where-Object {[System.Management.Automation.SemanticVersion]::Parse($_.properties.version).PreReleaseLabel -eq "nightly"}
15-
$releasedEntries = $entries.Where({[System.Management.Automation.SemanticVersion]::Parse($_.properties.version).PreReleaseLabel -ne "nightly"} );
16-
# keep last 10
17-
$entriesToKeep = ($sortedEntries | Select-Object -Last 10) + $releasedEntries
10+
$sorted = $entries | Sort-Object -Property Version -Descending
11+
12+
# Get the nightly releases
13+
$nightlies = $sorted | Where-Object { $null -ne $_.Version.PreReleaseLabel }
1814

15+
# mark the latest 50 nightlies as unlisted
16+
$tounlist = $nightlies | Select-Object -First 50 -Skip 10
17+
1918
$key = $("$env:POWERSHELLGALLERY_API_KEY")
20-
foreach($entry in $entries)
21-
{
22-
if(!$entriesToKeep.Contains($entry))
23-
{
24-
Write-host "Entry to be deleted - $($entry.properties.Version)"
25-
nuget delete "package/$($entry.properties.Id)" $entry.properties.Version -ApiKey $key -Source https://www.powershellgallery.com/api/v2 -NonInteractive
19+
20+
foreach ($entry in $tounlist) {
21+
Write-host "Entry to be deleted - $($entry.Version.ToString())"
22+
nuget delete "package/$($entry.Id)" $entry.version.ToString() -ApiKey $key -Source https://www.powershellgallery.com/api/v2 -NonInteractive
23+
}
24+
}
25+
26+
function GetEntries([string] $url) {
27+
$entries = New-Object System.Collections.Generic.List[System.Object]
28+
29+
$result = Invoke-WebRequest -Uri $url
30+
$xml = [xml]$result
31+
32+
foreach ($entry in $xml.feed.entry) {
33+
$newEntry = [PSCustomObject]@{
34+
Id = $entry.id
35+
Version = [System.Management.Automation.SemanticVersion]$entry.properties.version
2636
}
37+
$entries.Add($newEntry)
38+
}
39+
40+
41+
$nextLink = $xml.feed.link | Where-Object { $_.rel -eq "next" }
42+
43+
if ($null -ne $nextLink) {
44+
$extraEntries = GetEntries $nextLink.href
45+
$entries.AddRange($extraEntries)
2746
}
47+
return $entries
2848
}
2949

3050
Write-host "Starting cleanup old nightlies job"
31-
CleanPackage "PnP.PowerShell"
51+
UnlistNightlies "PnP.PowerShell"

0 commit comments

Comments
 (0)