-
Notifications
You must be signed in to change notification settings - Fork 4
/
make.ps1
167 lines (136 loc) · 5.07 KB
/
make.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# DebugMode?
$isDebug = $false
#$isDebug = $true
function EndMake() {
if (!$isDebug) {
Stop-Transcript | Out-Null
}
''
Read-Host "終了するには何かキーを教えてください..."
exit
}
function GetBuildNo(
[datetime]$timestamp) {
return ([int]($timestamp.ToString("yy")) + $timestamp.Month + $timestamp.Day).ToString("00") + $timestamp.ToString("HH")
}
# 現在のディレクトリを取得する
$cd = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $cd
if (!$isDebug) {
Start-Transcript make.log | Out-Null
}
# target
$targetClientDirectory = Get-Item .\source\RINGS
$targetDirectories = @($targetClientDirectory)
$depolyDirectory = ".\source\deploy"
# tools
$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
if (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\MSBuild.exe") {
$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\MSBuild.exe"
}
# バージョンを取得する
## ビルド番号を決定する
$timestamp = Get-Date
$buildNo = GetBuildNo($timestamp)
## リリースノートを取得する
if ($isDebug) {
if (Test-Path .\RELEASE_NOTES.bak) {
Copy-Item -Force .\RELEASE_NOTES.bak .\RELEASE_NOTES.xml
}
}
$releaseNotesXML = [xml] (Get-Content .\RELEASE_NOTES.xml -Encoding utf8)
if ($releaseNotesXML -eq $null) {
EndMake
}
$lastestNote = $releaseNotesXML.release_notes.note | Select-Object -Last 1
## バージョン番号を決定する
$version = $lastestNote.version.Replace("#BuildNo#", $buildNo)
$channel = $lastestNote.channel
$tag = ("v" + $version + "-" + $channel)
## アプリケーション名を取得する
$appName = $releaseNotesXML.release_notes.name
## アーカイブファイル名を決定する
$archiveFileName = $appName + "_v" + $version.Replace(".", "_") + "_" + $channel + ".zip"
## リリースノートを置換する
$content = Get-Content .\RELEASE_NOTES.xml -Encoding utf8
$content = $content.Replace("#BuildNo#", $buildNo)
$content = $content.Replace("#Timestamp#", $timestamp.ToString("o"))
$content = $content.Replace("#ArchiveFileName#", $archiveFileName)
$content = $content.Replace("#Tag#", $tag)
Copy-Item -Force .\RELEASE_NOTES.xml .\RELEASE_NOTES.bak
$content | Out-File -FilePath .\RELEASE_NOTES.xml -Encoding utf8
Write-Output "***"
Write-Output ("*** " + $appName + " v" + $version + " " + $channel + " ***")
Write-Output "***"
# Version.cs を上書きする
$content = Get-Content .\source\tools\Version.master.cs -Encoding utf8
$content = $content.Replace("#VERSION#", $version)
$content = $content.Replace("#CHANNEL#", $channel)
foreach ($d in $targetDirectories) {
$content | Out-File -FilePath (Join-Path $d "Version.cs") -Encoding utf8
}
'-> Build'
# Delete Release Directory
foreach ($d in $targetDirectories) {
$out = Join-Path $d "bin\Release\*"
if (Test-Path $out) {
Remove-Item -Recurse -Force $out
}
}
$target = Get-Item .\source\*.sln
& $msbuild $target /nologo /v:minimal /t:Clean /p:Configuration=Release
Start-Sleep -m 100
'-> Build Client'
$target = Get-Item $targetClientDirectory\*.csproj
& $msbuild $target /nologo /v:minimal /t:Build /p:Configuration=Release | Write-Output
Start-Sleep -m 100
# Successed? build
foreach ($d in $targetDirectories) {
$out = Join-Path $d "bin\Release"
if (!(Test-Path $out)) {
EndMake
}
}
foreach ($d in $targetDirectories) {
# pdb を削除する
Remove-Item -Force (Join-Path $d "bin\Release\*.pdb")
# app.config を削除する
$targets = @(
(Join-Path $d "bin\Release\RINGS.exe.config"),
(Join-Path $d "bin\Release\aframe.Updater.exe.config"))
foreach ($t in $targets) {
if (Test-Path $t) {
Remove-Item -Force $t
}
}
}
'-> Deploy'
# deploy ディレクトリを作る
if (!(Test-Path $depolyDirectory)) {
New-Item -ItemType Directory $depolyDirectory >$null
}
$deployBase = Join-Path $depolyDirectory $archiveFileName.Replace(".zip", "")
if (Test-Path $deployBase) {
Get-ChildItem -Path $deployBase -Recurse | Remove-Item -Force -Recurse
Remove-Item -Recurse -Force $deployBase
}
$deployClient = $deployBase
New-Item -ItemType Directory $deployClient >$null
# client を配置する
'-> Deploy Client'
Copy-Item -Force -Recurse $targetClientDirectory\bin\Release\* $deployClient
# client をアーカイブする
'-> Archive Client'
Compress-Archive -Force $deployClient\* $deployBase\..\$archiveFileName
Get-ChildItem -Path $deployBase -Recurse | Remove-Item -Force -Recurse
Remove-Item -Recurse -Force $deployBase
if (!$isDebug) {
if (Test-Path .\RELEASE_NOTES.bak) {
Remove-Item -Force .\RELEASE_NOTES.bak
}
}
$tag | Out-File .\CURRENT_VERSION -Encoding utf8
Write-Output "***"
Write-Output ("*** " + $appName + " v" + $version + " " + $channel + ", Completed! ***")
Write-Output "***"
EndMake