-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathbuild.gradle
105 lines (95 loc) · 3.39 KB
/
build.gradle
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
import javax.net.ssl.HttpsURLConnection
import java.nio.charset.StandardCharsets
plugins {
// Required for NeoGradle
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
}
def publishDiscord() {
try {
def cfLinks = new StringJoiner('\\n')
if (project(':neoforge').hasProperty('curse_link')) {
cfLinks.add("[NeoForge](${project(':neoforge').findProperty('curse_link')})")
}
def modrinthLinks = new StringJoiner('\\n')
if (project(':neoforge').hasProperty('curse_link')) {
modrinthLinks.add("[NeoForge](${project(':neoforge').findProperty('modrinth_link')})")
}
println(cfLinks)
println(modrinthLinks)
def changelog = file("CHANGELOG_LATEST.md").getText()
changelog = changelog.substring(changelog.indexOf("##"))
changelog = changelog.replaceAll("\n","\\\\n")
if (changelog.length() >= 1024) {
changelog = changelog.substring(0, 900)
changelog = changelog + "...[(See more)](${changelog_link})"
}
println(changelog)
int color = 65392
if (release_type == "beta") {
color = 16763904
} else if (release_type == "alpha") {
color = 16724273
}
final String message = """
{
"embeds": [
{
"title": "${mod_name} ${version}",
"color": ${color},
"fields": [
{
"name": "Minecraft Versions",
"value": "${release_versions.replaceAll(",", ", ")}"
},
{
"name": "CurseForge",
"value": "${cfLinks}",
"inline": true
},
{
"name": "Modrinth",
"value": "${modrinthLinks}",
"inline": true
},
{
"name": "Changelog",
"value": "${changelog}"
}
],
"thumbnail": {
"url": "${discord_thumbnail}"
}
}
]
}
"""
println(message)
final URL url = new URL("${discordWebhook}")
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection()
connection.addRequestProperty("Content-Type", "application/json; charset=UTF-8")
connection.addRequestProperty("User-Agent", "${mod_name} Gradle Upload")
connection.setDoOutput(true)
connection.setRequestMethod("POST")
connection.connect()
try (OutputStream out = connection.getOutputStream()) {
out.write(message.getBytes(StandardCharsets.UTF_8))
}
connection.getInputStream().close()
connection.disconnect()
} catch (IOException e) {
e.printStackTrace()
}
}
def ordered(String... dependencyPaths) {
def dependencies = dependencyPaths.collect { tasks.getByPath(it) }
for (int i = 0; i < dependencies.size() - 1; i++) {
dependencies[i + 1].mustRunAfter(dependencies[i])
}
return dependencies
}
tasks.register('publishNeoForge') {
dependsOn ordered(':neoforge:modrinth', ':neoforge:publishCurseForge')
doLast {
publishDiscord()
}
}