Improved versioning: added info about commit id and commit author.

This commit is contained in:
s1lentq 2016-03-01 04:23:28 +06:00
parent d20d9a8a78
commit 43c9b2cb8c
7 changed files with 39 additions and 5 deletions

View File

@ -30,7 +30,9 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
minorVersion: m.group(2) as int, minorVersion: m.group(2) as int,
maintenanceVersion: m.group(4) ? (m.group(4) as int) : null, maintenanceVersion: m.group(4) ? (m.group(4) as int) : null,
countCommit: gitInfo.countCommit, countCommit: gitInfo.countCommit,
lastCommitDate: gitInfo.lastCommitDate lastCommitDate: gitInfo.lastCommitDate,
commitID: gitInfo.commitID,
authorCommit: gitInfo.authorCommit
) )
} else { } else {
versionInfo = new RegamedllVersionInfo( versionInfo = new RegamedllVersionInfo(
@ -38,7 +40,9 @@ if (gitInfo.tag && gitInfo.tag[0] == 'v') {
minorVersion: project.minorVersion as int, minorVersion: project.minorVersion as int,
suffix: 'SNAPSHOT', suffix: 'SNAPSHOT',
countCommit: gitInfo.countCommit, countCommit: gitInfo.countCommit,
lastCommitDate: gitInfo.lastCommitDate lastCommitDate: gitInfo.lastCommitDate,
commitID: gitInfo.commitID,
authorCommit: gitInfo.authorCommit
) )
} }

View File

@ -10,4 +10,6 @@ class GitInfo {
String branch String branch
String tag String tag
Integer countCommit Integer countCommit
String commitID
String authorCommit
} }

View File

@ -26,6 +26,18 @@ class GitVersioner {
return count; return count;
} }
// return last commit excluding merge commit
static RevCommit parseCommitLast(Repository repo) {
Iterable<RevCommit> 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) { static GitInfo versionForDir(File dir) {
FileRepositoryBuilder builder = new FileRepositoryBuilder() FileRepositoryBuilder builder = new FileRepositoryBuilder()
Repository repo = builder.setWorkTree(dir) Repository repo = builder.setWorkTree(dir)
@ -38,17 +50,27 @@ class GitVersioner {
} }
def commit = new RevWalk(repo).parseCommit(head) def commit = new RevWalk(repo).parseCommit(head)
def commitLast = parseCommitLast(repo)
int commitCount = getCountCommit(repo)
def branch = repo.getBranch() def branch = repo.getBranch()
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC) 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 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( return new GitInfo(
lastCommitDate: commitDate, lastCommitDate: commitDate,
branch: branch, branch: branch,
tag: tag, tag: tag,
countCommit: commitCount countCommit: commitCount,
commitID: headCommitId,
authorCommit: authorCommit
) )
} }
} }

View File

@ -14,6 +14,8 @@ class RegamedllVersionInfo {
String suffix String suffix
Integer countCommit Integer countCommit
DateTime lastCommitDate DateTime lastCommitDate
String commitID
String authorCommit
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) { String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) {
StringBuilder sb = new StringBuilder() StringBuilder sb = new StringBuilder()

View File

@ -371,6 +371,6 @@ task generateAppVersion {
renderedFile.delete() renderedFile.delete()
renderedFile.write(content, 'utf-8') 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();
} }
} }

View File

@ -109,6 +109,7 @@ void GameDLL_Version_f()
// print version // print version
CONSOLE_ECHO("ReGameDLL build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")\n"); 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("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() void EXT_FUNC GameDLLInit()

View File

@ -10,6 +10,9 @@
\#define VERSION_MAJOR ${verInfo.majorVersion} \#define VERSION_MAJOR ${verInfo.majorVersion}
\#define VERSION_MINOR ${verInfo.minorVersion} \#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_D ${verInfo.format('.', '-', true)}
\#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit} \#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit}