-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.ps1
101 lines (85 loc) · 2.64 KB
/
release.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
# Copied from https://janjones.me/posts/clickonce-installer-build-publish-github/.
[CmdletBinding(PositionalBinding = $false)]
param (
[switch]$OnlyBuild = $false
)
$appName = "InOculus"
$projDir = "InOculus"
Set-StrictMode -version 2.0
$ErrorActionPreference = "Stop"
Write-Output "Working directory: $pwd"
# Find MSBuild.
$msBuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
-latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe `
-prerelease | select-object -first 1
Write-Output "MSBuild: $((Get-Command $msBuildPath).Path)"
# Load current Git tag.
$tag = $(git describe --tags)
Write-Output "Tag: $tag"
# Parse tag into a three-number version.
$version = $tag.Split('-')[0].TrimStart('v')
$version = "$version.0"
Write-Output "Version: $version"
# Clean output directory.
$publishDir = "bin/publish"
$outDir = "$projDir/$publishDir"
if (Test-Path $outDir) {
Remove-Item -Path $outDir -Recurse
}
# Publish the application.
Push-Location $projDir
try {
Write-Output "Restoring:"
dotnet restore -r win-x64
Write-Output "Publishing:"
$msBuildVerbosityArg = "/v:m"
if ($env:CI) {
$msBuildVerbosityArg = ""
}
& $msBuildPath /target:publish /p:PublishProfile=ClickOnceProfile `
/p:ApplicationVersion=$version /p:Configuration=Release `
/p:PublishDir=$publishDir /p:PublishUrl=$publishDir `
$msBuildVerbosityArg
# Measure publish size.
$publishSize = (Get-ChildItem -Path "$publishDir/Application Files" -Recurse |
Measure-Object -Property Length -Sum).Sum / 1Mb
Write-Output ("Published size: {0:N2} MB" -f $publishSize)
}
finally {
Pop-Location
}
if ($OnlyBuild) {
Write-Output "Build finished."
exit
}
# Clone `gh-pages` branch.
$ghPagesDir = "gh-pages"
if (-Not (Test-Path $ghPagesDir)) {
git clone $(git config --get remote.origin.url) -b gh-pages `
--depth 1 --single-branch $ghPagesDir
}
Push-Location $ghPagesDir
try {
# Remove previous application files.
Write-Output "Removing previous files..."
if (Test-Path "Application Files") {
Remove-Item -Path "Application Files" -Recurse
}
if (Test-Path "$appName.application") {
Remove-Item -Path "$appName.application"
}
# Copy new application files.
Write-Output "Copying new files..."
Copy-Item -Path "../$outDir/Application Files", "../$outDir/$appName.application" `
-Destination . -Recurse
# Stage and commit.
Write-Output "Staging..."
git add -A
Write-Output "Committing..."
git commit -m "Update to v$version"
# Push.
git push
}
finally {
Pop-Location
}