-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathferry-mpp.gradle
More file actions
422 lines (356 loc) · 14.2 KB
/
ferry-mpp.gradle
File metadata and controls
422 lines (356 loc) · 14.2 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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "me.modmuss50:mod-publish-plugin:1.1.0"
classpath "net.dumbcode.gradlehook:GradleHook:2.0.2"
classpath "org.kohsuke:github-api:1.330"
classpath "org.ajoberstar.grgit:grgit-gradle:5.3.2"
}
}
apply plugin: me.modmuss50.mpp.MppPlugin
apply plugin: net.dumbcode.gradlehook.GradleWebhookPlugin
apply plugin: org.ajoberstar.grgit.gradle.GrgitPlugin
ext.changelogFile = file(layout.buildDirectory.file("ferryReleaseChangelog.txt"))
ext.jarTask = findProperty('jarTask') ?: 'jar'
def curseReleaseType = "release"
def publications = getPublications(rootProject)
def stabilitySuffix = ""
def typeALPHA
def typeBETA
def typeSTABLE
rootProject.setVersion(getVersion())
// Publishing configuration
publishMods {
// Set the main file to be uploaded
//file = jar.archiveFile
// Markdown changelog
// This gets reconfigured later by the generateChangelog task.
changelog = "No Changelog Available"
// Defaults to the Gradle project version
//version = getVersion()
// Specify the release type
// This gets reconfigured later by the generateChangelog task.
type = ALPHA
// The display name/release title, this defaults to the Gradle project name + version
// This will typically be overridden for each publication later on...
if (project.hasProperty("releaseTitle")) {
displayName = project.getProperty("releaseTitle")
} else {
displayName = "${project.project_name} v${project.version} for ${project.minecraft_version}"
}
// A ConfigurableFileCollection of additional files that are uploaded alongside the main file
//additionalFiles.from(jar.archiveFile)
// The max number of times to retry on server error, defaults to 3.
//maxRetries = 5
// When dry run is enabled the release assets will be saved to the build directory for testing.
if (project.hasProperty("dryRun")) {
dryRun = true
}
// Set the brand color for all targets to the project's brand color.
// ... what happened to this property? ...
//brandColor = Integer.decode(project.project_color)
def options_modrinth = modrinthOptions {
if (providers.environmentVariable("MODRINTH_TOKEN").isPresent()) {
accessToken = providers.environmentVariable("MODRINTH_TOKEN").get()
} else {
accessToken = "undefined"
if (!dryRun) {
dryRun = true
}
}
projectId = project.modrinth_id
announcementTitle = "${project.modrinth_emote} Modrinth"
// A list of the versions the release supports
splitProperty("modrinth_game_versions").each {
minecraftVersions.add(it)
}
// Dependencies
splitProperty("modrinth_required_dependencies").each {
requires(it)
}
splitProperty("modrinth_optional_dependencies").each {
optional(it)
}
splitProperty("modrinth_incompatible_dependencies").each {
incompatible(it)
}
splitProperty("modrinth_embedded_dependencies").each {
embeds(it)
}
}
def options_curseforge = curseforgeOptions {
if (providers.environmentVariable("CURSEFORGE_TOKEN").isPresent()) {
accessToken = providers.environmentVariable("CURSEFORGE_TOKEN").get()
} else {
accessToken = "undefined"
if (!dryRun) {
dryRun = true
}
}
projectId = project.curseforge_id
projectSlug = project.curseforge_slug
announcementTitle = "${project.curseforge_emote} CurseForge"
// A list of the versions the release supports
splitProperty("curseforge_game_versions").each {
minecraftVersions.add(it)
}
// Dependencies
splitProperty("curseforge_required_dependencies").each {
requires(it)
}
splitProperty("curseforge_optional_dependencies").each {
optional(it)
}
splitProperty("curseforge_incompatible_dependencies").each {
incompatible(it)
}
splitProperty("curseforge_embedded_dependencies").each {
embeds(it)
}
}
if (project.hasProperty("github") && providers.environmentVariable("GITHUB_REPOSITORY").isPresent()) {
github {
if (providers.environmentVariable("GITHUB_TOKEN").isPresent()) {
accessToken = providers.environmentVariable("GITHUB_TOKEN").get()
} else {
accessToken = "undefined"
if (!dryRun) {
dryRun = true
}
}
announcementTitle = (project.github_emote != null ? project.github_emote + " " : "") + "Download from GitHub"
repository = providers.environmentVariable("GITHUB_REPOSITORY").get()
commitish = getBranch()
publications.each { Publication publication ->
additionalFiles.from(publication.getArchive())
}
}
}
if (project.hasProperty("modrinth")) {
publications.each { Publication publication ->
modrinth("${publication.getPlatform()}Modrinth") {
from options_modrinth
announcementTitle = publication.getAnnouncementTitle("Modrinth", project.modrinth_emote)
displayName = publication.getDisplayName()
file = publication.getArchive()
modLoaders.add(publication.getPlatform())
if (publication.getPlatform() == "fabric") {
modLoaders.add("quilt")
}
}
}
}
if (project.hasProperty("curseforge")) {
publications.each { Publication publication ->
curseforge("${publication.getPlatform()}Curseforge") {
from options_curseforge
announcementTitle = publication.getAnnouncementTitle("CurseForge", project.curseforge_emote)
displayName = publication.getDisplayName()
file = publication.getArchive()
modLoaders.add(publication.getPlatform())
if (publication.getPlatform() == "fabric") {
modLoaders.add("quilt")
}
}
}
}
if (project.hasProperty("discord")) {
discord {
if (!providers.environmentVariable("DISCORD_ANNOUNCEMENT_WEBHOOK").isPresent()) {
//dryRun = true
dryRunWebhookUrl = providers.environmentVariable("DISCORD_ANNOUNCEMENT_WEBHOOK_DRY_RUN")
webhookUrl = "undefined"
} else {
webhookUrl = providers.environmentVariable("DISCORD_ANNOUNCEMENT_WEBHOOK")
}
if (project.use_project_username.toBoolean()) {
avatarUrl = project.project_logo
username = project.project_name
} else if (project.hasProperty("project_owner")) {
username = project.project_owner
}
style {
link = "INLINE"
look = "MODERN"
color = project.project_color
thumbnailUrl = project.project_logo
}
content = changelog.map {
"### [" + project.project_name + stabilitySuffix + "](" + project.project_url + ")\n" +
"" + project.project_name + " v" + project.version + " for " + project.minecraft_version + " Released\n" +
"### Changes:\n" + it + "\n" +
"### Downloads:\n"
}
}
}
typeALPHA = ALPHA
typeBETA = BETA
typeSTABLE = STABLE
}
class Publication {
private String jarTask
private String platform
private Project project
private boolean single
Publication(Project project, String platform, String jarTask) {
assert platform != null && platform.length() > 0
this.jarTask = jarTask
this.platform = platform
this.project = project
this.single = (project.hasProperty("single_platform") && platform == project.getProperty("single_platform"))
}
String getPlatform() {
return platform
}
RegularFileProperty getArchive() {
return single
? project.tasks.named(jarTask, Jar).get().archiveFile as RegularFileProperty
: project.project(":${platform}").tasks.named(jarTask, Jar).get().archiveFile as RegularFileProperty
}
String getAnnouncementTitle(String name, String emote) {
assert name != null && name.length() > 0
return ((emote != null ? emote + " " : "") + name + (single ? "" : " - " + platform.capitalize()))
}
String getDisplayName() {
return single
? "${project.project_name} v${project.version} for ${project.minecraft_version}" as String
: "${project.project_name} ${platform.capitalize()} v${project.version} for ${project.minecraft_version}" as String
}
}
ArrayList<Publication> getPublications(Project project) {
if (project.hasProperty("single_platform")) {
assert (project.getProperty("single_platform") as String ?: '').length() > 0
return [ new Publication(project, project.getProperty("single_platform") as String, project.getProperty("jarTask") as String) ]
} else {
assert (project.getProperty("enabled_platforms") as String ?: '').length() > 0
return splitProperty("enabled_platforms").collect { platform -> new Publication(project, platform, project.getProperty("jarTask") as String) }
}
}
// Changelog generation and persistence
tasks.register('generateChangelog') {
def changes = StringBuilder.getDeclaredConstructor().newInstance()
if (!project.hasProperty("lastTag") || !project.hasProperty("currentTag")) {
println "Missing lastTag or currentTag parameters, aborting changelog creation"
return
}
def lastTag = project.getProperty("lastTag")
def currentTag = project.getProperty("currentTag")
def commits = "git log --max-count=$project.changelog_max_commit_search --pretty=format:\"%b\" $lastTag..$currentTag".execute()
println "Last version: $lastTag"
println "Current version: $currentTag"
def releaseType = project.default_release_type
if (currentTag.contains("-alpha")) {
releaseType = "alpha"
curseReleaseType = "alpha"
stabilitySuffix = " (Alpha)"
} else if (currentTag.contains("-beta")) {
releaseType = "beta"
curseReleaseType = "beta"
stabilitySuffix = " (Beta)"
} else if (currentTag.contains("-pre")) {
releaseType = "pre"
curseReleaseType = "beta"
stabilitySuffix = " (Pre-Release)"
} else if (currentTag.contains("-rc")) {
releaseType = "rc"
curseReleaseType = "beta"
stabilitySuffix = " (Release Candidate)"
} else if (!currentTag.contains("-")) {
releaseType = "stable"
}
println "Release type: ${releaseType}"
commits.in.readLines().each { line -> // Loops over the lines the git log command returns
def processedLine = line.toString()
if (processedLine.startsWith("\"")) {
processedLine = processedLine.substring(1)
}
if (processedLine.endsWith("\"")) {
processedLine = processedLine.substring(0, processedLine.length() - 1)
}
println "Reading line: $processedLine"
if (processedLine.startsWith("- ")) {
println "Adding changelog line:"
println " $processedLine"
if (changes.length() == 0) {
changes << processedLine
} else {
changes << "\n$processedLine"
}
}
}
commits.err.eachLine { line -> println line }
commits.waitFor()
println "Changelog:"
def releaseChangelog = changes.toString()
if (releaseChangelog.isEmpty()) {
releaseChangelog = "No Changelog Available"
}
println releaseChangelog
// Persist the changelog to disk.
changelogFile.getParentFile().mkdirs()
changelogFile.createNewFile()
changelogFile.text = releaseChangelog
// Do MPP config which depends on the changelog:
doLast {
publishMods.changelog = releaseChangelog
if (releaseType == "stable") {
publishMods.type = typeSTABLE
} else if (releaseType == "beta" || releaseType == "pre" || releaseType == "rc") {
publishMods.type = typeBETA
} else {
publishMods.type = typeALPHA
}
}
}
// The changelog must be generated prior to publishing mods.
tasks.publishMods.dependsOn(generateChangelog)
// Support functions
String getBranch() {
def branch = providers.environmentVariable("GITHUB_REF").getOrNull()
if (branch != null) {
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
String getVersion() {
def version = "unknown"
if (project.hasProperty("currentTag")) {
return project.currentTag.replace("v", "")
}
def branchLines = "git branch --show-current".execute().in.readLines()
if (!branchLines.isEmpty()) {
version = branchLines.get(0)
}
def tagLines = "git describe --tags --exact-match --abbrev=0".execute().in.readLines()
def release = false
if (!tagLines.isEmpty()) {
def matcher = tagLines.get(0) =~ /v([0-9].[0-9].[0-9])/
if (matcher.find()) {
version = matcher.group(1) // gets 1st match group of 1st match
release = true
}
}
if (!release) {
def lastTag = "git describe --tags --abbrev=0".execute().in.readLines()
def lastCommit = "git rev-parse --short HEAD".execute().in.readLines()
if (!lastTag.isEmpty() && !lastCommit.isEmpty()) {
version = lastTag.get(0).replace("v", "") + "+" + version + "." + lastCommit.get(0)
}
}
return version
}
String[] splitProperty(String property) {
String value = project.findProperty(property)
if (value == null) {
return new String[0]
}
return value.split(', *').findAll { !it.isBlank() }
}