Changelog generation
This commit is contained in:
parent
9973a9f8e8
commit
939bb4b7da
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,6 +3,10 @@
|
|||||||
# eclipse
|
# eclipse
|
||||||
/eclipse
|
/eclipse
|
||||||
|
|
||||||
|
# idea
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
|
||||||
# gradle
|
# gradle
|
||||||
build
|
build
|
||||||
.gradle
|
.gradle
|
||||||
|
77
build.gradle
77
build.gradle
@ -1,4 +1,5 @@
|
|||||||
import groovy.json.JsonSlurper
|
import groovy.json.JsonSlurper
|
||||||
|
import kcauldron.CreateChangelog
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
@ -47,26 +48,48 @@ minecraft {
|
|||||||
|
|
||||||
group = 'pw.prok'
|
group = 'pw.prok'
|
||||||
|
|
||||||
def retrieveBuildNumber() {
|
ext.buildInfoCached = null;
|
||||||
if (!project.hasProperty('officialBuild')) return 'UNOFFICIAL.' + retrieveGitHash(false)
|
|
||||||
new JsonSlurper().parse(new URL("https://prok.pw/version/${group}/${name}"))['nextBuildNumber']
|
def buildInfo(String key) {
|
||||||
|
if (!buildInfoCached) {
|
||||||
|
if (project.hasProperty('officialBuild')) {
|
||||||
|
buildInfoCached = new JsonSlurper().parse(new URL("https://prok.pw/version/${group}/${name}"))
|
||||||
|
} else {
|
||||||
|
buildInfoCached = [
|
||||||
|
nextBuildNumber: 'UNOFFICIAL.' + gitInfo('hash'),
|
||||||
|
version : 'NONE'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key ? buildInfoCached[key] : buildInfoCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
def retrieveGitHash(full = true) {
|
ext.gitInfoCached = null;
|
||||||
if (file('.git').exists())
|
|
||||||
return ['git', 'log', "--format=%${full?'H':'h'}", '-n', '1'].execute().text.trim()
|
|
||||||
return 'NOTGIT'
|
|
||||||
}
|
|
||||||
|
|
||||||
def retrieveGitBranch() {
|
def gitInfo(String key) {
|
||||||
if (file('.git').exists())
|
if (!gitInfoCached) {
|
||||||
return ['git', 'symbolic-ref', '--short', 'HEAD'].execute().text.trim();
|
if (file('.git').exists()) {
|
||||||
return 'NOTGIT'
|
gitInfoCached = [
|
||||||
|
hash : ['git', 'log', "--format=%h", '-n', '1'].execute().text.trim(),
|
||||||
|
fullHash: ['git', 'log', "--format=%H", '-n', '1'].execute().text.trim(),
|
||||||
|
branch : ['git', 'symbolic-ref', '--short', 'HEAD'].execute().text.trim(),
|
||||||
|
message : ['git', 'log', "--format=%B", '-n', '1'].execute().text.trim()
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
gitInfoCached = [
|
||||||
|
hash : 'NOT_A_GIT',
|
||||||
|
fullHash: 'NOT_A_GIT',
|
||||||
|
branch : 'NOT_A_GIT',
|
||||||
|
message : 'NOT_A_GIT'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key ? gitInfoCached[key] : gitInfoCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.mcVersion = "1.7.10"
|
ext.mcVersion = "1.7.10"
|
||||||
ext.forgeVersion = "1420"
|
ext.forgeVersion = "1420"
|
||||||
ext.revision = retrieveBuildNumber()
|
ext.revision = buildInfo('nextBuildNumber')
|
||||||
version = "${mcVersion}-${forgeVersion}.${revision}"
|
version = "${mcVersion}-${forgeVersion}.${revision}"
|
||||||
println "Updated KCauldron version: ${version}"
|
println "Updated KCauldron version: ${version}"
|
||||||
|
|
||||||
@ -77,12 +100,12 @@ launch4j {
|
|||||||
tasks.packageUniversal {
|
tasks.packageUniversal {
|
||||||
classifier = 'server'
|
classifier = 'server'
|
||||||
manifest.attributes([
|
manifest.attributes([
|
||||||
'KCauldron-Git-Branch': retrieveGitBranch(),
|
'KCauldron-Git-Branch' : gitInfo('branch'),
|
||||||
'KCauldron-Git-Hash': retrieveGitHash(),
|
'KCauldron-Git-Hash' : gitInfo('fullHash'),
|
||||||
'KCauldron-Version' : project.version,
|
'KCauldron-Version' : project.version,
|
||||||
'Implementation-Vendor' : 'Prototik',
|
'Implementation-Vendor' : 'Prototik',
|
||||||
'Implementationk-Title': 'KCauldron',
|
'Implementation-Title' : 'KCauldron',
|
||||||
'Implementation-Version': 'KCauldron-'+project.version,
|
'Implementation-Version': project.version,
|
||||||
'Forge-Version' : '10.13.3.1420',
|
'Forge-Version' : '10.13.3.1420',
|
||||||
'Specification-Vendor' : 'Bukkit Team',
|
'Specification-Vendor' : 'Bukkit Team',
|
||||||
'Specification-Title' : 'Bukkit',
|
'Specification-Title' : 'Bukkit',
|
||||||
@ -92,9 +115,20 @@ tasks.packageUniversal {
|
|||||||
|
|
||||||
tasks.createChangelog.onlyIf { false }
|
tasks.createChangelog.onlyIf { false }
|
||||||
|
|
||||||
|
task packageChangelog(type: CreateChangelog) {
|
||||||
|
onlyIf { project.hasProperty('officialBuild') }
|
||||||
|
classifier = 'changelog'
|
||||||
|
extension = 'txt'
|
||||||
|
oldChangelogUrl = "https://prok.pw/repo/${project.group.replace('.','/')}/${project.name}/${buildInfo('version')}/${project.name}-${buildInfo('version')}-changelog.txt"
|
||||||
|
hash = gitInfo('hash')
|
||||||
|
message = gitInfo('message')
|
||||||
|
version = project.version
|
||||||
|
}
|
||||||
|
|
||||||
task signJars(type: Sign, dependsOn: [packageUniversal, packageInstaller]) {
|
task signJars(type: Sign, dependsOn: [packageUniversal, packageInstaller]) {
|
||||||
sign packageInstaller
|
sign packageInstaller
|
||||||
sign packageUniversal
|
sign packageUniversal
|
||||||
|
sign packageChangelog
|
||||||
}
|
}
|
||||||
|
|
||||||
task preparePublication(dependsOn: signJars) {}
|
task preparePublication(dependsOn: signJars) {}
|
||||||
@ -103,9 +137,11 @@ def getSignatureFiles = {
|
|||||||
def allFiles = project.tasks.signJars.signatureFiles.collect { it }
|
def allFiles = project.tasks.signJars.signatureFiles.collect { it }
|
||||||
def signedServer = allFiles.find { it.name.contains('-server') }
|
def signedServer = allFiles.find { it.name.contains('-server') }
|
||||||
def signedInstaller = allFiles.find { it.name.contains('-installer') }
|
def signedInstaller = allFiles.find { it.name.contains('-installer') }
|
||||||
|
def signedChangelog = allFiles.find { it.name.contains('-changelog') }
|
||||||
return [
|
return [
|
||||||
[archive: signedServer, classifier: 'server', extension: 'jar.asc'],
|
[archive: signedServer, classifier: 'server', extension: 'jar.asc'],
|
||||||
[archive: signedInstaller, classifier: 'installer', extension: 'jar.asc']
|
[archive: signedInstaller, classifier: 'installer', extension: 'jar.asc'],
|
||||||
|
[archive: signedChangelog, classifier: 'changelog', extension: 'txt.asc']
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,17 +158,16 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
publications {
|
publications {
|
||||||
gpg(MavenPublication) {
|
maven(MavenPublication) {
|
||||||
getSignatureFiles().each { signature ->
|
getSignatureFiles().each { signature ->
|
||||||
artifact(signature.archive) {
|
artifact(signature.archive) {
|
||||||
classifier = signature.classifier
|
classifier = signature.classifier
|
||||||
extension = signature.extension
|
extension = signature.extension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
jar(MavenPublication) {
|
|
||||||
artifact packageUniversal
|
artifact packageUniversal
|
||||||
artifact packageInstaller
|
artifact packageInstaller
|
||||||
|
artifact packageChangelog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
buildSrc/build.gradle
Normal file
7
buildSrc/build.gradle
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
apply plugin: 'groovy'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile gradleApi()
|
||||||
|
compile localGroovy()
|
||||||
|
}
|
||||||
|
|
59
buildSrc/src/main/groovy/kcauldron/CreateChangelog.groovy
Normal file
59
buildSrc/src/main/groovy/kcauldron/CreateChangelog.groovy
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package kcauldron
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException
|
||||||
|
import org.gradle.api.GradleScriptException
|
||||||
|
import org.gradle.api.file.FileCollection
|
||||||
|
import org.gradle.api.internal.file.copy.CopyAction
|
||||||
|
import org.gradle.api.internal.file.copy.CopyActionProcessingStream
|
||||||
|
import org.gradle.api.internal.tasks.SimpleWorkResult
|
||||||
|
import org.gradle.api.tasks.Input
|
||||||
|
import org.gradle.api.tasks.SkipWhenEmpty
|
||||||
|
import org.gradle.api.tasks.WorkResult
|
||||||
|
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||||
|
|
||||||
|
public class CreateChangelog extends AbstractArchiveTask {
|
||||||
|
@Input
|
||||||
|
def String oldChangelogUrl
|
||||||
|
@Input
|
||||||
|
def String hash
|
||||||
|
@Input
|
||||||
|
def String message
|
||||||
|
@Input
|
||||||
|
def String version
|
||||||
|
@Input
|
||||||
|
def String format = "# <version>: <hash>\n<message>\n\n"
|
||||||
|
|
||||||
|
@Override
|
||||||
|
FileCollection getSource() {
|
||||||
|
return project.files(project.buildDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CopyAction createCopyAction() {
|
||||||
|
return new CopyAction() {
|
||||||
|
@Override
|
||||||
|
WorkResult execute(CopyActionProcessingStream stream) {
|
||||||
|
def oldChangelog;
|
||||||
|
try {
|
||||||
|
oldChangelog = new URL(oldChangelogUrl).text.trim();
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (!project.hasProperty('ignoreOldChangelog'))
|
||||||
|
throw new GradleException('Error occurred during fetching latest log', e)
|
||||||
|
oldChangelog = ''
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
def newMessage = '';
|
||||||
|
message.eachLine { newMessage += ' ' + it + '\n' }
|
||||||
|
def append = format.replace('<version>', version).replace('<hash>', hash).replace('<message>', message)
|
||||||
|
def changelog = append + oldChangelog;
|
||||||
|
archivePath.write(changelog.trim(), 'utf-8')
|
||||||
|
return new SimpleWorkResult(true);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new SimpleWorkResult(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user