mirror of
https://github.com/rehlds/metamod-r.git
synced 2025-02-05 18:20:35 +03:00
Refactoring versioning
This commit is contained in:
parent
94df0af371
commit
d51cc853cc
24
build.gradle
24
build.gradle
@ -25,27 +25,27 @@ if (gitInfo && gitInfo.tag && gitInfo.tag[0] == 'v') {
|
|||||||
majorVersion: m.group(1) as int,
|
majorVersion: m.group(1) as int,
|
||||||
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,
|
localChanges: gitInfo.localChanges,
|
||||||
lastCommitDate: gitInfo.lastCommitDate,
|
commitDate: gitInfo.commitDate,
|
||||||
commitID: gitInfo.commitID,
|
commitSHA: gitInfo.commitSHA,
|
||||||
authorCommit: gitInfo.authorCommit,
|
commitURL: gitInfo.commitURL
|
||||||
urlCommits: gitInfo.urlCommits
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
versionInfo = new MetamodVersionInfo(
|
versionInfo = new MetamodVersionInfo(
|
||||||
majorVersion: project.majorVersion as int,
|
majorVersion: project.majorVersion as int,
|
||||||
minorVersion: project.minorVersion as int,
|
minorVersion: project.minorVersion as int,
|
||||||
specialVersion: gitInfo ? project.specialVersion : "SNAPSHOT",
|
maintenanceVersion: project.maintenanceVersion as int,
|
||||||
countCommit: gitInfo ? gitInfo.countCommit : 0,
|
suffix: '',
|
||||||
lastCommitDate: gitInfo ? gitInfo.lastCommitDate : new DateTime(),
|
localChanges: gitInfo ? gitInfo.localChanges : true,
|
||||||
commitID: gitInfo ? gitInfo.commitID : "",
|
commitDate: gitInfo ? gitInfo.commitDate : new DateTime(),
|
||||||
authorCommit: gitInfo ? gitInfo.authorCommit : "",
|
commitSHA: gitInfo ? gitInfo.commitSHA : "",
|
||||||
urlCommits: gitInfo ? gitInfo.urlCommits : ""
|
commitURL: gitInfo ? gitInfo.commitURL : "",
|
||||||
|
commitCount: gitInfo ? (gitInfo.commitCount as int) : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
project.ext.metamodVersionInfo = versionInfo
|
project.ext.metamodVersionInfo = versionInfo
|
||||||
project.version = versionInfo.asVersion()
|
project.version = versionInfo.asMavenVersion()
|
||||||
|
|
||||||
apply from: 'publish.gradle'
|
apply from: 'publish.gradle'
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import org.apache.velocity.Template
|
|||||||
import org.apache.velocity.VelocityContext
|
import org.apache.velocity.VelocityContext
|
||||||
import org.apache.velocity.app.Velocity
|
import org.apache.velocity.app.Velocity
|
||||||
import org.joda.time.format.DateTimeFormat
|
import org.joda.time.format.DateTimeFormat
|
||||||
import versioning.MetamodVersionInfo
|
|
||||||
|
|
||||||
class VelocityUtils {
|
class VelocityUtils {
|
||||||
|
|
||||||
@ -20,28 +19,14 @@ class VelocityUtils {
|
|||||||
|
|
||||||
Velocity.init(p);
|
Velocity.init(p);
|
||||||
}
|
}
|
||||||
static String renderTemplate(File tplFile, MetamodVersionInfo ctx) {
|
|
||||||
|
static String renderTemplate(File tplFile, Map<String, ? extends Object> ctx) {
|
||||||
Template tpl = Velocity.getTemplate(tplFile.absolutePath)
|
Template tpl = Velocity.getTemplate(tplFile.absolutePath)
|
||||||
if (!tpl) {
|
if (!tpl) {
|
||||||
throw new RuntimeException("Failed to load velocity template ${tplFile.absolutePath}: not found")
|
throw new RuntimeException("Failed to load velocity template ${tplFile.absolutePath}: not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
def templateCtx = [
|
def velocityContext = new VelocityContext(ctx)
|
||||||
verInfo: ctx
|
|
||||||
]
|
|
||||||
|
|
||||||
def velocityContext = new VelocityContext(templateCtx)
|
|
||||||
|
|
||||||
if (ctx.specialVersion.length() > 0) {
|
|
||||||
velocityContext.put("appFlags", 0x0L)
|
|
||||||
velocityContext.put("formatSpecialVersion", "-" + ctx.specialVersion)
|
|
||||||
} else {
|
|
||||||
|
|
||||||
velocityContext.put("appFlags", "VS_FF_SPECIALBUILD")
|
|
||||||
velocityContext.put("formatSpecialVersion", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
velocityContext.put("current_version", ctx.asVersion())
|
|
||||||
velocityContext.put("_DateTimeFormat", DateTimeFormat)
|
velocityContext.put("_DateTimeFormat", DateTimeFormat)
|
||||||
|
|
||||||
def sw = new StringWriter()
|
def sw = new StringWriter()
|
||||||
|
@ -6,11 +6,11 @@ import org.joda.time.DateTime
|
|||||||
|
|
||||||
@CompileStatic @TypeChecked
|
@CompileStatic @TypeChecked
|
||||||
class GitInfo {
|
class GitInfo {
|
||||||
DateTime lastCommitDate
|
boolean localChanges
|
||||||
|
DateTime commitDate
|
||||||
String branch
|
String branch
|
||||||
String tag
|
String tag
|
||||||
Integer countCommit
|
String commitSHA
|
||||||
String commitID
|
String commitURL
|
||||||
String authorCommit
|
Integer commitCount
|
||||||
String urlCommits
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package versioning
|
package versioning
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import groovy.transform.TypeChecked
|
import groovy.transform.TypeChecked
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.api.Status;
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
import org.eclipse.jgit.lib.Repository
|
import org.eclipse.jgit.lib.Repository
|
||||||
import org.eclipse.jgit.lib.StoredConfig
|
import org.eclipse.jgit.lib.StoredConfig
|
||||||
@ -14,6 +17,7 @@ import org.joda.time.DateTimeZone
|
|||||||
|
|
||||||
@CompileStatic @TypeChecked
|
@CompileStatic @TypeChecked
|
||||||
class GitVersioner {
|
class GitVersioner {
|
||||||
|
|
||||||
static GitInfo versionForDir(String dir) {
|
static GitInfo versionForDir(String dir) {
|
||||||
versionForDir(new File(dir))
|
versionForDir(new File(dir))
|
||||||
}
|
}
|
||||||
@ -26,22 +30,10 @@ 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 String prepareUrlToCommits(String url) {
|
static String prepareUrlToCommits(String url) {
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
// default remote url
|
// default remote url
|
||||||
return "https://bitbucket.org/rehlds/metamod/commits/";
|
return "https://github.com/theAsmodai/metamod-r/commits/";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -61,27 +53,44 @@ class GitVersioner {
|
|||||||
} else {
|
} else {
|
||||||
sb.append(childPath).append('/commit/');
|
sb.append(childPath).append('/commit/');
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
// check uncommited changes
|
||||||
|
static boolean getUncommittedChanges(Repository repo) {
|
||||||
|
Git git = new Git(repo);
|
||||||
|
Status status = git.status().call();
|
||||||
|
|
||||||
|
Set<String> uncommittedChanges = status.getUncommittedChanges();
|
||||||
|
for(String uncommitted : uncommittedChanges) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
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)
|
||||||
.findGitDir()
|
.findGitDir()
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
ObjectId head = repo.resolve('HEAD')
|
ObjectId head = repo.resolve('HEAD');
|
||||||
if (!head) {
|
if (!head) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
final StoredConfig cfg = repo.getConfig();
|
final StoredConfig cfg = repo.getConfig();
|
||||||
def commit = new RevWalk(repo).parseCommit(head)
|
def commit = new RevWalk(repo).parseCommit(head);
|
||||||
def commitLast = parseCommitLast(repo)
|
if (!commit) {
|
||||||
int commitCount = getCountCommit(repo)
|
throw new RuntimeException("Can't find last commit.");
|
||||||
|
}
|
||||||
|
|
||||||
def branch = repo.getBranch()
|
def localChanges = getUncommittedChanges(repo);
|
||||||
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC)
|
def commitDate = new DateTime(1000L * commit.commitTime, DateTimeZone.UTC);
|
||||||
|
if (localChanges) {
|
||||||
|
commitDate = new DateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
def branch = repo.getBranch();
|
||||||
|
|
||||||
String url = null;
|
String url = null;
|
||||||
String remote_name = cfg.getString("branch", branch, "remote");
|
String remote_name = cfg.getString("branch", branch, "remote");
|
||||||
@ -99,31 +108,18 @@ class GitVersioner {
|
|||||||
url = cfg.getString("remote", remote_name, "url");
|
url = cfg.getString("remote", remote_name, "url");
|
||||||
}
|
}
|
||||||
|
|
||||||
println 'Debug: Start';
|
String commitURL = prepareUrlToCommits(url);
|
||||||
println ' cfg: (' + cfg + ')';
|
|
||||||
println ' branch: (' + branch + ')';
|
|
||||||
println ' remote_name: (' + remote_name + ')';
|
|
||||||
println ' url: (' + url + ')';
|
|
||||||
println 'Debug: End';
|
|
||||||
|
|
||||||
String urlCommits = prepareUrlToCommits(url);
|
|
||||||
|
|
||||||
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 commitSHA = commit.getId().abbreviate(7).name();
|
||||||
String authorCommit = commitLast.getAuthorIdent().getName();
|
|
||||||
|
|
||||||
return new GitInfo(
|
return new GitInfo(
|
||||||
lastCommitDate: commitDate,
|
localChanges: localChanges,
|
||||||
|
commitDate: commitDate,
|
||||||
branch: branch,
|
branch: branch,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
countCommit: commitCount,
|
commitSHA: commitSHA,
|
||||||
commitID: headCommitId,
|
commitURL: commitURL,
|
||||||
authorCommit: authorCommit,
|
commitCount: getCountCommit(repo)
|
||||||
urlCommits: urlCommits
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,40 +3,56 @@ package versioning
|
|||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import groovy.transform.ToString
|
import groovy.transform.ToString
|
||||||
import groovy.transform.TypeChecked
|
import groovy.transform.TypeChecked
|
||||||
|
import org.joda.time.format.DateTimeFormat
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
@CompileStatic @TypeChecked
|
@CompileStatic @TypeChecked
|
||||||
@ToString(includeNames = true)
|
@ToString(includeNames = true)
|
||||||
class MetamodVersionInfo {
|
class MetamodVersionInfo {
|
||||||
int majorVersion
|
Integer majorVersion
|
||||||
int minorVersion
|
Integer minorVersion
|
||||||
Integer maintenanceVersion
|
Integer maintenanceVersion
|
||||||
String specialVersion
|
String suffix
|
||||||
Integer countCommit
|
|
||||||
DateTime lastCommitDate
|
|
||||||
String commitID
|
|
||||||
String authorCommit
|
|
||||||
String urlCommits
|
|
||||||
|
|
||||||
String format(String versionSeparator, String suffixSeparator, boolean includeSuffix) {
|
boolean localChanges
|
||||||
|
DateTime commitDate
|
||||||
|
String commitSHA
|
||||||
|
String commitURL
|
||||||
|
Integer commitCount
|
||||||
|
|
||||||
|
String asMavenVersion(boolean extra = true, String separator = ".") {
|
||||||
StringBuilder sb = new StringBuilder()
|
StringBuilder sb = new StringBuilder()
|
||||||
sb.append(majorVersion).append(versionSeparator).append(minorVersion)
|
sb.append(majorVersion).append(separator).append(minorVersion);
|
||||||
if (maintenanceVersion != null) {
|
if (maintenanceVersion != null) {
|
||||||
sb.append(versionSeparator).append(maintenanceVersion)
|
sb.append(separator).append(maintenanceVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specialVersion && includeSuffix) {
|
if (commitCount != null) {
|
||||||
sb.append(suffixSeparator).append(specialVersion)
|
sb.append(separator).append(commitCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extra && suffix) {
|
||||||
|
sb.append('-' + suffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// do mark for this build like a modified version
|
||||||
|
if (extra && localChanges) {
|
||||||
|
sb.append('+m');
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString()
|
return sb.toString()
|
||||||
}
|
}
|
||||||
String asVersion() {
|
String asCommitDate(String pattern = null) {
|
||||||
StringBuilder sb = new StringBuilder()
|
if (pattern == null) {
|
||||||
sb.append(majorVersion).append('.' + minorVersion).append('.' + countCommit);
|
pattern = "MMM d yyyy";
|
||||||
return sb;
|
if (commitDate.getDayOfMonth() >= 10) {
|
||||||
|
pattern = "MMM d yyyy";
|
||||||
}
|
}
|
||||||
String asMavenVersion() {
|
}
|
||||||
format('.', '-', true)
|
|
||||||
|
return DateTimeFormat.forPattern(pattern).withLocale(Locale.ENGLISH).print(commitDate);
|
||||||
|
}
|
||||||
|
String asCommitTime() {
|
||||||
|
return DateTimeFormat.forPattern('HH:mm:ss').withLocale(Locale.ENGLISH).print(commitDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
majorVersion=1
|
majorVersion=1
|
||||||
minorVersion=3
|
minorVersion=3
|
||||||
specialVersion=
|
maintenanceVersion=0
|
||||||
|
@ -171,20 +171,26 @@ task generateAppVersion {
|
|||||||
def tplFile = project.file('version/appversion.vm')
|
def tplFile = project.file('version/appversion.vm')
|
||||||
def renderedFile = project.file('version/appversion.h')
|
def renderedFile = project.file('version/appversion.h')
|
||||||
|
|
||||||
|
// check to up-to-date
|
||||||
inputs.file tplFile
|
inputs.file tplFile
|
||||||
inputs.file project.file('gradle.properties')
|
inputs.file project.file('gradle.properties')
|
||||||
outputs.file renderedFile
|
outputs.file renderedFile
|
||||||
inputs.property('version', verInfo.asMavenVersion())
|
|
||||||
inputs.property('lastCommitDate', verInfo.lastCommitDate.toString())
|
|
||||||
|
|
||||||
println "##teamcity[buildNumber '" + verInfo.asVersion() + "']";
|
// this will ensure that this task is redone when the versions change
|
||||||
|
inputs.property('version', rootProject.version)
|
||||||
|
inputs.property('commitDate', verInfo.asCommitDate())
|
||||||
|
|
||||||
|
println "##teamcity[buildNumber '" + verInfo.asMavenVersion(false) + "']";
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
def content = VelocityUtils.renderTemplate(tplFile, verInfo)
|
def templateCtx = [
|
||||||
|
verInfo: verInfo
|
||||||
|
]
|
||||||
|
|
||||||
|
def content = VelocityUtils.renderTemplate(tplFile, templateCtx)
|
||||||
renderedFile.delete()
|
renderedFile.delete()
|
||||||
renderedFile.write(content, 'utf-8')
|
renderedFile.write(content, 'utf-8')
|
||||||
|
|
||||||
println 'The current Metamod version is ' + verInfo.asVersion().toString() + ', maven version is ' + verInfo.asMavenVersion().toString() + ', commit id: ' + verInfo.commitID.toString() + ', commit author: ' + verInfo.authorCommit.toString() + ', url: (' + verInfo.urlCommits.toString() + ')';
|
println 'The current Metamod maven version is ' + rootProject.version + ', url: (' + verInfo.commitURL + '' + verInfo.commitSHA + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,24 @@ set srcdir=%~1
|
|||||||
set repodir=%~2
|
set repodir=%~2
|
||||||
|
|
||||||
set old_version=
|
set old_version=
|
||||||
set old_specialbuild=""
|
|
||||||
set version_revision=0
|
|
||||||
set version_specialbuild=
|
|
||||||
set version_id_commit=
|
|
||||||
set version_author_commit=
|
|
||||||
set version_pdate_1=%date:~-4%-%date:~3,2%-%date:~0,2%
|
|
||||||
set version_pdate=%version_pdate_1%%time:~0,2%:%time:~3,2%:%time:~6,2%
|
|
||||||
set version_pdate_2=%time:~0,2%-%time:~3,2%-%time:~6,2%
|
|
||||||
set version_pdate_2=%version_pdate_2: =%
|
|
||||||
set version_date=%version_pdate_1%__%version_pdate_2%
|
|
||||||
set version_major=0
|
set version_major=0
|
||||||
set version_minor=0
|
set version_minor=0
|
||||||
set version_specialversion=
|
set version_modifed=
|
||||||
set url_commit=
|
|
||||||
|
set commitSHA=
|
||||||
|
set commitURL=
|
||||||
|
set commitCount=0
|
||||||
|
set branch_name=master
|
||||||
|
|
||||||
|
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
|
||||||
|
set "YYYY=%dt:~0,4%"
|
||||||
|
set "MM=%dt:~4,2%"
|
||||||
|
set "DD=%dt:~6,2%"
|
||||||
|
set "hour=%dt:~8,2%"
|
||||||
|
set "min=%dt:~10,2%"
|
||||||
|
set "sec=%dt:~12,2%"
|
||||||
|
|
||||||
|
for /f "tokens=%MM%" %%I in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set "month=%%I"
|
||||||
|
|
||||||
::
|
::
|
||||||
:: Check for git.exe presence
|
:: Check for git.exe presence
|
||||||
@ -35,8 +39,11 @@ set errlvl="%ERRORLEVEL%"
|
|||||||
IF EXIST "%srcdir%\appversion.h" (
|
IF EXIST "%srcdir%\appversion.h" (
|
||||||
FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do (
|
FOR /F "usebackq tokens=1,2,3" %%i in ("%srcdir%\appversion.h") do (
|
||||||
IF %%i==#define (
|
IF %%i==#define (
|
||||||
IF %%j==APP_VERSION_C set old_version=%%k
|
IF %%j==APP_VERSION (
|
||||||
IF %%j==APP_VERSION_SPECIALBUILD set old_specialbuild=%%k
|
:: Remove quotes
|
||||||
|
set v=%%k
|
||||||
|
set old_version=!v:"=!
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -46,7 +53,7 @@ IF %errlvl% == "1" (
|
|||||||
|
|
||||||
:: if we haven't appversion.h, we need to create it
|
:: if we haven't appversion.h, we need to create it
|
||||||
IF NOT "%old_version%" == "" (
|
IF NOT "%old_version%" == "" (
|
||||||
set version_revision=0
|
set commitCount=0
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,7 +65,6 @@ IF EXIST "%srcdir%\version.h" (
|
|||||||
IF %%i==#define (
|
IF %%i==#define (
|
||||||
IF %%j==VERSION_MAJOR set version_major=%%k
|
IF %%j==VERSION_MAJOR set version_major=%%k
|
||||||
IF %%j==VERSION_MINOR set version_minor=%%k
|
IF %%j==VERSION_MINOR set version_minor=%%k
|
||||||
IF %%j==VERSION_SPECIALVERSION set version_specialversion=%%k
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) ELSE (
|
) ELSE (
|
||||||
@ -66,7 +72,6 @@ IF EXIST "%srcdir%\version.h" (
|
|||||||
IF NOT [%%j] == [] (
|
IF NOT [%%j] == [] (
|
||||||
IF %%i==majorVersion set version_major=%%j
|
IF %%i==majorVersion set version_major=%%j
|
||||||
IF %%i==minorVersion set version_minor=%%j
|
IF %%i==minorVersion set version_minor=%%j
|
||||||
IF %%i==specialVersion set version_specialversion=%%j
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -75,79 +80,69 @@ IF EXIST "%srcdir%\version.h" (
|
|||||||
:: Read revision and release date from it
|
:: Read revision and release date from it
|
||||||
::
|
::
|
||||||
IF NOT %errlvl% == "1" (
|
IF NOT %errlvl% == "1" (
|
||||||
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --all | wc -l"') DO (
|
:: Get current branch
|
||||||
|
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO (
|
||||||
|
set branch_name=%%i
|
||||||
|
)
|
||||||
|
|
||||||
|
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-list --count !branch_name!"') DO (
|
||||||
IF NOT [%%i] == [] (
|
IF NOT [%%i] == [] (
|
||||||
set version_revision=%%i
|
set /a commitCount=%%i
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
::
|
|
||||||
:: Now form full version string like 1.0.0.1
|
|
||||||
::
|
|
||||||
|
|
||||||
set new_version=%version_major%,%version_minor%,0,%version_revision%
|
|
||||||
|
|
||||||
::
|
::
|
||||||
:: Get remote url repository
|
:: Get remote url repository
|
||||||
::
|
::
|
||||||
IF NOT %errlvl% == "1" (
|
IF NOT %errlvl% == "1" (
|
||||||
|
|
||||||
set branch_name=master
|
|
||||||
set branch_remote=origin
|
set branch_remote=origin
|
||||||
:: Get current branch
|
|
||||||
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --abbrev-ref HEAD"') DO (
|
|
||||||
set branch_name=%%i
|
|
||||||
)
|
|
||||||
:: Get remote name by current branch
|
:: Get remote name by current branch
|
||||||
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." config branch.!branch_name!.remote"') DO (
|
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." config branch.!branch_name!.remote"') DO (
|
||||||
set branch_remote=%%i
|
set branch_remote=%%i
|
||||||
)
|
)
|
||||||
:: Get remote url
|
:: Get remote url
|
||||||
FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
|
FOR /F "tokens=2 delims=@" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
|
||||||
set url_commit=%%i
|
set commitURL=%%i
|
||||||
)
|
|
||||||
:: Get author last no-merge commit
|
|
||||||
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." log -1 --no-merges --pretty=format:%%an"') DO (
|
|
||||||
set version_author_commit=%%i
|
|
||||||
)
|
)
|
||||||
:: Get commit id
|
:: Get commit id
|
||||||
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO (
|
FOR /F "tokens=*" %%i IN ('"git -C "%repodir%\." rev-parse --verify HEAD"') DO (
|
||||||
set var=%%i
|
set shafull=%%i
|
||||||
set version_id_commit=!var:~0,+7!
|
set commitSHA=!shafull:~0,+7!
|
||||||
)
|
)
|
||||||
|
|
||||||
IF [!url_commit!] == [] (
|
IF [!commitURL!] == [] (
|
||||||
|
|
||||||
FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
|
FOR /F "tokens=1" %%i IN ('"git -C "%repodir%\." config remote.!branch_remote!.url"') DO (
|
||||||
set url_commit=%%i
|
set commitURL=%%i
|
||||||
)
|
)
|
||||||
|
|
||||||
:: strip .git
|
:: strip .git
|
||||||
if "x!url_commit:~-4!"=="x.git" (
|
if "x!commitURL:~-4!"=="x.git" (
|
||||||
set url_commit=!url_commit:~0,-4!
|
set commitURL=!commitURL:~0,-4!
|
||||||
)
|
)
|
||||||
|
|
||||||
:: append extra string
|
:: append extra string
|
||||||
If NOT "%url_commit%"=="%url_commit:bitbucket.org=%" (
|
If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" (
|
||||||
set url_commit=!url_commit!/commits/
|
set commitURL=!commitURL!/commits/
|
||||||
) ELSE (
|
) ELSE (
|
||||||
set url_commit=!url_commit!/commit/
|
set commitURL=!commitURL!/commit/
|
||||||
)
|
)
|
||||||
|
|
||||||
) ELSE (
|
) ELSE (
|
||||||
:: strip .git
|
:: strip .git
|
||||||
if "x!url_commit:~-4!"=="x.git" (
|
if "x!commitURL:~-4!"=="x.git" (
|
||||||
set url_commit=!url_commit:~0,-4!
|
set commitURL=!commitURL:~0,-4!
|
||||||
)
|
)
|
||||||
:: replace : to /
|
:: replace : to /
|
||||||
set url_commit=!url_commit::=/!
|
set commitURL=!commitURL::=/!
|
||||||
|
|
||||||
:: append extra string
|
:: append extra string
|
||||||
If NOT "%url_commit%"=="%url_commit:bitbucket.org=%" (
|
If NOT "!commitURL!"=="!commitURL:bitbucket.org=!" (
|
||||||
set url_commit=https://!url_commit!/commits/
|
set commitURL=https://!commitURL!/commits/
|
||||||
) ELSE (
|
) ELSE (
|
||||||
set url_commit=https://!url_commit!/commit/
|
set commitURL=https://!commitURL!/commit/
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -163,25 +158,30 @@ IF NOT %errlvl% == "1" (
|
|||||||
)
|
)
|
||||||
|
|
||||||
IF [%localChanged%]==[1] (
|
IF [%localChanged%]==[1] (
|
||||||
IF NOT [%version_specialversion%] == [] (
|
set version_modifed=+m
|
||||||
set version_specialbuild=%version_specialversion%
|
|
||||||
) ELSE (
|
|
||||||
set version_specialbuild=m
|
|
||||||
)
|
|
||||||
) ELSE (
|
|
||||||
set version_specialbuild=
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
::
|
||||||
|
:: Now form full version string like 1.0.0.1
|
||||||
|
::
|
||||||
|
|
||||||
|
set new_version=%version_major%.%version_minor%.%commitCount%%version_modifed%
|
||||||
|
|
||||||
::
|
::
|
||||||
:: Update appversion.h if version has changed or modifications/mixed revisions detected
|
:: Update appversion.h if version has changed or modifications/mixed revisions detected
|
||||||
::
|
::
|
||||||
IF NOT "%new_version%"=="%old_version%" goto _update
|
IF NOT "%new_version%"=="%old_version%" (
|
||||||
IF NOT "%version_specialbuild%"==%old_specialbuild% goto _update
|
goto _update
|
||||||
|
)
|
||||||
|
|
||||||
goto _exit
|
goto _exit
|
||||||
|
|
||||||
:_update
|
:_update
|
||||||
echo Updating appversion.h, new version is "%new_version%", the old one was "%old_version%"
|
|
||||||
echo new special build is "%version_specialbuild%", the old one was %old_specialbuild%
|
::
|
||||||
|
:: Write appversion.h
|
||||||
|
::
|
||||||
|
echo Updating appversion.h, new version is "%new_version%", the old one was %old_version%
|
||||||
|
|
||||||
echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h"
|
echo #ifndef __APPVERSION_H__>"%srcdir%\appversion.h"
|
||||||
echo #define __APPVERSION_H__>>"%srcdir%\appversion.h"
|
echo #define __APPVERSION_H__>>"%srcdir%\appversion.h"
|
||||||
@ -192,40 +192,19 @@ echo // Don't edit it.>>"%srcdir%\appversion.h"
|
|||||||
echo // >>"%srcdir%\appversion.h"
|
echo // >>"%srcdir%\appversion.h"
|
||||||
echo.>>"%srcdir%\appversion.h"
|
echo.>>"%srcdir%\appversion.h"
|
||||||
echo // Version defines>>"%srcdir%\appversion.h"
|
echo // Version defines>>"%srcdir%\appversion.h"
|
||||||
|
echo #define APP_VERSION "%new_version%">>"%srcdir%\appversion.h"
|
||||||
|
|
||||||
IF "%version_specialversion%" == "" (
|
>>"%srcdir%\appversion.h" echo #define APP_VERSION_C %version_major%,%version_minor%,%commitCount%
|
||||||
echo #define APP_VERSION_D %version_major%.%version_minor%.%version_revision% >>"%srcdir%\appversion.h"
|
echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%commitCount%">>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%version_revision%">>"%srcdir%\appversion.h"
|
echo #define APP_VERSION_FLAGS 0x0L>>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_STRD_RC "%version_major%.%version_minor%.%version_revision%">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_C %version_major%,%version_minor%,0,%version_revision% >>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_STRCS "%version_major%,%version_minor%,0,%version_revision%">>"%srcdir%\appversion.h"
|
|
||||||
) ELSE (
|
|
||||||
echo #define APP_VERSION_D %version_major%.%version_minor%.%version_maintenance%.%version_revision% >>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_STRD "%version_major%.%version_minor%.%version_maintenance%.%version_revision%">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_STRD_RC "%version_major%.%version_minor%.%version_maintenance%.%version_revision%">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_C %version_major%,%version_minor%,%version_maintenance%,%version_revision% >>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_STRCS "%version_major%,%version_minor%,%version_maintenance%,%version_revision%">>"%srcdir%\appversion.h"
|
|
||||||
)
|
|
||||||
|
|
||||||
echo.>>"%srcdir%\appversion.h"
|
echo.>>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_DATE %version_date%>>"%srcdir%\appversion.h"
|
echo #define APP_COMMIT_DATE "%YYYY%-%DD%-%MM%">>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_DATE_STR "%version_date%">>"%srcdir%\appversion.h"
|
echo #define APP_COMMIT_TIME "%hour%:%min%:%sec%">>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_PDATE_STR "%version_pdate%">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION_YMD_STR "%version_pdate_1%">>"%srcdir%\appversion.h"
|
|
||||||
echo.>>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_COMMIT_AUTHOR "(%version_author_commit%)">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_COMMIT_ID "%version_id_commit%">>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_COMMITS_URL "%url_commit%">>"%srcdir%\appversion.h"
|
|
||||||
echo.>>"%srcdir%\appversion.h"
|
|
||||||
|
|
||||||
IF NOT "%version_specialbuild%" == "" (
|
echo.>>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_FLAGS VS_FF_SPECIALBUILD>>"%srcdir%\appversion.h"
|
echo #define APP_COMMIT_SHA "%commitSHA%">>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION_SPECIALBUILD "%version_specialbuild%">>"%srcdir%\appversion.h"
|
echo #define APP_COMMIT_URL "%commitURL%">>"%srcdir%\appversion.h"
|
||||||
echo #define APP_VERSION APP_VERSION_STRD "" APP_VERSION_SPECIALBUILD>>"%srcdir%\appversion.h"
|
|
||||||
) ELSE (
|
|
||||||
echo #define APP_VERSION_FLAGS 0x0L>>"%srcdir%\appversion.h"
|
|
||||||
echo #define APP_VERSION APP_VERSION_STRD>>"%srcdir%\appversion.h"
|
|
||||||
)
|
|
||||||
echo.>>"%srcdir%\appversion.h"
|
echo.>>"%srcdir%\appversion.h"
|
||||||
|
|
||||||
echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h"
|
echo #endif //__APPVERSION_H__>>"%srcdir%\appversion.h"
|
||||||
|
@ -72,14 +72,14 @@ BEGIN
|
|||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "041904b0"
|
BLOCK "041904b0"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", ""
|
VALUE "Comments", "Metamod-r is fully reworked fork of original Metamod-p by Jussi Kivilinna. Metamod allows running multiple mod-like plugin DLLs, to add functionality or change the behavior of the running HLDS game mod."
|
||||||
VALUE "FileDescription", "Metamod Counter-Strike GameMod DLL"
|
VALUE "FileDescription", "Metamod-r Half-Life MOD DLL"
|
||||||
VALUE "FileVersion", APP_VERSION_STRD_RC
|
VALUE "FileVersion", APP_VERSION_STRD
|
||||||
VALUE "InternalName", "Metamod"
|
VALUE "InternalName", "Metamod-r"
|
||||||
VALUE "LegalCopyright", ""
|
VALUE "LegalCopyright", "Copyright (c) 2017"
|
||||||
VALUE "OriginalFilename", "metamod_mm.dll"
|
VALUE "OriginalFilename", "metamod_mm.dll"
|
||||||
VALUE "ProductName", "Metamod"
|
VALUE "ProductName", "Metamod"
|
||||||
VALUE "ProductVersion", APP_VERSION_STRD_RC
|
VALUE "ProductVersion", APP_VERSION_STRD
|
||||||
#if APP_VERSION_FLAGS != 0x0L
|
#if APP_VERSION_FLAGS != 0x0L
|
||||||
VALUE "SpecialBuild", APP_VERSION_SPECIALBUILD
|
VALUE "SpecialBuild", APP_VERSION_SPECIALBUILD
|
||||||
#endif
|
#endif
|
||||||
@ -87,7 +87,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "Translation", 0x419, 1200
|
VALUE "Translation", 0x0, 1200
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
|
|
||||||
@ -105,4 +105,3 @@ END
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
#endif // not APSTUDIO_INVOKED
|
#endif // not APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ void cmd_meta_version()
|
|||||||
}
|
}
|
||||||
|
|
||||||
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
||||||
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
|
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ "");
|
||||||
META_CONS("Metamod-r from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
|
META_CONS("Metamod-r from: " APP_COMMIT_URL APP_COMMIT_SHA "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// "meta version" client command.
|
// "meta version" client command.
|
||||||
@ -128,8 +128,8 @@ void client_meta_version(edict_t *pEntity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
||||||
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
|
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ "");
|
||||||
META_CONS("Metamod-r from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
|
META_CONS("Metamod-r from: " APP_COMMIT_URL APP_COMMIT_SHA "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// "meta gpl" console command.
|
// "meta gpl" console command.
|
||||||
|
@ -44,15 +44,15 @@ void metamod_startup()
|
|||||||
Q_snprintf(execFile, sizeof execFile, "%s/%s", g_config->directory(), EXEC_CFG);
|
Q_snprintf(execFile, sizeof execFile, "%s/%s", g_config->directory(), EXEC_CFG);
|
||||||
|
|
||||||
META_CONS(" ");
|
META_CONS(" ");
|
||||||
META_CONS(" Metamod-r version %s Copyright (c) 2016-2017 ReHlds Team (rebuild of original Metamod by Will Day)", APP_VERSION_STRD);
|
META_CONS(" Metamod-r version %s Copyright (c) 2016-2017 ReHLDS Team (rebuild of original Metamod by Will Day and Jussi Kivilinna)", APP_VERSION_STRD);
|
||||||
META_CONS(" Metamod-r comes with ABSOLUTELY NO WARRANTY; for details type `meta gpl'.");
|
META_CONS(" Metamod-r comes with ABSOLUTELY NO WARRANTY; for details type `meta gpl'.");
|
||||||
META_CONS(" This is free software, and you are welcome to redistribute it");
|
META_CONS(" This is free software, and you are welcome to redistribute it");
|
||||||
META_CONS(" under certain conditions; type `meta gpl' for details.");
|
META_CONS(" under certain conditions; type `meta gpl' for details.");
|
||||||
META_CONS(" ");
|
META_CONS(" ");
|
||||||
|
|
||||||
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
META_CONS("Metamod-r v%s, API (%s)", APP_VERSION_STRD, META_INTERFACE_VERSION);
|
||||||
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ " (" APP_VERSION_STRD ")");
|
META_CONS("Metamod-r build: " __TIME__ " " __DATE__ "");
|
||||||
META_CONS("Metamod-r from: " APP_COMMITS_URL APP_COMMIT_ID " " APP_COMMIT_AUTHOR "");
|
META_CONS("Metamod-r from: " APP_COMMIT_URL APP_COMMIT_SHA "");
|
||||||
|
|
||||||
// Get gamedir, very early on, because it seems we need it all over the
|
// Get gamedir, very early on, because it seems we need it all over the
|
||||||
// place here at the start.
|
// place here at the start.
|
||||||
|
@ -7,25 +7,15 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
// Version defines
|
// Version defines
|
||||||
\#define VERSION_MAJOR ${verInfo.majorVersion}
|
\#define APP_VERSION "$verInfo.asMavenVersion()"
|
||||||
\#define VERSION_MINOR ${verInfo.minorVersion}
|
\#define APP_VERSION_C $verInfo.asMavenVersion(false, ",")
|
||||||
|
\#define APP_VERSION_STRD "$verInfo.asMavenVersion(false)"
|
||||||
|
\#define APP_VERSION_FLAGS 0x0L
|
||||||
|
|
||||||
\#define APP_COMMIT_AUTHOR "(${verInfo.authorCommit})"
|
\#define APP_COMMIT_DATE "$verInfo.asCommitDate("yyyy-MM-dd")"
|
||||||
\#define APP_COMMIT_ID "${verInfo.commitID}"
|
\#define APP_COMMIT_TIME "$verInfo.asCommitTime()"
|
||||||
\#define APP_COMMITS_URL "${verInfo.urlCommits}"
|
|
||||||
|
|
||||||
\#define APP_VERSION_D ${verInfo.format('.', '-', true)}
|
\#define APP_COMMIT_SHA "$verInfo.commitSHA"
|
||||||
\#define APP_VERSION_C ${verInfo.majorVersion},${verInfo.minorVersion},0,${verInfo.countCommit}
|
\#define APP_COMMIT_URL "$verInfo.commitURL"
|
||||||
|
|
||||||
\#define APP_VERSION_STRD "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}${formatSpecialVersion}"
|
|
||||||
\#define APP_VERSION_STRD_RC "${verInfo.majorVersion}.${verInfo.minorVersion}.${verInfo.countCommit}${formatSpecialVersion}"
|
|
||||||
|
|
||||||
\#define APP_VERSION_FLAGS ${appFlags}
|
|
||||||
\#define APP_VERSION_SPECIALBUILD "${verInfo.specialVersion}"
|
|
||||||
|
|
||||||
#set ( $commitYMD = $_DateTimeFormat.forPattern('yyyy-MM-dd').print($verInfo.lastCommitDate) )
|
|
||||||
|
|
||||||
\#define APP_VERSION_YMD_STR "${commitYMD}"
|
|
||||||
\#define APP_VERSION APP_VERSION_STRD
|
|
||||||
|
|
||||||
#endif //__APPVERSION_H__
|
#endif //__APPVERSION_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user