|
| 1 | +#!/usr/bin/env pwsh |
| 2 | + |
| 3 | +#Requires -Version 7.0 |
| 4 | + |
| 5 | +[CmdletBinding()] |
| 6 | +param( |
| 7 | + [Parameter(Mandatory = $true, Position = 0)] |
| 8 | + [string] $SdkRoot |
| 9 | +) |
| 10 | + |
| 11 | +foreach ($serviceDirectory in (Join-Path $SdkRoot 'sdk' -Resolve | Get-ChildItem -Directory)) { |
| 12 | + foreach ($packageDirectory in (Get-ChildItem $serviceDirectory -Directory)) { |
| 13 | + foreach ($projectFile in (Join-Path $packageDirectory 'src' -Resolve -ErrorAction SilentlyContinue | Get-ChildItem -Filter *.csproj)) { |
| 14 | + $packageName = $projectFile.BaseName.ToLowerInvariant().Replace('.', '_') |
| 15 | + if (-not $packageName.StartsWith("azure")) { |
| 16 | + continue |
| 17 | + } |
| 18 | + $existingPackageName = $packageName |
| 19 | + |
| 20 | + [xml] $projectXml = Get-Content $projectFile |
| 21 | + $description = (([string]($projectXml.Project.PropertyGroup.Description -join '') -split "`n").Trim() -join ' ').Trim() |
| 22 | + |
| 23 | + $idx0 = $packageName.Substring(0, 2) |
| 24 | + $idx1 = $packageName.Substring(2, 2) |
| 25 | + |
| 26 | + $resp = Invoke-WebRequest "https://index.crates.io/$idx0/$idx1/$packageName" -SkipHttpErrorCheck |
| 27 | + if ($resp.StatusCode -eq 404) { |
| 28 | + $existingPackageName = $packageName -replace '_', '-' |
| 29 | + $resp = Invoke-WebRequest "https://index.crates.io/$idx0/$idx1/$existingPackageName" -SkipHttpErrorCheck |
| 30 | + } |
| 31 | + |
| 32 | + $exists = $resp.StatusCode -eq 200 |
| 33 | + $microsoftOwned = $false |
| 34 | + [string[]] $owners = $() |
| 35 | + |
| 36 | + if ($exists) { |
| 37 | + # If we found a package, get the publisher. There is a 1s per request rate limit. |
| 38 | + Start-Sleep -Seconds 1 |
| 39 | + |
| 40 | + $resp = Invoke-WebRequest "https://crates.io/api/v1/crates/$existingPackageName/owners" -SkipHttpErrorCheck |
| 41 | + if ($resp.StatusCode -ne 200) { |
| 42 | + Write-Error "No owner information for existing package $existingPackageName" |
| 43 | + continue |
| 44 | + } |
| 45 | + |
| 46 | + $json = $resp.Content | ConvertFrom-Json |
| 47 | + [string[]] $owners = $json.users.login |
| 48 | + $microsoftOwned = $owners -contains 'azure-sdk' -or $owners -contains 'heaths' -or $owners -contains 'github:azure:azure-sdk-publish-rust' |
| 49 | + |
| 50 | + } |
| 51 | + else { |
| 52 | + $existingPackageName = '' |
| 53 | + } |
| 54 | + |
| 55 | + [pscustomobject] @{ |
| 56 | + Name = $packageName |
| 57 | + Description = $description |
| 58 | + Exists = $exists |
| 59 | + ExistingPackageName = $existingPackageName |
| 60 | + MicrosoftOwned = $microsoftOwned -or $false |
| 61 | + Owners = $owners -join ';' |
| 62 | + Publish = $true |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments