-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.gradle
197 lines (158 loc) · 6.56 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
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
import groovy.json.JsonSlurper
import java.util.function.BiFunction
import java.util.function.Function
import java.util.stream.Stream
plugins {
id "fabric-loom" version "1.7-SNAPSHOT"
id "maven-publish"
id "me.modmuss50.mod-publish-plugin" version "0.7.4"
}
group = project.group
version = project.version
base {
archivesName = project.archives_base_name
}
// global publishing variables - shouldPublish defaults to true, but can be set to false by using `-PshouldPublish=false`
def shouldPublish = Boolean.parseBoolean( providers.gradleProperty("shouldPublish").getOrElse("true") )
def changelogText = "Changelog could not be found... 😬"
repositories {
mavenCentral()
maven { url "https://maven.terraformersmc.com/releases/" } // Mod Menu
maven { url "https://maven.isxander.dev/releases" } // YACL
}
dependencies {
minecraft "com.mojang:minecraft:$project.minecraft"
mappings "net.fabricmc:yarn:$project.minecraft$project.yarn:v2"
modImplementation "net.fabricmc:fabric-loader:$project.loader"
modImplementation "net.fabricmc.fabric-api:fabric-api:$project.api"
modImplementation "com.terraformersmc:modmenu:$project.modmenu"
modImplementation "dev.isxander:yet-another-config-lib:$project.yacl-fabric"
}
processResources {
inputs.property "version", version
filesMatching("fabric.mod.json") {
expand "version": version
/* filter {
it.replace("example_key", rootProject.exampleVar)
} */
}
def changelog = file("changelog.md")
if( changelog.exists() ) {
// replaces github issue numbers with links
file("changelog.md").text = changelog.text.replaceAll("##(\\d+)", "[#\$1](https://www.github.com/mrbuilder1961/ChatPatches/issues/\$1)")
// hackily gets the first changelog entry
def newEntryTitle = "## Chat Patches `" + version + "`"
def prevEntryIndex = file("changelog.md").text.replaceFirst(newEntryTitle, "").indexOf("## Chat Patches `") + newEntryTitle.length() - 2
changelogText = file("changelog.md").text.substring(0, prevEntryIndex).replaceFirst("# Changelog\\s+", "")
// considered "malformed" if it doesn't end with any word characters, whitespace, or newlines
if( !changelogText.matches("(?s).*(\\s+|(\r?\n)+|\\w+)\$") ) {
print "/!\\ Warning: /!\\ Changelog seemed malformed, this is probably caused by an invalid version ($version)."
if(shouldPublish) {
shouldPublish = false
print " Cancelled publishing, just in case."
}
println()
}
}
if(changelogText.length() > 2000) {
def more = "..\n***.. and more! Check out the full release notes on GitHub!***"
changelogText = changelogText.substring(0, 2000 - more.length()).stripTrailing() + more
println "Trimmed changelog, was over 2000 characters"
}
if(!shouldPublish)
println "Using changelog text:\n>$changelogText<"
}
tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {}
}
publishMods {
// constants
def v = rootProject.version
File secrets = file("secrets.json") // tokens revert to '-' when no secrets.json exists OR the token is not found
Function<String, List<String>> propListGetter = (String propertyName) ->
rootProject[propertyName] != null ? Stream.of( rootProject[propertyName].toString().split(",") ).filter{!it.isBlank()}.toList() : new ArrayList<>()
BiFunction<String, Boolean, String> tokenGetter = (String tokenName, boolean valid) ->
valid && secrets.exists() ? Objects.requireNonNullElse(new JsonSlurper().parse(secrets)[tokenName], "-") : "-"
// gradle.properties vars
String phase = rootProject.phase.toString().toLowerCase()
List<String> loaders = propListGetter.apply("loaders") // Arrays.asList( rootProject.loaders.toString().split(",") )
List<String> targets = propListGetter.apply("targets") // Arrays.asList( rootProject.targets.toString().split(",") )
String[] required = propListGetter.apply("required").toArray()
String[] optionals = propListGetter.apply("optionals").toArray()
String[] incompatibles = propListGetter.apply("incompatibles").toArray()
String[] embedded = propListGetter.apply("embedded").toArray()
String branch = rootProject.branch.toString()
// tokens - token name and if it should return the token or "-"
String cfToken = tokenGetter.apply("curseforge", shouldPublish)
String mrToken = tokenGetter.apply("modrinth", shouldPublish)
String ghToken = tokenGetter.apply("github", shouldPublish)
String dcToken = tokenGetter.apply("discord", shouldPublish)
String dcDebugToken = tokenGetter.apply("discord_debug", !shouldPublish) // always publishes to debug webhook
displayName = v.toString()
file = remapJar.archiveFile // Forge would use jar (NeoForge? i think so..)
changelog = changelogText
type = (phase.matches("release|stable") ? STABLE : phase.matches("beta") ? BETA : ALPHA)
modLoaders = loaders
dryRun = !shouldPublish
if(shouldPublish) {
println "Publishing v$v to $loaders on $targets!"
} else {
println "Not publishing v$v because shouldPublish was false! Maybe check if the changelog was malformed?"
println "Using:\n\ttype: $phase\n\tbranch: $branch\n\tloaders: $loaders\n\ttargets: $targets"
println "\trequired: $required\n\toptionals: $optionals\n\tincompatibles: $incompatibles\n\tembedded: $embedded"
}
curseforge {
accessToken = cfToken
projectId = rootProject.cfId
projectSlug = archives_base_name
minecraftVersions.addAll(targets)
clientRequired = true
requires(required)
optional(optionals)
incompatible(incompatibles)
embeds(embedded)
}
modrinth {
accessToken = mrToken
projectId = rootProject.mrId
minecraftVersions.addAll(targets)
// specify id OR slug NOT both, +OPTIONAL specific version
requires(required)
optional(optionals)
incompatible(incompatibles)
embeds(embedded)
}
github {
accessToken = ghToken
repository = "mrbuilder1961/ChatPatches"
commitish = branch // publishes to the latest supported (targeted) version
tagName = "$branch-$v" // branch-version
additionalFiles.from(remapSourcesJar.archiveFile, jar.archiveFile)
}
discord {
webhookUrl = dcToken // official
dryRunWebhookUrl = dcDebugToken // debug testing
username = "Publisher Bot"
avatarUrl = "https://cdn.modrinth.com/data/MOqt4Z5n/56c954dea290ef4dd1b0d6ea92a811acac62ca85.png"
}
}