-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
130 lines (107 loc) · 4.7 KB
/
Copy pathbuild.ps1
File metadata and controls
130 lines (107 loc) · 4.7 KB
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
129
130
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$projectRoot = $PSScriptRoot
$sourceRoot = Join-Path $projectRoot 'src'
$testRoot = Join-Path $projectRoot 'tests'
$OutputRoot = [System.IO.Path]::GetFullPath(
(Join-Path $projectRoot 'artifacts'))
$buildRoot = Join-Path $OutputRoot 'build'
$releaseRoot = Join-Path $OutputRoot 'release'
$packageName = 'ten-thirty-two-bluetooth-refresh-windows-x64'
$packageRoot = Join-Path $releaseRoot $packageName
$zipPath = Join-Path $releaseRoot ($packageName + '.zip')
$zipHashPath = $zipPath + '.sha256'
$frameworkRoot = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319'
$compiler = Join-Path $frameworkRoot 'csc.exe'
if (-not (Test-Path -LiteralPath $compiler -PathType Leaf)) {
throw "The .NET Framework x64 compiler was not found at $compiler."
}
foreach ($ownedPath in @($buildRoot, $releaseRoot)) {
$resolvedOwnedPath = [System.IO.Path]::GetFullPath($ownedPath)
$expectedParent = [System.IO.Path]::GetFullPath($OutputRoot)
$actualParent = [System.IO.Path]::GetFullPath(
(Split-Path -Parent $resolvedOwnedPath))
if (-not $actualParent.Equals(
$expectedParent,
[System.StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to clean a path outside the project artifacts directory."
}
if (Test-Path -LiteralPath $resolvedOwnedPath) {
$existingItem = Get-Item -LiteralPath $resolvedOwnedPath -Force
if (($existingItem.Attributes -band
[System.IO.FileAttributes]::ReparsePoint) -ne 0) {
throw "Refusing to clean the reparse-point path $resolvedOwnedPath."
}
}
}
if (Test-Path -LiteralPath $buildRoot) {
Remove-Item -LiteralPath $buildRoot -Recurse -Force
}
if (Test-Path -LiteralPath $releaseRoot) {
Remove-Item -LiteralPath $releaseRoot -Recurse -Force
}
New-Item -ItemType Directory -Path $buildRoot -Force | Out-Null
New-Item -ItemType Directory -Path $packageRoot -Force | Out-Null
$coreSources = @(
(Join-Path $sourceRoot 'Core\CommandResult.cs'),
(Join-Path $sourceRoot 'Core\CommandRunner.cs'),
(Join-Path $sourceRoot 'Core\PnpRescanService.cs')
)
$appSources = @(
(Join-Path $sourceRoot 'Program.cs'),
(Join-Path $sourceRoot 'MainForm.cs'),
(Join-Path $sourceRoot 'BrandHeader.cs'),
(Join-Path $sourceRoot 'Properties\AssemblyInfo.cs')
) + $coreSources
$appPath = Join-Path $buildRoot 'BluetoothRefresh.exe'
$testPath = Join-Path $buildRoot 'BluetoothRefresh.Tests.exe'
$manifestPath = Join-Path $projectRoot 'app.manifest'
& $compiler /nologo /target:winexe /platform:x64 /optimize+ /debug:pdbonly `
/out:$appPath /win32manifest:$manifestPath `
/reference:System.dll /reference:System.Core.dll `
/reference:System.Drawing.dll /reference:System.Windows.Forms.dll `
$appSources
if ($LASTEXITCODE -ne 0) {
throw "Application compilation failed with exit code $LASTEXITCODE."
}
& $compiler /nologo /target:exe /platform:x64 /optimize+ `
/out:$testPath /reference:System.dll /reference:System.Core.dll `
($coreSources + (Join-Path $testRoot 'CoreTests.cs'))
if ($LASTEXITCODE -ne 0) {
throw "Test compilation failed with exit code $LASTEXITCODE."
}
& $testPath
if ($LASTEXITCODE -ne 0) {
throw "Core tests failed with exit code $LASTEXITCODE."
}
Copy-Item -LiteralPath $appPath -Destination $packageRoot
Copy-Item -LiteralPath (Join-Path $projectRoot 'README.md') -Destination $packageRoot
Copy-Item -LiteralPath (Join-Path $projectRoot 'SECURITY.md') -Destination $packageRoot
Copy-Item -LiteralPath (Join-Path $projectRoot 'LICENSE') -Destination $packageRoot
$hashTargets = Get-ChildItem -LiteralPath $packageRoot -File |
Where-Object { $_.Name -ne 'SHA256SUMS.txt' } |
Sort-Object Name
$hashLines = foreach ($file in $hashTargets) {
$hash = Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256
'{0} {1}' -f $hash.Hash.ToLowerInvariant(), $file.Name
}
$hashPath = Join-Path $packageRoot 'SHA256SUMS.txt'
[System.IO.File]::WriteAllLines($hashPath, $hashLines, [System.Text.Encoding]::ASCII)
Compress-Archive -Path (Join-Path $packageRoot '*') -DestinationPath $zipPath `
-CompressionLevel Optimal -Force
$zipHash = Get-FileHash -LiteralPath $zipPath -Algorithm SHA256
$zipHashLine = '{0} {1}' -f `
$zipHash.Hash.ToLowerInvariant(), `
(Split-Path -Leaf $zipPath)
[System.IO.File]::WriteAllText(
$zipHashPath,
$zipHashLine + [Environment]::NewLine,
[System.Text.Encoding]::ASCII)
Write-Host ''
Write-Host 'Build, tests, hashes, and package completed.'
Write-Host ('Application: {0}' -f $appPath)
Write-Host ('Package: {0}' -f $zipPath)
Write-Host ('Package hash:{0}' -f $zipHashPath)
Write-Host ('ZIP SHA-256: {0}' -f $zipHash.Hash.ToLowerInvariant())