msbuild

Форк
0
/
extract-artifact-archives.ps1 
63 строки · 2.3 Кб
1
# This script looks for each archive file in a directory and extracts it into the target directory.
2
# For example, the file "$InputPath/bin.tar.gz" extracts to "$ExtractPath/bin.tar.gz.extracted/**".
3
# Uses the "tar" utility added to Windows 10 / Windows 2019 that supports tar.gz and zip.
4
param(
5
  # Full path to directory where archives are stored.
6
  [Parameter(Mandatory=$true)][string] $InputPath,
7
  # Full path to directory to extract archives into. May be the same as $InputPath.
8
  [Parameter(Mandatory=$true)][string] $ExtractPath
9
)
10

11
$ErrorActionPreference = 'Stop'
12
Set-StrictMode -Version 2.0
13

14
$disableConfigureToolsetImport = $true
15

16
try {
17
  # `tools.ps1` checks $ci to perform some actions. Since the SDL
18
  # scripts don't necessarily execute in the same agent that run the
19
  # build.ps1/sh script this variable isn't automatically set.
20
  $ci = $true
21
  . $PSScriptRoot\..\tools.ps1
22

23
  Measure-Command {
24
    $jobs = @()
25

26
    # Find archive files for non-Windows and Windows builds.
27
    $archiveFiles = @(
28
      Get-ChildItem (Join-Path $InputPath "*.tar.gz")
29
      Get-ChildItem (Join-Path $InputPath "*.zip")
30
    )
31

32
    foreach ($targzFile in $archiveFiles) {
33
      $jobs += Start-Job -ScriptBlock {
34
        $file = $using:targzFile
35
        $fileName = [System.IO.Path]::GetFileName($file)
36
        $extractDir = Join-Path $using:ExtractPath "$fileName.extracted"
37

38
        New-Item $extractDir -ItemType Directory -Force | Out-Null
39

40
        Write-Host "Extracting '$file' to '$extractDir'..."
41

42
        # Pipe errors to stdout to prevent PowerShell detecting them and quitting the job early.
43
        # This type of quit skips the catch, so we wouldn't be able to tell which file triggered the
44
        # error. Save output so it can be stored in the exception string along with context.
45
        $output = tar -xf $file -C $extractDir 2>&1
46
        # Handle NZEC manually rather than using Exit-IfNZEC: we are in a background job, so we
47
        # don't have access to the outer scope.
48
        if ($LASTEXITCODE -ne 0) {
49
          throw "Error extracting '$file': non-zero exit code ($LASTEXITCODE). Output: '$output'"
50
        }
51

52
        Write-Host "Extracted to $extractDir"
53
      }
54
    }
55

56
    Receive-Job $jobs -Wait
57
  }
58
}
59
catch {
60
  Write-Host $_
61
  Write-PipelineTelemetryError -Force -Category 'Sdl' -Message $_
62
  ExitWithExitCode 1
63
}
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.