-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.gradle.kts
382 lines (315 loc) · 13 KB
/
build.gradle.kts
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.zaproxy.gradle.CreateNewsMainRelease
import org.zaproxy.gradle.CreatePullRequest
import org.zaproxy.gradle.CustomXmlConfiguration
import org.zaproxy.gradle.DownloadReleasedAddOns
import org.zaproxy.gradle.GenerateReleaseStateLastCommit
import org.zaproxy.gradle.GenerateWebsiteAddonsData
import org.zaproxy.gradle.GenerateWebsiteMainReleaseData
import org.zaproxy.gradle.GenerateWebsitePages
import org.zaproxy.gradle.GenerateWebsiteSbomPages
import org.zaproxy.gradle.GenerateWebsiteWeeklyReleaseData
import org.zaproxy.gradle.GitHubRepo
import org.zaproxy.gradle.GitHubUser
import org.zaproxy.gradle.HandleMainRelease
import org.zaproxy.gradle.HandleWeeklyRelease
import org.zaproxy.gradle.UpdateAddOnZapVersionsEntries
import org.zaproxy.gradle.UpdateAndCreatePullRequestAddOnRelease
import org.zaproxy.gradle.UpdateDailyZapVersionsEntries
import org.zaproxy.gradle.UpdateGettingStartedWebsitePage
import org.zaproxy.gradle.UpdateMainZapVersionsEntries
import org.zaproxy.gradle.UpdateZapVersionWebsiteData
import org.zaproxy.gradle.crowdin.DeployCrowdinTranslations
import java.util.Optional
plugins {
java
id("com.diffplug.spotless")
id("org.zaproxy.common")
id("net.ltgt.errorprone") version "3.1.0"
id("org.zaproxy.crowdin") version "0.3.1"
}
apply(from = "$rootDir/gradle/ci.gradle.kts")
crowdin {
credentials {
token.set(System.getenv("CROWDIN_AUTH_TOKEN"))
}
configuration {
file.set(file("gradle/crowdin.yml"))
}
}
dependencies {
"errorprone"("com.google.errorprone:error_prone_core:2.20.0")
implementation("org.apache.commons:commons-text:1.10.0")
implementation("org.kohsuke:github-api:1.101")
compileOnly("com.infradna.tool:bridge-method-annotation:1.18") {
exclude(group = "org.jenkins-ci")
}
compileOnly("com.github.spotbugs:spotbugs-annotations:3.1.12")
implementation("net.sf.json-lib:json-lib:2.4:jdk15")
implementation("org.zaproxy:zap:2.12.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.assertj:assertj-core:3.24.2")
}
val zapVersionsDir = layout.buildDirectory.dir("ZapVersionsTests")
val copyZapVersions =
tasks.create<Copy>("copyZapVersions") {
from(rootDir)
into(zapVersionsDir)
include("ZapVersions*.xml")
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
sourceSets["test"].output.dir(mapOf("builtBy" to copyZapVersions), zapVersionsDir)
spotless {
format("properties", { targetExclude("buildSrc/**", "gradle/**") })
kotlin {
ktlint()
}
kotlinGradle {
ktlint()
}
}
val noAddOnsZapVersions = "ZapVersions.xml"
val devZapVersions = "ZapVersions-dev.xml"
val nameLatestZapVersions = "ZapVersions-2.15.xml"
val latestZapVersions = file(nameLatestZapVersions)
val ghUser = GitHubUser("zapbot", "[email protected]", System.getenv("ZAPBOT_TOKEN"))
val adminRepo = GitHubRepo("zaproxy", "zap-admin", rootDir)
val addOnsZapVersions = files(devZapVersions, latestZapVersions)
val defaultChecksumAlgorithm = "SHA-256"
tasks {
register<ZapTask>("generateReleaseNotes") {
description = "Generates release notes."
mainClass.set("org.zaproxy.admin.GenerateReleaseNotes")
}
register<ZapTask>("listDownloadCounts") {
description = "Lists download counts."
mainClass.set("org.zaproxy.admin.CountDownloads")
}
register<ZapTask>("pendingAddOnReleases") {
description = "Reports the add-ons that are pending a release of new version."
mainClass.set("org.zaproxy.admin.PendingAddOnReleases")
}
register<ZapTask>("generateHelpAddOn") {
description = "Generates the basic help files for an add-on."
mainClass.set("org.zaproxy.admin.HelpGenerator")
standardInput = System.`in`
}
register<ZapTask>("checkLatestReleaseNotes") {
description = "Checks the latest release notes do not contain issues from previous ones."
mainClass.set("org.zaproxy.admin.CheckLatestReleaseNotes")
}
register<CreateNewsMainRelease>("createNewsMainRelease") {
newsDir.set(File(rootDir, "files/news"))
previousVersion.set(
provider {
val zapVersionsXml = CustomXmlConfiguration(latestZapVersions)
zapVersionsXml.getString("core.version")
},
)
item.set("ZAP @@VERSION@@ is available now")
link.set("https://www.zaproxy.org/download/")
}
register<UpdateMainZapVersionsEntries>("updateMainRelease") {
into.setFrom(fileTree(rootDir).matching { include("ZapVersions*.xml") })
baseDownloadUrl.set("https://github.com/zaproxy/zaproxy/releases/download/v@@VERSION@@/")
windows32FileName.set("ZAP_@@VERSION_UNDERSCORES@@_windows-x32.exe")
windows64FileName.set("ZAP_@@VERSION_UNDERSCORES@@_windows.exe")
linuxFileName.set("ZAP_@@VERSION@@_Linux.tar.gz")
macFileName.set("ZAP_@@VERSION@@.dmg")
releaseNotes.set("Bug fix and enhancement release.")
releaseNotesUrl.set("https://www.zaproxy.org/docs/desktop/releases/@@VERSION@@/")
checksumAlgorithm.set(defaultChecksumAlgorithm)
}
register<CreatePullRequest>("createPullRequestMainRelease") {
description = "Creates a pull request to update the main release."
user.set(ghUser)
repo.set(adminRepo)
branchName.set("update-main-release")
commitSummary.set("Update main release")
commitDescription.set(
provider {
val zapVersionsXml = CustomXmlConfiguration(latestZapVersions)
val mainVersion = zapVersionsXml.getString("core.version")
"Update main release to version $mainVersion."
},
)
}
register<UpdateDailyZapVersionsEntries>("updateDailyRelease") {
into.setFrom(
fileTree(rootDir).matching {
include(noAddOnsZapVersions, devZapVersions)
},
)
baseDownloadUrl.set("https://github.com/zaproxy/zaproxy/releases/download/w")
checksumAlgorithm.set(defaultChecksumAlgorithm)
}
register<CreatePullRequest>("createPullRequestDailyRelease") {
description = "Creates a pull request to update the daily release."
user.set(ghUser)
repo.set(adminRepo)
branchName.set("update-daily-release")
commitSummary.set("Update weekly release")
commitDescription.set(
provider {
val zapVersionsXml = CustomXmlConfiguration(file(noAddOnsZapVersions))
val dailyVersion = zapVersionsXml.getString("core.daily-version")
"Update weekly release to version $dailyVersion."
},
)
}
register<UpdateAddOnZapVersionsEntries>("updateAddOnRelease") {
into.setFrom(addOnsZapVersions)
checksumAlgorithm.set(defaultChecksumAlgorithm)
}
register<UpdateAndCreatePullRequestAddOnRelease>("updateAndCreatePullRequestAddOnRelease") {
into.setFrom(addOnsZapVersions)
checksumAlgorithm.set(defaultChecksumAlgorithm)
user.set(ghUser)
repo.set(adminRepo)
branchName.set("add-on-release")
}
register<DeployCrowdinTranslations>("deployCrowdinTranslations") {
deployConfiguration.set(file("src/main/crowdin-tasks.yml"))
user.set(ghUser)
branchName.set("crowdin-update")
commitSummary.set("Update localized resources")
commitDescription.set("Update resources from Crowdin.")
}
}
val zaproxyRepo = GitHubRepo("zaproxy", "zaproxy", file("$rootDir/../zaproxy"))
val websiteGeneratedDataComment = "# This file is automatically updated by $adminRepo repo."
val generateWebsiteMainReleaseData by tasks.registering(GenerateWebsiteMainReleaseData::class) {
zapVersions.set(latestZapVersions)
generatedDataComment.set(websiteGeneratedDataComment)
into.set(layout.buildDirectory.file("c_main_files.yml"))
gitHubUser.set(ghUser)
gitHubRepo.set(zaproxyRepo)
}
val generateWebsiteWeeklyReleaseData by tasks.registering(GenerateWebsiteWeeklyReleaseData::class) {
zapVersions.set(file(noAddOnsZapVersions))
generatedDataComment.set(websiteGeneratedDataComment)
into.set(layout.buildDirectory.file("e_weekly_files.yml"))
}
val generateWebsiteAddonsData by tasks.registering(GenerateWebsiteAddonsData::class) {
zapVersions.set(latestZapVersions)
generatedDataComment.set(websiteGeneratedDataComment)
into.set(layout.buildDirectory.file("addons.yaml"))
websiteUrl.set("https://www.zaproxy.org/")
}
val websiteRepo = GitHubRepo("zaproxy", "zaproxy-website", file("$rootDir/../zaproxy-website"))
val siteDir = file("${websiteRepo.dir}/site")
val generateReleaseStateLastCommit by tasks.registering(GenerateReleaseStateLastCommit::class) {
zapVersionsPath.set(noAddOnsZapVersions)
zapVersionsAddOnsPath.set(nameLatestZapVersions)
releaseState.set(layout.buildDirectory.file("release_state_last_commit.json"))
}
val releaseStateData = generateReleaseStateLastCommit.map { it.releaseState.get() }
val addOnsHelpWebsite = file("src/main/addons-help-website.txt")
val downloadReleasedAddOns by tasks.registering(DownloadReleasedAddOns::class) {
releaseState.set(releaseStateData)
zapVersions.set(latestZapVersions)
allowedAddOns.set(addOnsHelpWebsite)
outputDir.set(layout.buildDirectory.dir("releasedAddOns"))
}
val generateWebsitePages by tasks.registering(GenerateWebsitePages::class) {
allowedAddOns.set(addOnsHelpWebsite)
addOns.from(downloadReleasedAddOns.map { fileTree(it.outputDir).matching { include("*.zap") } })
helpAddOnRegex.set("^help(?:_[a-zA-Z_]+)?")
siteUrl.set("https://www.zaproxy.org/")
baseUrlPath.set("/docs/desktop/")
addOnsDirName.set("addons")
pageType.set("userguide")
redirectPageType.set("_default")
redirectPageLayout.set("redirect")
sectionPageName.set("_index.md")
imagesDirName.set("images")
noticeGeneratedPage.set("This page was generated from the add-on.")
outputDir.set(layout.buildDirectory.dir("websiteHelpPages"))
}
val updateGettingStartedWebsitePage by tasks.registering(UpdateGettingStartedWebsitePage::class) {
addOn.set(
downloadReleasedAddOns.map {
var files = fileTree(it.outputDir).matching { include("gettingStarted*.zap") }.files
if (files.isEmpty()) Optional.empty() else Optional.of(files.first())
},
)
filenameRegex.set("ZAPGettingStartedGuide-.+\\.pdf")
gettingStartedPage.set(file("$siteDir/content/getting-started/index.md"))
pdfDirectory.set(file("$siteDir/static/pdf/"))
}
val generateWebsiteSbomPages by tasks.registering(GenerateWebsiteSbomPages::class) {
releaseState.set(releaseStateData)
zapVersions.set(latestZapVersions)
outputDir.set(layout.buildDirectory.dir("websiteSbomPages"))
}
val updateZapVersionWebsiteData by tasks.registering(UpdateZapVersionWebsiteData::class) {
releaseState.set(releaseStateData)
val downloadDir = "$siteDir/data/download"
dataFiles.from(files("$downloadDir/b_details.yml", "$downloadDir/c_main.yml", "$downloadDir/g_latest.yml"))
}
val copyWebsiteGeneratedData by tasks.registering(Copy::class) {
group = "ZAP"
description = "Copies the generated website data to the website repo."
destinationDir = siteDir
into("data") {
from(generateWebsiteAddonsData)
into("download") {
from(generateWebsiteMainReleaseData, generateWebsiteWeeklyReleaseData)
}
}
into("content") {
from(generateWebsitePages)
from(generateWebsiteSbomPages)
}
}
updateZapVersionWebsiteData {
mustRunAfter(copyWebsiteGeneratedData)
}
updateGettingStartedWebsitePage {
mustRunAfter(copyWebsiteGeneratedData)
}
val updateWebsite by tasks.registering(CreatePullRequest::class) {
dependsOn(copyWebsiteGeneratedData)
dependsOn(updateGettingStartedWebsitePage)
dependsOn(updateZapVersionWebsiteData)
user.set(ghUser)
repo.set(websiteRepo)
baseBranchName.set("main")
branchName.set("update-data")
commitSummary.set("Update data")
commitDescription.set(
provider {
"""
From:
$adminRepo@${headCommit(adminRepo.dir)}
""".trimIndent()
},
)
}
fun headCommit(repoDir: File) =
FileRepositoryBuilder()
.setGitDir(File(repoDir, ".git"))
.build()
.exactRef("HEAD")
.getObjectId()
.getName()
val handleWeeklyRelease by tasks.registering(HandleWeeklyRelease::class) {
releaseState.set(releaseStateData)
gitHubUser.set(ghUser)
gitHubRepo.set(zaproxyRepo)
eventType.set("release-weekly-docker")
}
val handleMainRelease by tasks.registering(HandleMainRelease::class) {
releaseState.set(releaseStateData)
gitHubUser.set(ghUser)
gitHubRepo.set(zaproxyRepo)
eventType.set("release-main-docker")
}
tasks.register("handleRelease") {
dependsOn(updateWebsite)
dependsOn(handleWeeklyRelease)
dependsOn(handleMainRelease)
}