forked from ReplayMod/ReplayMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
executable file
·167 lines (147 loc) · 6.08 KB
/
Copy pathbuild.gradle
File metadata and controls
executable file
·167 lines (147 loc) · 6.08 KB
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
import groovy.json.JsonOutput
def latestVersion = file('version.txt').readLines().first()
def releaseCommit = command('git', 'blame', '-p', '-l', 'version.txt').first().tokenize(' ').first()
if (latestVersion == '2.1.0') { // First version since change from tag-based
releaseCommit = '35ac26e91689ac9bdf12dbb9902c452464a75108' // git rev-parse 1.12.2-2.1.0
}
def currentCommit = command('git', 'rev-parse', 'HEAD').first()
if (releaseCommit == currentCommit) {
version = latestVersion
} else {
def diff = command('git', 'log', '--format=oneline', "$releaseCommit..$currentCommit").size()
version = "$latestVersion-$diff-g${currentCommit.substring(0, 7)}"
}
if (gitDescribe().endsWith('*')) {
version = "$version-dirty"
}
group= "com.replaymod"
subprojects {
buildscript {
repositories {
maven { url 'https://jitpack.io' }
}
configurations.classpath.resolutionStrategy.eachDependency { dep ->
if (System.getenv('REPRODUCIBLE_BUILD') == '1') return
def req = dep.target
// Substitute FG 2.0 with custom fork that works with Gradle 3
if (req.group == 'net.minecraftforge.gradle' && req.name == 'ForgeGradle' && req.version == '2.0-SNAPSHOT') {
dep.useTarget 'com.github.ReplayMod:ForgeGradle:dd521d0'
}
// Substitute FG 2.1 with custom fork that works with Gradle 3
if (req.group == 'net.minecraftforge.gradle' && req.name == 'ForgeGradle' && req.version == '2.1-SNAPSHOT') {
dep.useTarget 'com.github.ReplayMod:ForgeGradle:9c2f79c'
}
}
}
// Thanks for wasting my time gradle...
// Workaround for https://discuss.gradle.org/t/idea-plugin-bug/21525
apply plugin: 'eclipse'
apply plugin: 'idea'
}
def gitDescribe() {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--always', '--dirty=*'
standardOutput = stdout
}
return stdout.toString().trim()
} catch (e) {
return "unknown"
}
}
apply from: 'versions/preprocessor.gradle'
task setCoreVersion() {
doLast {
def vars = [MC: project.mcVersion as int, DEV_ENV: 1]
project.convertTree(vars, 'src/main/java')
project.convertTree(vars, 'src/main/resources')
project.file('versions/core/mcVersion').write(vars.MC.toString())
}
}
def command(Object...cmd) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine cmd
standardOutput = stdout
}
return stdout.toString().tokenize('\n')
}
def generateVersionsJson() {
// Find all tag-style releases by listing all tags
def tagVersions = command 'git', 'for-each-ref', '--sort=taggerdate', '--format=%(refname:short)', 'refs/tags'
// Find all commit-style releases
// List all commits
def releaseCommits =
command 'git', 'log', '--format=%H', '--date-order', '-E',
'--grep', /Pre-release [0-9]+ of [0-9]+\.[0-9]+\.[0-9]+/,
'--grep', /Release [0-9]+\.[0-9]+\.[0-9]+/
// Find version string and MC versions for each commit hash
def commitVersions = releaseCommits.collect { commit ->
def version = command('git', 'show', "$commit:version.txt").first()
def mcVersions = command 'git', 'ls-tree', '-d', '--name-only', "$commit:versions"
mcVersions.remove('core')
return mcVersions.collect { "$it-$version" }
}.flatten()
def versions = commitVersions + tagVersions.reverse()
def mcVersions = versions.collect {it.substring(0, it.indexOf('-'))}.unique()
mcVersions.sort(new OrderBy([0, 1, 2].collect { i -> { it -> (it.tokenize('.')[i] ?: '0') as int } }))
def root = [
homepage: 'https://www.replaymod.com/download/',
promos: [:]
]
mcVersions.forEach { mcVersion ->
def mcVersionRoot = [:]
def latest
def recommended
versions.forEach {
def (thisMcVersion, modVersion, preVersion) = it.tokenize('-')
if (thisMcVersion == mcVersion) {
mcVersionRoot[it] = tagVersions.contains(it) ?
"See https://github.com/ReplayMod/ReplayMod/releases/$it" :
'See https://www.replaymod.com/forum/thread/100'
if (latest == null) latest = it
if (preVersion == null) {
if (recommended == null) recommended = it
}
}
}
root[mcVersion] = mcVersionRoot
root.promos[mcVersion + '-latest'] = latest
if (recommended != null) {
root.promos[mcVersion + '-recommended'] = recommended
}
}
root
}
task doRelease() {
doLast {
// Parse version
def version = project.releaseVersion as String
if (gitDescribe().endsWith('*')) {
throw new InvalidUserDataException('Git working tree is dirty. Make sure to commit all changes.')
}
def (modVersion, preVersion) = version.tokenize('-')
preVersion = preVersion != null && preVersion.startsWith('b') ? preVersion.substring(1) : null
// Create new commit
def commitMessage = preVersion != null ?
"Pre-release $preVersion of $modVersion" :
"Release $modVersion"
file('version.txt').write("$version\n")
command 'git', 'add', 'version.txt'
command 'git', 'commit', '-m', commitMessage
// Generate versions.json content
def versionsRoot = generateVersionsJson()
def versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
// Switch to master branch to update versions.json
command 'git', 'checkout', 'master'
// Write versions.json
new File('versions.json').write(versionsJson)
// Commit changes
project.exec { commandLine 'git', 'add', 'versions.json' }
project.exec { commandLine 'git', 'commit', '-m', "Update versions.json for $version" }
// Return to previous branch
project.exec { commandLine 'git', 'checkout', '-' }
}
}
defaultTasks 'build'