forked from microsoft/azure-pipelines-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compress-Tasks.ps1
37 lines (32 loc) · 1.22 KB
/
Compress-Tasks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$SourceRoot,
[Parameter(Mandatory = $true)]
[string]$TargetPath,
[switch]$Individually)
$ErrorActionPreference = 'Stop'
Add-Type -Assembly 'System.IO.Compression.FileSystem'
if ($Individually) {
# Create the target root directory.
if (!(Test-Path -LiteralPath $TargetPath -PathType Container)) {
$null = New-Item -Path $TargetPath -ItemType Directory
}
# Create each task zip.
Get-ChildItem -LiteralPath $SourceRoot |
ForEach-Object {
$sourceDir = $_.FullName
$targetDir = [System.IO.Path]::Combine($TargetPath, $_.Name)
Write-Host "Compressing $($_.Name)"
$null = New-Item -Path $targetDir -ItemType Directory
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceDir, "$targetDir\task.zip")
}
} else {
# Create the target directory.
$targetDir = [System.IO.Path]::GetDirectoryName($TargetPath)
if (!(Test-Path -LiteralPath $targetDir -PathType Container)) {
$null = New-Item -Path $targetDir -ItemType Directory
}
# Create the zip.
[System.IO.Compression.ZipFile]::CreateFromDirectory($SourceRoot, $TargetPath)
}