Skip to content

Commit 66a457d

Browse files
authored
Get package information based on Azure SDK for .NET names (Azure#2204)
* Get package information based on Azure SDK for .NET names * Reset variables With a `foreach` expression, variables never went out of scope and were never reset automatically. Need to do so manually. Also filters on "azure*" for package names.
1 parent 9fcbd12 commit 66a457d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

eng/scripts/Get-NetPackageInfo.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)