forked from Hendrix-Shen/MagicLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
176 lines (144 loc) · 5.79 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
plugins {
id("maven-publish")
id("org.ajoberstar.grgit").version("${grgit_version}")
}
ext {
Map env = System.getenv()
File localPropsFile = file("${rootDir}/local.properties")
if (localPropsFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(localPropsFile))
p.each { key, value ->
ext[key as String] = value
}
}
getEnv = {
return env
}
getOrDefault = { String key, String defaultValue ->
String value
(value = project.findProperty(key)) && !value.isEmpty() ? value : defaultValue
}
isGithubCI = {
return env.get("GITHUB_ACTION") != null
}
getBuildNumber = {
return env.GITHUB_RUN_NUMBER ? env.GITHUB_RUN_NUMBER : 0
}
getVersionGit = { List paths ->
if (grgit == null || grgit.head() == null) {
return "nogit"
}
List latestCommits = paths.isEmpty() ? grgit.log(maxCommits: 1) : grgit.log(paths: paths, maxCommits: 1)
return latestCommits.isEmpty() ? "uncommited" : "${latestCommits.get(0).id.substring(0, 7)}"
}
getVersionType = {
String type = getOrDefault("ow.build.environment.buildType", null)
if (type != null) {
return type
}
type = env.BUILD_TYPE
switch (type) {
case "BETA":
return "beta"
case "FORK":
return "fork"
case "RC":
return "rc"
case "RELEASE":
return "stable"
case "PULL_REQUEST":
return "pull_request"
default:
return "development"
}
}
getVersionPatch = { List paths ->
if (grgit == null || grgit.head() == null) {
return 0
}
List latestCommits = paths.isEmpty() ? grgit.log() : grgit.log(paths: paths)
return latestCommits.size()
}
getVersion = { Project proj ->
return "${proj.property("mod.version")}.${getVersionPatch(proj == rootProject ? [] : [proj.projectDir.name])}"
}
getVersionWithCommitHash = { Project proj ->
return "${getVersion(proj)}+${getVersionGit(proj == rootProject ? [] : [proj.projectDir.name])}-${getVersionType()}"
}
getModVersion = { Project proj ->
return "${getVersion(proj)}-${getVersionType()}"
}
getMavenArtifactVersion = { Project proj ->
return project.getVersionType() == "stable" ? "${getVersion(proj)}" : "${getModVersion(proj)}"
}
addPomMetadataInformation = { Project project, MavenPublication publication ->
publication.pom {
name.set("${project.property("mod.archives_base_name")}")
description.set("${project.property("mod.description")}")
url.set("${project.property("mod.homepage")}")
licenses {
license {
name.set("${project.property("mod.license")}")
url.set("${project.property("mod.license_url")}")
}
}
developers {
developer {
id.set("Hendrix-Shen")
name.set("Hendrix-Shen")
email.set("[email protected]")
}
developer {
id.set("plusls")
name.set("plusls")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:${project.property("mod.sources")}.git")
developerConnection.set("scm:git:${project.property("mod.sources").replace("https", "ssh")}.git")
url.set("${project.property("mod.sources")}")
}
}
}
String nyanMaven_username = project.getOrDefault("secrets.nyanMaven.username", project.getEnv().NYAN_MAVEN_USERNAME)
String nyanMaven_password = project.getOrDefault("secrets.nyanMaven.password", project.getEnv().NYAN_MAVEN_PASSWORD)
isNyanMavenCredentialsExist = {
return nyanMaven_username && nyanMaven_password
}
credentialsNyanMaven = { MavenArtifactRepository mavenArtifactRepository ->
mavenArtifactRepository.credentials { PasswordCredentials passwordCredentials ->
username(nyanMaven_username)
password(nyanMaven_password)
}
mavenArtifactRepository.authentication { AuthenticationContainer authentications ->
BasicAuthentication
}
}
}
tasks.register("genLocalProperties") {
it.group("${project.property("mod.id")}")
doFirst {
File localPropsFile = file("${rootDir}/local.properties")
if (localPropsFile.exists()) {
throw new IllegalStateException("local.properties file already generated. If you want to regenerate it, please delete it manually first")
} else {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(localPropsFile))
bufferedWriter.writeLine("# Secrets")
bufferedWriter.writeLine("secrets.gpg.signingKey=")
bufferedWriter.writeLine("secrets.gpg.signingPassword=")
bufferedWriter.writeLine("secrets.nyanMaven.username=")
bufferedWriter.writeLine("secrets.nyanMaven.password=")
bufferedWriter.writeLine("")
bufferedWriter.writeLine("# Overwritten configurations")
bufferedWriter.writeLine("ow.build.environment.local=")
bufferedWriter.writeLine("ow.build.environment.buildType=")
bufferedWriter.writeLine("ow.game.window.width=")
bufferedWriter.writeLine("ow.game.window.height=")
bufferedWriter.writeLine("ow.game.window.username=")
bufferedWriter.close()
project.getLogger().info("local.properties generated successfully!")
}
}
}