forked from Shadows-of-Fire/Shadows-of-Greg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
284 lines (242 loc) · 8.16 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
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
import java.util.regex.Pattern
import groovy.json.JsonSlurper
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
buildscript {
repositories {
mavenCentral()
maven {
name = "Forge"
url = "https://maven.minecraftforge.net/"
}
maven {
name = "jitpack"
url = "https://jitpack.io"
}
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.github.GregTechCE:ForgeGradle:FG_2.3-SNAPSHOT"
classpath "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
classpath "org.apache.httpcomponents:httpmime:4.5.1"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
group = "gregicadditions"
version = getVersion()
archivesBaseName = "Shadows_of_Greg"
sourceCompatibility = targetCompatibility = '1.8'
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft {
version = "1.12.2-14.23.5.2847"
runDir = "run"
mappings = "stable_39"
makeObfSourceJar = false
replace("@VERSION@",project.version)
replaceIn("GregicAdditions.java")
}
repositories {
maven {
url = "http://dvs1.progwml6.com/files/maven/"
}
maven {
url = "https://maven.blamejared.com/"
}
maven {
url = "http://maven.ic2.player.to"
}
maven {
url "https://minecraft.curseforge.com/api/maven"
}
maven {
url = "http://chickenbones.net/maven/"
}
maven {
name = "tterrag maven"
setUrl("http://maven.tterrag.com/")
}
}
dependencies {
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+"
deobfCompile "mezz.jei:jei_1.12.2:+"
deobfCompile "net.sengir.forestry:forestry_1.12.2:+"
deobfCompile "gregtechce:gregtech:1.12.2:1.17.0.764"
deobfCompile "codechicken:ChickenASM:1.12-+"
deobfCompile "codechicken-lib-1-8:CodeChickenLib-1.12.2:3.2.3.357:universal"
deobfCompile "slimeknights.mantle:Mantle:1.12-1.3.3.42"
deobfCompile "slimeknights:TConstruct:1.12.2-2.12.0.115"
deobfCompile "team.chisel.ctm:CTM:MC1.12.2-1.0.2.31"
deobfCompile "mcjty.theoneprobe:TheOneProbe-1.12:1.12-1.4.28-17"
testImplementation "junit:junit:4.13.1"
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
/*
Fetches the last tag associated with the current branch.
*/
def getLastTag() {
return run("git describe --abbrev=0 --tags " +
(System.env["GITHUB_TAG"] ? run("git rev-list --tags --skip=1 --max-count=1") : "")
)
}
/*
Runs a command and returns the output.
*/
def run(command) {
def process = command.execute()
def outputStream = new StringBuffer();
def errorStream = new StringBuffer();
process.waitForProcessOutput(outputStream, errorStream)
errorStream.toString().with {
if (it) {
throw new GradleException("Error executing ${command}:\n> ${it}")
}
}
return outputStream.toString().trim()
}
/*
Rewrites the version.
*/
def getVersion () {
def lastTag = getLastTag()
if (System.env['GITHUB_TAG']) {
return System.env['GITHUB_TAG']
} else {
def commitNo = run "git rev-list ${lastTag}..HEAD --count"
return lastTag
}
}
task generateChangelog {
doLast {
/*
Create a comprehensive changelog.
*/
def lastTag = getLastTag()
print(lastTag)
def changelog = (run([
"git"
, "log"
, "--date=format:%d %b %Y"
, "--pretty=%s - **%an** (%ad)"
, "${lastTag}..HEAD"
].plus(
/*
Collect relevant directories only, them being:
* ./src/main/java
* ./src/main/resources
*/
sourceSets.main.java.srcDirs
.plus(sourceSets.main.resources.srcDirs)
.collect { [ "--", it ] }
).flatten()))
if (changelog) {
changelog = "Changes since ${lastTag}:\n${("\n" + changelog).replaceAll("\n", "\n* ")}"
}
def f = new File("build/changelog.md")
f.write(changelog ?: "There have been no changes.", "UTF-8")
}
}
task deployCurseForge {
doLast {
def final CURSEFORGE_ENDPOINT = "https://minecraft.curseforge.com/"
/*
Helper function for checking environmental variables.
*/
def final checkVariables = { variables ->
for (vari in variables) {
if (!System.env[vari]) {
throw new GradleException("Environmental variable ${vari} is unset")
}
}
}
checkVariables([
'CURSEFORGE_API_TOKEN', 'CURSEFORGE_PROJECT_ID'
])
/*
Helper function for fetching JSON data.
*/
def final fetch = { url, headers = null ->
def connection = new URL(url).openConnection();
connection.setRequestProperty("X-Api-Token", System.env["CURSEFORGE_API_TOKEN"])
if (headers != null) {
for (header in headers) {
connection.setRequestProperty(headers[1], headers[2])
}
}
def code = connection.getResponseCode()
if (code == 200) {
return new JsonSlurper().parseText(connection.getInputStream().getText())
} else {
throw new GradleException("Fetch failed with code ${code} (${url})")
}
}
/*
Fetch the list of Minecraft versions from CurseForge.
*/
def targetVersion = project.minecraft.version
def version = fetch(CURSEFORGE_ENDPOINT + "api/game/versions").with {
def v = it.find { it.name == targetVersion }
if (!v) {
throw new GradleException("Version ${project.minecraft.version} not found on CurseForge")
}
return v
}
/*
Fill the papers for CurseForge.
*/
def metadata = new groovy.json.JsonBuilder().with {
def versions = [ version.id ]
/*
CurseForge is dumb, so we'll have to prepend two spaces
to each newline. This is disgusting, but it works.
*/
def log = new File("build/changelog.md")
.getText("UTF-8")
.replaceAll("\n", " \n")
.replaceAll("\n\\*", "\n•")
def root = it {
changelog log
changelogType "markdown"
releaseType System.env['GITHUB_TAG'] ? "release" : "beta"
gameVersions versions
// Defined in gradle.properties
displayName "${project_fancy_name} ${project.version}"
}
if (project_curseforge_dependencies) {
def data = new JsonSlurper().parseText(project_curseforge_dependencies)
root << [relations: [ projects: data ]]
}
return it.toString()
}
/*
Upload the artifact to CurseForge.
*/
new HTTPBuilder(CURSEFORGE_ENDPOINT).request(Method.POST) { req ->
requestContentType = "multipart/form-data"
headers["X-Api-Token"] = System.env["CURSEFORGE_API_TOKEN"]
uri.path = "api/projects/${System.env["CURSEFORGE_PROJECT_ID"]}/upload-file"
req.entity = new MultipartEntityBuilder().with {
addPart("file", new FileBody(
new File("${project.jar.destinationDir}/${project.jar.archiveName}")
))
addPart("metadata", new StringBody(metadata))
return it.build()
}
}
}
}