-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathbuild-and-release.ps1
288 lines (237 loc) · 8.42 KB
/
build-and-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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#@formatter:off
function Exec([scriptblock]$cmd, [string]$errorMessage = "Error executing command: " + $cmd) {
& $cmd
if ($LastExitCode -ne 0) {
git reset --hard
throw $errorMessage
}
}
$ErrorActionPreference = 'Stop'
$version = $args[0]
$nextVersion = $args[1]
$dryRun = $args[2]
if (!$version) {
Write-Error "Version is required"
exit 1
}
if (!$nextVersion) {
Write-Error "Next version is required"
exit 1
}
if ($version -eq $nextVersion) {
Write-Error "next version $nextVersion must be different from current version $version"
exit 1
}
$env:githubReleasesUrl = "https://api.github.com/repos/theotherp/nzbhydra2/releases"
if ($dryRun -ne "true" -and $dryRun -ne "false") {
Write-Error "Dry run must be true or false"
exit 1
}
$dryRun = [System.Convert]::ToBoolean($dryRun)
if ($dryRun) {
Write-Host "Dry run is enabled"
} else {
Write-Host "Dry run is disabled"
}
if (Test-Path "discordtoken.txt") {
$discordToken = Get-Content "discordtoken.txt"
$env:DISCORD_TOKEN = $discordToken
Write-Host "Discord token is set"
}
if (Test-Path "githubtoken.txt") {
$githubToken = Get-Content "githubtoken.txt"
$env:GITHUB_TOKEN = $githubToken
Write-Host "Github token is set"
$response = Invoke-WebRequest -Uri https://api.github.com -Method Head -Headers @{"Authorization" = "token $githubToken"}
if ($response.StatusCode -eq 200) {
Write-Host "GitHub token seems to be valid - HTTP status code is 200 OK"
} else {
Write-Error "GitHub token seems to be invalid - HTTP status code is $($response.StatusCode)"
exit 1
}
}
if ($discordToken -eq $null) {
Write-Error "Discord token is required"
exit 1
}
if ($githubToken -eq $null) {
Write-Error "Github token is required"
exit 1
}
if (!(Test-Path "readme.md")) {
Write-Error "Readme.md is required"
exit 1
}
if ((git status --porcelain) -ne $null) {
Write-Error "Git has untracked or changed files"
exit 1
}
else {
Write-Host "Git is clean"
}
$dockerInfo = wsl -d Ubuntu -- sh -c "docker info"
if (!$dockerInfo -contains "Docker Root Dir") {
Write-Error "Docker is not running in WSL"
exit 1
}
Write-Host "Setting release version"
exec { mvn -q -B versions:set `-DnewVersion="$version" }
if (-not $?) {
Write-Error "Setting release version failed"
git reset --hard
exit 1
}
Write-Host "Checking preconditions"
exec { mvn -q -B org.nzbhydra:github-release-plugin:3.0.0:precheck }
if (-not $?) {
Write-Error "Preconditions failed"
git reset --hard
exit 1
}
Write-Host "Generating changelog"
exec { mvn -q -B org.nzbhydra:github-release-plugin:3.0.0:generate-changelog }
if (-not $?) {
Write-Error "Changing log generation failed"
git reset --hard
exit 1
}
Write-Host "Generating wrapper hashes"
exec { mvn -q -B org.nzbhydra:github-release-plugin:3.0.0:generate-wrapper-hashes }
if (-not $?) {
Write-Error "Wrapper hash generation failed"
git reset --hard
exit 1
}
Write-Host "Making versions effective"
exec { mvn -q -B versions:commit }
if (-not $?) {
Write-Error "Making versions effective failed"
git reset --hard
exit 1
}
Write-Host "Building core jar"
exec { mvn -q -pl org.nzbhydra:nzbhydra2,org.nzbhydra:shared,org.nzbhydra:mapping,org.nzbhydra:core clean install -B -T 1C `-DskipTests=true}
erase .\releases\generic-release\include\*.jar
copy .\core\target\*-exec.jar .\releases\generic-release\include\
if (-not $?) {
Write-Error "Clean install of core failed"
git reset --hard
exit 1
}
$genericVersion = java -jar releases/generic-release/include/core-$version-exec.jar -version
if ($genericVersion -ne $version) {
Write-Error "Generic version $version expected but is $genericVersion"
exit 1
}
Write-Host "Building windows executable"
try {
.\buildCore.cmd
copy .\core\target\core.exe .\releases\windows-release\include\
copy .\core\target\*.dll .\releases\windows-release\include\
} catch {
exit 1
}
$windowsVersion = releases/windows-release/include/core.exe -version
if ($windowsVersion -ne $version) {
Write-Error "Windows version $version expected but is $windowsVersion"
exit 1
}
Write-Host "Building linux amd64 executables"
wsl -d Ubuntu -- sh -c ./misc/buildLinuxCore/buildBoth.sh
$linuxAmd64Version = wsl -d Ubuntu releases/linux-amd64-release/include/executables/core -version
if ($linuxAmd64Version -ne $version) {
Write-Error "Linux amd64 version $version expected but is $linuxAmd64Version"
exit 1
}
#We must ask the build machine because we can't run the binary locally
$linuxArm64Version = wsl -d Ubuntu -- sh -c "ssh -i ~/.ssh/oraclecloud.key build@141.147.54.141 /home/build/nzbhydra2/core/target/core -version"
if ($linuxArm64Version -ne $version) {
Write-Error "Linux arm64 version $version expected but is $linuxArm64Version"
exit 1
}
Write-Host "All required files exist and versions match"
Write-Host "Building releases ***********************************************************************"
exec { mvn -q -pl org.nzbhydra:windows-release,org.nzbhydra:generic-release,org.nzbhydra:linux-amd64-release,org.nzbhydra:linux-arm64-release clean install -T 1C `-DskipTests=true}
#We need to commit and push the source code now so that it's packaged in the release
if ($dryRun) {
Write-Host "Committing (not really, just dry run) ***********************************************************************"
} else {
Write-Host "Committing ***********************************************************************"
git commit -am "Update to $version"
if (-not $?) {
Write-Error "Commit failed"
git reset --hard
exit 1
}
}
if ($dryRun) {
Write-Host "Tagging (not really, just dry run) ***********************************************************************"
} else {
Write-Host "Tagging ***********************************************************************"
git tag -a v$version -m v$version
if (-not $?) {
Write-Error "Tagging failed"
git reset --hard
exit 1
}
}
if ($dryRun) {
Write-Host "Pushing (not really, just dry run) ***********************************************************************"
} else {
Write-Host "Pushing ***********************************************************************"
git push
git push origin v$version
if (-not $?) {
Write-Error "Pushing failed"
git reset --hard
exit 1
}
}
if ($dryRun) {
Write-Host "Releasing to github (not really, just dry run) ***********************************************************************"
exec { mvn -B org.nzbhydra:github-release-plugin:3.0.0:release `-DdryRun }
} else {
Write-Host "Releasing to github ***********************************************************************"
exec { mvn -B org.nzbhydra:github-release-plugin:3.0.0:release }
}
if (-not $?) {
Write-Error "Releasing to github failed"
exit 1
}
if ($dryRun) {
Write-Host "Publishing to discord (not really, just dry run) ***********************************************************************"
exec { java -jar other/discord-releaser/target/discordreleaser-jar-with-dependencies.jar core/src/main/resources/changelog.yaml $version discordtoken.txt true }
} else {
Write-Host "Publishing to discord ***********************************************************************"
exec { java -jar other/discord-releaser/target/discordreleaser-jar-with-dependencies.jar core/src/main/resources/changelog.yaml $version discordtoken.txt false }
}
if (-not $?) {
Write-Error "Publishing to discord failed"
Read-Host -Prompt "Press enter to continue"
}
Write-Host "Setting new snapshot version"
exec { mvn -B versions:set `-DnewVersion="$nextVersion"-SNAPSHOT }
if (-not $?) {
Write-Error "Setting new snapshot version failed"
git reset --hard
exit 1
}
Write-Host "Making snapshot version effective"
exec { mvn -B versions:commit }
if (-not $?) {
Write-Error "Making snapshot version effective failed"
git reset --hard
exit 1
}
if ($dryRun) {
Write-Host "Committing update to $nextVersion-SNAPSHOT (not really, just dry run) ***********************************************************************"
} else {
Write-Host "Committing ***********************************************************************"
git commit -am "Update to $nextVersion-SNAPSHOT"
if (-not $?) {
Write-Error "Commit failed"
git reset --hard
exit 1
}
}
Write-Host "Done"