Repository navigation
Expand file tree
/
Copy pathpackage-release.ps1
More file actions
79 lines (68 loc) · 3.47 KB
/
Copy pathpackage-release.ps1
File metadata and controls
79 lines (68 loc) · 3.47 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
param(
[string]$Version = "2.0.0",
[string]$ExecutablePath = "",
[string]$OutputDirectory = ""
)
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
if ($Version -notmatch '^\d+\.\d+\.\d+$') {
throw "Version must use MAJOR.MINOR.PATCH format."
}
if ([String]::IsNullOrWhiteSpace($ExecutablePath)) {
$ExecutablePath = Join-Path $projectRoot "dist\DesktopNest.exe"
}
elseif (-not [System.IO.Path]::IsPathRooted($ExecutablePath)) {
$ExecutablePath = Join-Path $projectRoot $ExecutablePath
}
$ExecutablePath = [System.IO.Path]::GetFullPath($ExecutablePath)
if (-not (Test-Path -LiteralPath $ExecutablePath -PathType Leaf)) {
throw "Release executable was not found: $ExecutablePath"
}
if ([String]::IsNullOrWhiteSpace($OutputDirectory)) {
$OutputDirectory = Join-Path $projectRoot "release"
}
elseif (-not [System.IO.Path]::IsPathRooted($OutputDirectory)) {
$OutputDirectory = Join-Path $projectRoot $OutputDirectory
}
$OutputDirectory = [System.IO.Path]::GetFullPath($OutputDirectory)
New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null
$temporaryRoot = Join-Path ([System.IO.Path]::GetTempPath()) (
"DesktopNest-package-" + [Guid]::NewGuid().ToString("N"))
$temporaryRoot = [System.IO.Path]::GetFullPath($temporaryRoot)
$systemTemp = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath())
if (-not $temporaryRoot.StartsWith($systemTemp, [StringComparison]::OrdinalIgnoreCase)) {
throw "Temporary package path escaped the system temporary directory."
}
$packageName = "DesktopNest-v$Version-windows"
$packageRoot = Join-Path $temporaryRoot $packageName
$packageDist = Join-Path $packageRoot "dist"
$archivePath = Join-Path $OutputDirectory ($packageName + ".zip")
$checksumPath = $archivePath + ".sha256"
try {
New-Item -ItemType Directory -Force -Path $packageDist | Out-Null
Copy-Item -LiteralPath $ExecutablePath -Destination (Join-Path $packageDist "DesktopNest.exe") -Force
Copy-Item -LiteralPath (Join-Path $projectRoot "DesktopNest.exe.config") -Destination (Join-Path $packageDist "DesktopNest.exe.config") -Force
Copy-Item -LiteralPath (Join-Path $projectRoot "启动拾光桌面.cmd") -Destination $packageRoot -Force
Copy-Item -LiteralPath (Join-Path $projectRoot "README.md") -Destination $packageRoot -Force
Copy-Item -LiteralPath (Join-Path $projectRoot "CHANGELOG.md") -Destination $packageRoot -Force
Copy-Item -LiteralPath (Join-Path $projectRoot "API_KEY_IMPORT.local.example") -Destination $packageRoot -Force
if (Test-Path -LiteralPath $archivePath) {
Remove-Item -LiteralPath $archivePath -Force
}
Compress-Archive -LiteralPath $packageRoot -DestinationPath $archivePath -CompressionLevel Optimal
$hash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
[System.IO.File]::WriteAllText(
$checksumPath,
$hash + " " + [System.IO.Path]::GetFileName($archivePath) + [Environment]::NewLine,
(New-Object System.Text.UTF8Encoding($false)))
Write-Host "Release package: $archivePath" -ForegroundColor Green
Write-Host "SHA-256: $hash" -ForegroundColor Green
}
finally {
if (Test-Path -LiteralPath $temporaryRoot) {
$resolvedTemporaryRoot = [System.IO.Path]::GetFullPath($temporaryRoot)
if ($resolvedTemporaryRoot.StartsWith($systemTemp, [StringComparison]::OrdinalIgnoreCase)) {
Remove-Item -LiteralPath $resolvedTemporaryRoot -Recurse -Force
}
}
}