[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx ...
[mono-project.git] / eng / common / sdl / extract-artifact-packages.ps1
blobd857ae21972d6235d2a36a055680ee5bae127368
1 param(
2 [Parameter(Mandatory=$true)][string] $InputPath, # Full path to directory where artifact packages are stored
3 [Parameter(Mandatory=$true)][string] $ExtractPath # Full path to directory where the packages will be extracted
6 $ErrorActionPreference = "Stop"
7 Set-StrictMode -Version 2.0
9 # `tools.ps1` checks $ci to perform some actions. Since the post-build
10 # scripts don't necessarily execute in the same agent that run the
11 # build.ps1/sh script this variable isn't automatically set.
12 $ci = $true
13 $disableConfigureToolsetImport = "true"
14 . $PSScriptRoot\..\tools.ps1
16 $ExtractPackage = {
17 param(
18 [string] $PackagePath # Full path to a NuGet package
21 if (!(Test-Path $PackagePath)) {
22 Write-PipelineTaskError "Input file does not exist: $PackagePath"
23 ExitWithExitCode 1
26 $RelevantExtensions = @(".dll", ".exe", ".pdb")
27 Write-Host -NoNewLine "Extracting" ([System.IO.Path]::GetFileName($PackagePath)) "... "
29 $PackageId = [System.IO.Path]::GetFileNameWithoutExtension($PackagePath)
30 $ExtractPath = Join-Path -Path $using:ExtractPath -ChildPath $PackageId
32 Add-Type -AssemblyName System.IO.Compression.FileSystem
34 [System.IO.Directory]::CreateDirectory($ExtractPath);
36 try {
37 $zip = [System.IO.Compression.ZipFile]::OpenRead($PackagePath)
39 $zip.Entries |
40 Where-Object {$RelevantExtensions -contains [System.IO.Path]::GetExtension($_.Name)} |
41 ForEach-Object {
42 $TargetFile = Join-Path -Path $ExtractPath -ChildPath $_.Name
44 [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $TargetFile, $true)
47 catch {
50 finally {
51 $zip.Dispose()
54 function ExtractArtifacts {
55 if (!(Test-Path $InputPath)) {
56 Write-Host "Input Path does not exist: $InputPath"
57 ExitWithExitCode 0
59 $Jobs = @()
60 Get-ChildItem "$InputPath\*.nupkg" |
61 ForEach-Object {
62 $Jobs += Start-Job -ScriptBlock $ExtractPackage -ArgumentList $_.FullName
65 foreach ($Job in $Jobs) {
66 Wait-Job -Id $Job.Id | Receive-Job
70 try {
71 Measure-Command { ExtractArtifacts }
73 catch {
74 Write-Host $_
75 Write-Host $_.Exception
76 Write-Host $_.ScriptStackTrace
77 ExitWithExitCode 1