-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.gradle
222 lines (193 loc) · 6 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
plugins {
id "com.github.breadmoirai.github-release" version "2.2.12"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.+"
}
import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit
def runCommand(cmd) {
def commitHashProc = cmd.execute(null, file("${projectDir}"))
commitHashProc.waitFor()
if(commitHashProc.exitValue() == 0){
def commitHash = commitHashProc.text.trim()
return commitHash
} else {
println commitHashProc.err.text
println(cmd + " exited with non-zero return value")
return null
}
}
def getCommitVersion() {
def ver = null
def versionPath = "version.txt"
if(file(versionPath).isFile()) {
ver = file(versionPath).text
} else {
ver = runCommand("git describe --tags --dirty") ?: "UNKNOWN-" + runCommand("git describe --always --dirty") ?: "UNKNOWN"
}
ver = ver.trim()
if(ver.charAt(0) == 'v') {
ver = ver.substring(1)
}
return ver
}
def buildVersion = getCommitVersion()
def changeLogFile = new File("${projectDir}/changelog.md")
def changeLog = changeLogFile.exists() ? changeLogFile.getText('UTF-8') : ""
def readConfigs() {
def configs = [:]
file('.').eachFileMatch(groovy.io.FileType.FILES, ~/publish-.*\.properties/, {
def props = new Properties()
it.withInputStream { props.load(it) }
def name = it.name.split("\\.properties")[0].split("-")[1]
configs[name] = props
})
return configs
}
ext.configs = readConfigs()
ext.gameVersions = configs.keySet()
ext.githubToken = System.getenv("GITHUB_TOKEN")
ext.curseToken = System.getenv("CURSEFORGE_TOKEN")
ext.modrinthToken = System.getenv("MODRINTH_TOKEN")
def debugPublish = project.hasProperty("debugPublish")
def useVPrefixForTag = project.hasProperty("useVPrefixForTag") && project.useVPrefixForTag.toBoolean()
task build {}
task assemble {}
if(githubToken != null){
githubRelease {
token project.githubToken // This is your personal access token with Repo permissions
// You get this from your user settings > developer settings > Personal Access Tokens
owner project.githubOwner // default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
repo project.githubRepo // by default this is set to your project name
tagName ((useVPrefixForTag ? "v" : "") + "${buildVersion}") // by default this is set to "v${project.version}"
targetCommitish "master" // by default this is set to "master"
releaseName "${buildVersion}"
body changeLog // by default this is empty
draft false // by default this is false
prerelease false // by default this is false
releaseAssets getFiles() // this points to which files you want to upload as assets with your release
overwrite false // by default false; if set to true, will delete an existing release with the same tag and name
dryRun debugPublish // by default false; you can use this to see what actions would be taken without making a release
apiEndpoint "https://api.github.com" // should only change for github enterprise users
client new OkHttpClient.Builder()
.writeTimeout(5, TimeUnit.MINUTES)
.readTimeout(5, TimeUnit.MINUTES)
.build() // Added because I kept getting SocketTimeoutExceptions
}
}
def getMainFile(files) {
def shortest = null
files.each {
if (shortest == null || it.name.length() < shortest.name.length()) {
shortest = it
}
}
return shortest
}
task publishCurseForge {}
task publishModrinth {}
if(curseToken != null) {
project.gameVersions.forEach {
task("publishCurseForge-$it", type: GradleBuild) {
tasks = ["curseforge"]
startParameter.projectProperties = gradle.startParameter.projectProperties + [gameVersion: it]
}
publishCurseForge.dependsOn "publishCurseForge-$it"
}
}
if(modrinthToken != null) {
project.gameVersions.forEach {
task("publishModrinth-$it", type: GradleBuild) {
tasks = ["modrinth"]
startParameter.projectProperties = gradle.startParameter.projectProperties + [gameVersion: it]
}
publishModrinth.dependsOn "publishModrinth-$it"
}
}
gameVersions.each {
def gameVersion = it
def files = getFiles(gameVersion)
def mainFile = getMainFile(files)
def extraFiles = files - mainFile
if(debugPublish) {
println("Main file: " + mainFile)
println("Additional files: " + extraFiles)
}
if(curseToken != null) {
curseforge {
apiKey = project.curseToken
project {
id = project.curseID
changelogType = 'markdown'
changelog = changeLog
releaseType = 'release'
addGameVersion gameVersion
addGameVersion "Forge"
mainArtifact(mainFile) {
displayName = "$releaseName $buildVersion"
relations {
configs[gameVersion]['curseForgeRelations'].split(';').each {
def kv = it.split(':')
def k = kv[0]
def v = kv[1]
if (k == 'requiredDependency') {
requiredDependency v
} else if (k == 'embeddedLibrary') {
embeddedLibrary v
} else if (k == 'optionalDependency') {
optionalDependency v
} else if (k == 'tool') {
tool v
} else if (k == 'incompatible') {
incompatible v
} else {
throw new IllegalArgumentException(k)
}
}
}
}
extraFiles.each { addArtifact(it) }
}
options {
debug = debugPublish
javaIntegration = false
forgeGradleIntegration = false
javaVersionAutoDetect = false
}
}
}
if(modrinthToken != null) {
modrinth {
token = project.modrinthToken
projectId = project.modrinthID
versionNumber = "$gameVersion-$buildVersion"
versionName = "$releaseName $buildVersion"
uploadFile = mainFile
gameVersions = [gameVersion]
additionalFiles = extraFiles
loaders = ['forge']
changelog = changeLog
detectLoaders = false
debugMode = debugPublish
dependencies {
// TODO
}
}
}
}
def getFiles(ver) {
def files = []
new File('.', configs[ver]['buildPath']).eachFile(groovy.io.FileType.FILES, {
if(!(it.name.endsWith("-sources.jar") || it.name.endsWith("-dev.jar"))){
files << it
}
})
return files
}
def getFiles() {
def files = []
project.gameVersions.each {
files += getFiles(it)
}
return files
}