-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
build.gradle
169 lines (143 loc) · 5.2 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
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
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(':fabric').hasProperty('curse_link')) {
cfLinks.add("[Fabric](${project(':fabric').findProperty('curse_link')})")
}
if (project(':forge').hasProperty('curse_link')) {
cfLinks.add("[Forge](${project(':forge').findProperty('curse_link')})")
}
if (project(':neoforge').hasProperty('curse_link')) {
cfLinks.add("[NeoForge](${project(':neoforge').findProperty('curse_link')})")
}
def modrinthLinks = new StringJoiner('\\n')
if (project(':fabric').hasProperty('modrinth_link')) {
modrinthLinks.add("[Fabric](${project(':fabric').findProperty('modrinth_link')})")
}
if (project(':forge').hasProperty('modrinth_link')) {
modrinthLinks.add("[Forge](${project(':forge').findProperty('modrinth_link')})")
}
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, 924)
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 = URI.create("${discordWebhook}").toURL()
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('publishFabric') {
dependsOn ordered(':fabric:modrinth', ':fabric:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishForge') {
dependsOn ordered(':forge:modrinth', ':forge:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishNeoForge') {
dependsOn ordered(':neoforge:modrinth', ':neoforge:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishFabricForge') {
dependsOn ordered(':forge:modrinth', 'forge:publishCurseForge', ':fabric:modrinth', ':fabric:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishFabricNeoForge') {
dependsOn ordered(':fabric:modrinth', ':fabric:publishCurseForge', ':neoforge:modrinth', ':neoforge:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishForgeNeoForge') {
dependsOn ordered(':forge:modrinth', ':forge:publishCurseForge', ':neoforge:modrinth', ':neoforge:publishCurseForge')
doLast {
publishDiscord()
}
}
tasks.register('publishFabricForgeNeoForge') {
dependsOn ordered(':forge:modrinth', ':forge:publishCurseForge', ':fabric:modrinth', ':fabric:publishCurseForge', ':neoforge:modrinth', ':neoforge:publishCurseForge')
doLast {
publishDiscord()
}
}