Skip to content

Commit 1f4af3b

Browse files
committed
Extract to same folder names
The tools use the full path as a bug ID and this makes everything re-create for every build.
1 parent 19ba785 commit 1f4af3b

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

scripts/azure-pipelines-package.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,8 @@ extends:
141141
$surrogateContents | Set-Content $destFile
142142
displayName: Generate the surrogate files
143143
- pwsh: |
144-
$nupkgs = (Get-ChildItem "$(Build.ArtifactStagingDirectory)\binaries-to-scan\*\*.*nupkg")
145-
foreach ($nupkg in $nupkgs) {
146-
$filename = $nupkg.Name.TrimEnd('.nupkg')
147-
$dest = "$(Build.ArtifactStagingDirectory)\binaries-to-scan\nuget_symbols-extracted\$filename"
148-
Write-Host "Extracting '$nupkg' to '$dest'..."
149-
Expand-Archive $nupkg $dest
150-
Remove-Item $nupkg
151-
}
144+
./scripts/extract-nupkg-files.ps1 `
145+
-SourcePath "$(Build.ArtifactStagingDirectory)\binaries-to-scan\*\*.*nupkg" `
146+
-DestinationPath "$(Build.ArtifactStagingDirectory)\binaries-to-scan\nuget_symbols-extracted" `
147+
-RemoveOriginal
152148
displayName: Extract all the .nupkg files

scripts/azure-templates-stages-package.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,9 @@ stages:
6666
Move-Item -Path '$(Build.ArtifactStagingDirectory)\output\' -Destination '.\output\'
6767
displayName: Prepare the build artifact for publishing
6868
- pwsh: |
69-
$nupkgs = (Get-ChildItem ".\output\nugets*\*.*nupkg")
70-
foreach ($nupkg in $nupkgs) {
71-
$filename = $nupkg.Name.TrimEnd('.nupkg')
72-
$dest = ".\output\extracted_nugets\$filename"
73-
Write-Host "Extracting '$nupkg' to '$dest'..."
74-
Expand-Archive $nupkg $dest
75-
}
69+
.\scripts\extract-nupkg-files.ps1 `
70+
-SourcePath ".\output\nugets*\*.*nupkg" `
71+
-DestinationPath ".\output\extracted_nugets"
7672
displayName: Extract all the .nupkg files for scanning
7773
publishArtifacts:
7874
- name: package_normal_windows

scripts/extract-nupkg-files.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env pwsh
2+
param(
3+
[Parameter(Mandatory = $true)]
4+
[string]$SourcePath,
5+
[Parameter(Mandatory = $true)]
6+
[string]$DestinationPath,
7+
[switch]$RemoveOriginal
8+
)
9+
10+
$ErrorActionPreference = 'Stop'
11+
12+
function Get-NuGetPackageInfo {
13+
param([string]$ExtractedPath)
14+
15+
try {
16+
# Get the folder name as fallback (this is the package ID)
17+
$packageId = Split-Path $ExtractedPath -Leaf
18+
19+
# Try to find the .nuspec file to get the version
20+
$nuspecFile = Get-ChildItem -Path $ExtractedPath -Filter "*.nuspec" -Recurse | Select-Object -First 1
21+
22+
# Get the package ID and version from the .nuspec
23+
[xml]$nuspec = Get-Content $nuspecFile.FullName
24+
$packageId = $nuspec.package.metadata.id
25+
$version = $nuspec.package.metadata.version
26+
27+
# Return folder name based on whether version contains dash
28+
if ($version.Contains('-')) {
29+
return "$packageId-Preview"
30+
} else {
31+
return "$packageId-Stable"
32+
}
33+
}
34+
catch {
35+
# If parsing fails, fall through
36+
}
37+
38+
return $null
39+
}
40+
41+
# Ensure the destination directory exists
42+
if (-not (Test-Path $DestinationPath)) {
43+
New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
44+
Write-Host "Created destination directory: $DestinationPath"
45+
}
46+
47+
# Find all .nupkg files
48+
$nupkgs = Get-ChildItem $SourcePath
49+
if ($nupkgs.Count -eq 0) {
50+
Write-Host "No .nupkg files found in: $SourcePath"
51+
return
52+
}
53+
Write-Host "Found $($nupkgs.Count) .nupkg file(s) to extract"
54+
55+
# Extract each .nupkg file
56+
foreach ($nupkg in $nupkgs) {
57+
$filename = $nupkg.Name.TrimEnd('.nupkg')
58+
Write-Host "Extracting '$nupkg' to default location: '$filename'..."
59+
60+
# Extract to default location first
61+
$defaultDest = Join-Path $DestinationPath $filename
62+
Expand-Archive -Path $nupkg.FullName -DestinationPath $defaultDest -Force
63+
64+
# Try to get package info from the nuspec to see if we should move
65+
$betterFolderName = Get-NuGetPackageInfo -ExtractedPath $defaultDest
66+
if ($betterFolderName -and $betterFolderName -ne $filename) {
67+
$finalDest = Join-Path $DestinationPath $betterFolderName
68+
Move-Item $defaultDest $finalDest
69+
Write-Host "Moved '$filename' to '$betterFolderName' based on nuspec info"
70+
}
71+
72+
if ($RemoveOriginal) {
73+
Remove-Item $nupkg.FullName -Force
74+
Write-Host "Removed original file: $($nupkg.FullName)"
75+
}
76+
}
77+
78+
Write-Host "Extraction completed successfully"

0 commit comments

Comments
 (0)