-
Notifications
You must be signed in to change notification settings - Fork 4
/
helper.gradle
320 lines (282 loc) · 10.9 KB
/
helper.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
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
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.114'
}
repositories {
gradlePluginPortal()
}
}
def env = System.getenv()
//from https://lowcarbrob.medium.com/android-pro-tip-generating-your-apps-changelog-from-git-inside-build-gradle-19a07533eec4
String generateChangelog() {
println "Assembeling Changelog ..."
def lastTag = "git describe --tags --abbrev=0".execute().text.trim()
def gitLogCmd = "git log $lastTag..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text.trim()
def features = ""
def fixes = ""
def changes = ""
gitLogCmd.eachLine { gitLine ->
def line = gitLine.substring(1, gitLine.length() - 1)
if (line.trim().startsWith("[")) {
def sline = line.split("]", 2)
if (sline.length == 2) {
def type = sline[0].trim().toLowerCase().substring(1)
def comment = sline[1].trim()
//filter issue links
if (comment.contains("(")) {
def cline = comment.split("\\(", 2)
if (cline.length == 2 && cline[1].contains("#")) {
comment = cline[0].trim()
}
}
if (type == "fix" || type == "fixes" || type == "fixed") {
fixes += "- $comment \n"
} else if (type == "feature" || type == "features") {
features += "- $comment \n"
} else if (type == "change" || type == "changes" || type == "changed") {
changes += "- $comment \n"
} else {
println "Unknown Type: $type ($line)"
}
}
}
}
def changelog = ""
if (!features.isEmpty()) {
changelog += "#### Features\n"
changelog += features.trim()
changelog += "\n\n"
}
if (!changes.isEmpty()) {
changelog += "#### Changes\n"
changelog += changes.trim()
changelog += "\n\n"
}
if (!fixes.isEmpty()) {
changelog += "#### Fixes\n"
changelog += fixes.trim()
changelog += "\n\n"
}
println "Changelog since $lastTag:\n$changelog"
return changelog
}
task changelog() {
group = 'publishing'
doLast {
new File(projectDir, "CHANGES.md").text = generateChangelog()
}
}
def requiredDependencies = evaluate(project.required_dependencies)
def optionalDependencies = evaluate(project.optional_dependencies)
modrinth {
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
def modrinth_token = new File(projectDir, "../MODRINTH_TOKEN")
if (modrinth_token.exists()) {
modrinth_token = modrinth_token.text
} else {
modrinth_token = ""
}
def slurper = new groovy.json.JsonSlurper()
token = modrinth_token
//modrinth_id
projectId = findProperty('modrinth_id') ?: project.archives_base_name
versionNumber = project.mod_version
versionType = project.release_channel
uploadFile = remapJar
gameVersions = slurper.parseText(project.modrinth_versions)
loaders = ["fabric"]
changelog = changes
dependencies {
requiredDependencies.each { dep ->
print dep
required.project dep
}
optionalDependencies.each { dep ->
optional.project dep
}
}
debugMode = false
}
curseforge {
def projectID = findProperty('modrinth_id') ?: project.archives_base_name
def slurper = new groovy.json.JsonSlurper()
apiKey = new File(projectDir, "../CURSEFORGE_TOKEN")
if (apiKey.exists()) {
apiKey = apiKey.text
} else {
apiKey = ""
}
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
project {
id = project.curseforge_id
changelogType = 'markdown'
changelog = changes
releaseType = project.release_channel
def versions = slurper.parseText(project.modrinth_versions);
def latestVersion = ''
for (v in versions) {
addGameVersion v
latestVersion = "[$v]"
}
addGameVersion 'Fabric'
addGameVersion 'Java 21'
relations {
requiredDependencies.each { dep ->
requiredDependency dep
}
optionalDependencies.each { dep ->
optionalDependency dep
}
}
mainArtifact(remapJar) {
displayName = "$projectID-$project.version $latestVersion"
}
afterEvaluate {
mainArtifact(remapJar.outputs)
}
}
options {
debug = false
forgeGradleIntegration = false
}
}
task nextVersion() {
group = 'publishing'
doLast {
def slurper = new groovy.json.JsonSlurper();
def projectID = findProperty('modrinth_id') ?: project.archives_base_name
def inputFile = rootProject.file('modrinth.json')
def gameVersions = java.net.URLEncoder.encode(project.modrinth_versions, "UTF-8")
def json = slurper.parseText('[{ "version_number" : "1.0.-1" }]')
try {
new URL("https://api.modrinth.com/v2/project/${projectID}/version?&game_versions=${gameVersions}").withInputStream { i -> inputFile.withOutputStream { it << i } }
json = slurper.parseText(inputFile.text)
} catch (FileNotFoundException) {
}
println(json)
def version = json[0].version_number
//increment patch version
def indexedVersionList = version.split(/\./).toList().withIndex()
indexedVersionList = indexedVersionList.collect { num, idx -> num.toInteger() }
indexedVersionList[2] = indexedVersionList[2].value + 1
def updatedVersion = indexedVersionList.join(".")
println "\n\n"
println "------------- CURRENT VERSION -------------"
println "Last Published Version: " + version
println " Game Versions: " + json[0].game_versions
println " Status: " + json[0].status
println " Featured: " + json[0].featured
println " Downloaded: " + json[0].downloads
println "\n"
println "-------------- NEXT VERSION ---------------"
println "Next Version: " + updatedVersion
println "\n\n"
def propertiesFile = new File("gradle.properties")
def newContents = propertiesFile.text.replaceFirst("mod_version=\\d+.\\d+.\\d+", "mod_version=${updatedVersion}")
propertiesFile.text = newContents
def rootFabricFile = rootProject.file("src/main/resources/fabric.mod.json")
def rootFabricFileJson = slurper.parseText(rootFabricFile.text)
allprojects.each { proj ->
if (proj.path != ':') {
println "Ignoring ${proj}"
return
}
println "Updating Version in ${proj}"
def fabricFile = proj.file("src/main/resources/fabric.mod.json")
def fabricJson = slurper.parseText(fabricFile.text)
fabricJson.version = updatedVersion
fabricJson.depends.minecraft = slurper.parseText(modrinth_versions)
fabricJson.depends.fabricloader = rootFabricFileJson.depends.fabricloader
fabricJson.depends['fabric-api'] = rootFabricFileJson.depends['fabric-api']
fabricJson.depends.java = rootFabricFileJson.depends.java
fabricFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(fabricJson))
}
}
}
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: [build, remapJar, sourcesJar, javadocJar]) {
group = 'publishing'
def slurper = new groovy.json.JsonSlurper()
def apiKey = new File(projectDir, "../GITHUB_TOKEN")
onlyIf {
apiKey.exists()
}
doLast {
apiKey = apiKey.text
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
def github = GitHub.connectUsingOAuth(apiKey as String)
def repository = github.getRepository("quiqueck/" + archivesBaseName)
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("${archivesBaseName}-${version}")
releaseBuilder.body(changes)
releaseBuilder.commitish("1.20")
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-javadoc.jar"), "application/java-archive");
subprojects.each { sub ->
ghRelease.uploadAsset(file("${sub.buildDir}/libs/${sub.archivesBaseName}-${version}.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${sub.buildDir}/libs/${sub.archivesBaseName}-${version}-sources.jar"), "application/java-archive");
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
def githubName = findProperty('github_base_name') ?: project.archives_base_name
artifactId = project.archives_base_name
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
// Optional POM configuration
pom {
name = project.archives_base_name
url = "https://github.com/quiqueck/${githubName}"
licenses {
license {
name = 'The MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
scm {
connection = "scm:git:https://github.com/quiqueck/${githubName}.git"
developerConnection = "scm:git:https://github.com/quiqueck/${githubName}.git"
url = "https://github.com/quiqueck/${githubName}"
}
}
}
}
repositories {
maven {
def slurper = new groovy.json.JsonSlurper();
def apiKey = slurper.parseText(new File(projectDir, "../AMBER_TOKEN").text)
println "\nPublishing ${project.archives_base_name} to Maven..."
name = "Ambertation"
url = "https://maven.ambertation.de/releases/"
credentials {
username = apiKey.username
password = apiKey.token
}
}
}
}