From 43c9b2cb8c7cac4096101a2cbaf9a30b08dd1f28 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 1 Mar 2016 04:23:28 +0600 Subject: [PATCH] Improved versioning: added info about commit id and commit author. --- build.gradle | 8 ++++-- .../src/main/groovy/versioning/GitInfo.groovy | 2 ++ .../groovy/versioning/GitVersioner.groovy | 26 +++++++++++++++++-- .../versioning/RegamedllVersionInfo.groovy | 2 ++ regamedll/build.gradle | 2 +- regamedll/dlls/game.cpp | 1 + regamedll/version/appversion.vm | 3 +++ 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index c78a2cc2..08694329 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,9 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') { minorVersion: m.group(2) as int, maintenanceVersion: m.group(4) ? (m.group(4) as int) : null, countCommit: gitInfo.countCommit, - lastCommitDate: gitInfo.lastCommitDate + lastCommitDate: gitInfo.lastCommitDate, + commitID: gitInfo.commitID, + authorCommit: gitInfo.authorCommit ) } else { versionInfo = new RegamedllVersionInfo( @@ -38,7 +40,9 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') { minorVersion: project.minorVersion as int, suffix: 'SNAPSHOT', countCommit: gitInfo.countCommit, - lastCommitDate: gitInfo.lastCommitDate + lastCommitDate: gitInfo.lastCommitDate, + commitID: gitInfo.commitID, + authorCommit: gitInfo.authorCommit ) } diff --git a/buildSrc/src/main/groovy/versioning/GitInfo.groovy b/buildSrc/src/main/groovy/versioning/GitInfo.groovy index 78100bc7..9d89fce5 100644 --- a/buildSrc/src/main/groovy/versioning/GitInfo.groovy +++ b/buildSrc/src/main/groovy/versioning/GitInfo.groovy @@ -10,4 +10,6 @@ class GitInfo { String branch String tag Integer countCommit + String commitID + String authorCommit } diff --git a/buildSrc/src/main/groovy/versioning/GitVersioner.groovy b/buildSrc/src/main/groovy/versioning/GitVersioner.groovy index 986d036b..56a41f16 100644 --- a/buildSrc/src/main/groovy/versioning/GitVersioner.groovy +++ b/buildSrc/src/main/groovy/versioning/GitVersioner.groovy @@ -26,6 +26,18 @@ class GitVersioner { return count; } + // return last commit excluding merge commit + static RevCommit parseCommitLast(Repository repo) { + Iterable commits = Git.wrap(repo).log().call() + for (RevCommit b : commits) { + if (b.getParents().length > 1) { // it's merge commit ignore it + continue; + } + return b; + } + + return null; + } static GitInfo versionForDir(File dir) { FileRepositoryBuilder builder = new FileRepositoryBuilder() Repository repo = builder.setWorkTree(dir) @@ -38,17 +50,27 @@ class GitVersioner { } def commit = new RevWalk(repo).parseCommit(head) + def commitLast = parseCommitLast(repo) + int commitCount = getCountCommit(repo) + def branch = repo.getBranch() def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC) - int commitCount = getCountCommit(repo); + + if (!commit) { + throw new RuntimeException("Can't find last commit.") + } String tag = repo.tags.find { kv -> kv.value.objectId == commit.id }?.key + String headCommitId = commit.getId().abbreviate(7).name(); + String authorCommit = commitLast.getAuthorIdent().getName(); return new GitInfo( lastCommitDate: commitDate, branch: branch, tag: tag, - countCommit: commitCount + countCommit: commitCount, + commitID: headCommitId, + authorCommit: authorCommit ) } } diff --git a/buildSrc/src/main/groovy/versioning/RegamedllVersionInfo.groovy b/buildSrc/src/main/groovy/versioning/RegamedllVersionInfo.groovy index 273aa15d..a3ba26fd 100644 --- a/buildSrc/src/main/groovy/versioning/RegamedllVersionInfo.groovy +++ b/buildSrc/src/main/groovy/versioning/RegamedllVersionInfo.groovy @@ -14,6 +14,8 @@ class RegamedllVersionInfo { String suffix Integer countCommit DateTime lastCommitDate + String commitID + String authorCommit String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { StringBuilder sb = new StringBuilder() diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 21e112ff..468c9575 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -371,6 +371,6 @@ task generateAppVersion { renderedFile.delete() renderedFile.write(content, 'utf-8') - println 'The current ReGameDLL version is ' + verInfo.asVersion().toString() + ', maven version is ' + verInfo.asMavenVersion().toString(); + println 'The current ReGameDLL version is ' + verInfo.asVersion().toString() + ', maven version is ' + verInfo.asMavenVersion().toString() + ', commit id: ' + verInfo.commitID.toString() + ', commit author: ' + verInfo.authorCommit.toString(); } } diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp index d2758ca4..d5dc68d6 100644 --- a/regamedll/dlls/game.cpp +++ b/regamedll/dlls/game.cpp @@ -109,6 +109,7 @@ void GameDLL_Version_f() // print version CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n"); CONSOLE_ECHO("ReGameDLL API version %i.%i\n", REGAMEDLL_API_VERSION_MAJOR, REGAMEDLL_API_VERSION_MINOR); + CONSOLE_ECHO("Build from: https://github.com/s1lentq/ReGameDLL_CS/commit/" APP_COMMIT_ID " (" APP_COMMIT_AUTHOR ")\n"); } void EXT_FUNC GameDLLInit() diff --git a/regamedll/version/appversion.vm b/regamedll/version/appversion.vm index 14140d44..21384417 100644 --- a/regamedll/version/appversion.vm +++ b/regamedll/version/appversion.vm @@ -10,6 +10,9 @@ \#define VERSION_MAJOR ${verInfo.majorVersion} \#define VERSION_MINOR ${verInfo.minorVersion} +\#define APP_COMMIT_AUTHOR "${verInfo.authorCommit}" +\#define APP_COMMIT_ID "${verInfo.commitID}" + \#define APP_VERSION_D ${verInfo.format('.', '-', true)} \#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit}