|
| 1 | +# This script extracts all "*.nupkg" files and parses the ".nuspec" file. |
| 2 | +# It looks at the dependencies of that package and alerts if some dependencies |
| 3 | +# of this organization are not available. |
| 4 | + |
| 5 | +$Organization = "NexusMods" |
| 6 | + |
| 7 | +$nupkgs = Get-ChildItem -Path "*" -Recurse -Include "*.nupkg" |
| 8 | + |
| 9 | +$allPackages = [System.Collections.Generic.HashSet[string]]::new() |
| 10 | +$allDependencies = [System.Collections.Generic.HashSet[string]]::new() |
| 11 | + |
| 12 | +foreach ($item in $nupkgs) |
| 13 | +{ |
| 14 | + $packageName = [System.IO.Path]::GetFileName( |
| 15 | + [System.IO.Path]::GetDirectoryName( |
| 16 | + [System.IO.Path]::GetDirectoryName( |
| 17 | + [System.IO.Path]::GetDirectoryName($item)))) |
| 18 | + |
| 19 | + $allPackages.Add($packageName) |
| 20 | + $extractedPath = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($item.FullName), "extracted") |
| 21 | + |
| 22 | + Expand-Archive -Path $item.FullName -DestinationPath $extractedPath -Force |
| 23 | + |
| 24 | + $nuspecFilePath = [System.IO.Path]::Combine($extractedPath, $packageName + ".nuspec") |
| 25 | + |
| 26 | + if (![System.IO.File]::Exists($nuspecFilePath)) { |
| 27 | + echo "File $nuspecFilePath does not exist!" |
| 28 | + exit 1 |
| 29 | + } |
| 30 | + |
| 31 | + # Select-Xml doesn't want to work for whatever reason |
| 32 | + #$dependencies = Select-Xml -Path $nuspecFilePath -XPath "//dependency" |
| 33 | + |
| 34 | + $xml = ([xml](Get-Content -Path $nuspecFilePath)) |
| 35 | + $dependencies = $xml.ChildNodes[1].ChildNodes.dependencies.group.dependency.id |
| 36 | + |
| 37 | + foreach ($dep in $dependencies) { |
| 38 | + if (!$dep.StartsWith($Organization)) { |
| 39 | + continue |
| 40 | + } |
| 41 | + |
| 42 | + $allDependencies.Add($dep) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +$allDependencies.ExceptWith($allPackages) |
| 47 | + |
| 48 | +foreach ($missing in $allDependencies) { |
| 49 | + echo "The following package wasn't packed: $missing" |
| 50 | +} |
| 51 | + |
| 52 | +if ($allDependencies.Count -ne 0) { |
| 53 | + exit 1 |
| 54 | +} else { |
| 55 | + echo "All packages are correct" |
| 56 | +} |
0 commit comments