Skip to content

Commit fe9e359

Browse files
committed
custom prune pwsh script
1 parent ec02b37 commit fe9e359

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

.github/workflows/publish-dev-package.yml

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,50 @@ jobs:
3535
mkdir pkgs
3636
dotnet pack --no-restore -c Release -p:PackageVersion=${{ steps.version.outputs.dev_version }} -o ./pkgs
3737
38-
#the prune command deletes older package versions to avoid -dev package clutter
39-
#it groups packages by -label, and keeps the 5 latest of each pre-release label (-rc1, -rc2, -dev, etc)
4038
- name: Publish to SpecterOps Packages
4139
env:
4240
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
4341
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
4442
run: |
4543
dotnet tool install -g sleet
46-
sleet push ./pkgs
47-
sleet retention prune --package SharpHoundCommon --package SharpHoundRPC `
48-
--stable -1 --prerelease 5 --release-labels 1 --dry-run
44+
45+
#the prune command deletes older -dev package versions to avoid clutter
46+
#it deletes any versions of the $packageIds with "-dev" that are older than the first $maxDevVersions
47+
- name: Prune old -dev packages
48+
shell: pwsh
49+
run: |
50+
$dryRun = $true
51+
$packageIndexUrl = 'https://s3.amazonaws.com/bloodhound-ad/sleet.packageindex.json'
52+
$packageIds = @('SharpHoundCommons', 'SharpHoundRPC')
53+
$maxDevVersions = 2
54+
55+
$packageIndex = Invoke-RestMethod -Uri $packageIndexUrl
56+
57+
foreach ($packageId in $packageIds) {
58+
$devPackages = @(
59+
foreach ($version in ($packageIndex.packages.$packageId | Where-Object { $_ -like '*-dev.*' })) {
60+
try {
61+
[pscustomobject]@{
62+
PackageId = $packageId
63+
Version = $version
64+
SemVer = [System.Management.Automation.SemanticVersion]$version
65+
}
66+
} catch {
67+
Write-Warning "Skipping unparseable version: $packageId $version"
68+
}
69+
}
70+
) | Sort-Object SemVer -Descending
71+
72+
Write-Host "Current $packageId -dev versions in feed:"
73+
$devPackages | Format-Table -AutoSize
74+
75+
$devPackages | Select-Object -Skip $maxDevVersions | ForEach-Object {
76+
if ($dryRun) {
77+
Write-Host "[DRY RUN] sleet delete --id $($_.PackageId) --version $($_.Version)"
78+
}
79+
else {
80+
Write-Host "Deleting $($_.PackageId) $($_.Version)";
81+
#sleet delete --id $_.PackageId --version $_.Version --reason "Prune old dev build"
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)