-
Notifications
You must be signed in to change notification settings - Fork 3
/
Deploy.ps1
128 lines (101 loc) · 4.07 KB
/
Deploy.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Configurable variables
$repo = './'
$packing = 'release'
$outputFormat = Join-Path -Path '\..' -ChildPath 'BabiesAndChildren-{0}.zip'
$internalPath = 'BabiesAndChildren'
$pathsToRemove = '.git', '.gitattributes', '.gitignore'
[Console]::ResetColor()
# Progress Bar Variables
$Activity = "Deploying"
$Id = 1
# Complex Progress Bar
$Step = 0
$TotalSteps = 6
$StatusText = '"Step $($Step.ToString().PadLeft($TotalSteps.ToString().Length)) of $TotalSteps | $Task"' # Single quotes need to be on the outside
$StatusBlock = [ScriptBlock]::Create($StatusText) # This script block allows the string above to use the current values of embedded values each time it's run
# Read environvemt
$Task = "Collecting info..."
$Step++
##Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
$startupPath = Get-Location
if ($IsWindows) {
$7z = (GET-ItemProperty 'HKLM:\SOFTWARE\7-Zip').Path + '7z.exe'
}
else {
$7z = &which 7z
}
$packingRjw = Join-Path -Path $packing -ChildPath $internalPath
Push-Location -Path $repo
try {
[string]$version = git describe --tags
} catch {
[string]$version = ""
}
if ($version -eq "") {
$manifest = Join-Path -Path '.\About' -ChildPath 'Manifest.xml'
[string]$version = (Select-Xml -Path $manifest -XPath '/Manifest/version' | Select-Object -ExpandProperty Node).innerText
}
$output = $outputFormat -f $version
Pop-Location
# Cleanup
$Task = "Cleanup..."
$Step++
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
if (Test-Path $packing) { Remove-Item -Recurse -Force $packing }
if (Test-Path $output) { Remove-Item $output }
# Prepating data
$Task = "Copying..."
$Step++
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
$items = Get-ChildItem -Force -Path $repo
$items | Foreach-Object -Begin {
$i = 0
} -Process {
$i++
if (-Not ($pathsToRemove -contains $_.Name)) {
Copy-Item -Recurse $_.FullName -Destination (Join-Path -Path $packingRjw -ChildPath $_.Name)
}
$p = $i * 100 / $items.Count
Write-Progress -Id ($Id+1) -ParentId $Id -Activity 'Copying' -Status ('{0:0}% complete' -f $p) -PercentComplete $p
}
Write-Progress -Id ($Id+1) -ParentId $Id -Activity "Copying" -Status "Ready" -Completed
# removing files from subfolders
$Task = "Excluding..."
$Step++
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
foreach ($path in $pathsToRemove) {
$p = Join-Path -Path $packingRjw -ChildPath $path
if (Test-Path $p) { Remove-Item -Recurse -Force $p }
}
# archiving
$Task = "Archiving..."
$Step++
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
Push-Location -Path $packing
& $7z a -r -bsp1 (Join-Path -Path $startupPath.Path -ChildPath $output) + $internalPath | Foreach-Object -Begin {
Write-Progress -Id ($Id+1) -ParentId $Id -Activity 'Archiving' -Status "Starting..." -PercentComplete 0
} -Process {
$line = $_.Trim()
if ($line -ne "") {
[int]$p = 0
[bool]$result = [int]::TryParse($line.Split('%')[0], [ref]$p)
if ($result) {
Write-Progress -Id ($Id+1) -ParentId $Id -Activity 'Archiving' -Status $line -PercentComplete $p
}
}
}
Write-Progress -Id ($Id+1) -Activity "Archiving" -Status "Ready" -Completed
Pop-Location
# cleanup
$Task = "Cleanup..."
$Step++
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation " " -PercentComplete ($Step / $TotalSteps * 100)
if (Test-Path $packing) { Remove-Item -Recurse -Force $packing }
Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -Completed
# If running in the console, wait for input before closing.
if ($Host.Name -eq "ConsoleHost")
{
Write-Host "Done"
Write-Host "Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}