如何查找最新的git从Ant构建脚本提交哈希 [英] How to lookup the latest git commit hash from an ant build script
问题描述
如何查找最新的git从Ant构建脚本提交哈希?
How can I lookup the latest git commit hash from an ant build script?
我目前正在对我存放在GitHub上一个新的开源项目。我想延长我现有的Ant构建文件,让我创建编号生成。我想象,我会的东西,如启动打造蚁buildnum -Dnum = 12。
I am currently working on a new open source project which I store on github. I would like to extend my existing ANT build file to allow me to create numbered builds. I am imagining that I would launch the build with something like "ant buildnum -Dnum=12".
我想产生的罐子有它的信息两个关键位的清单文件:
I would like the resulting jar to have two crucial bits of information in it's manifest file:
- build.number = 12
- build.gitcommit =
我知道如何创建build.number线。不过,我不能确定最好的蚂蚁水暖查找最新的git的承诺哈希这是我要填写的值。
I know how to create the build.number line. However, I am unsure of the best ant plumbing to lookup the latest git commit hash which is the value I want to fill in for .
推荐答案
我写了下面的蚂蚁目标在github上的项目。用法:
I wrote the following ant target for a project on github. Usage:
- 商店版本财产repository.version
- 工作
- 其他目标必须依赖于这个目标,如果他们需要Git版本
- 只有一个混帐命令被执行(--always)
如果没有安装的git或没有.git目录是present(后备)
<available file=".git" type="dir" property="git.present"/>
<target name="git.revision" description="Store git revision in ${repository.version}" if="git.present">
<exec executable="git" outputproperty="git.revision" failifexecutionfails="false" errorproperty="">
<arg value="describe"/>
<arg value="--tags"/>
<arg value="--always"/>
<arg value="HEAD"/>
</exec>
<condition property="repository.version" value="${git.revision}" else="unknown">
<and>
<isset property="git.revision"/>
<length string="${git.revision}" trim="yes" length="0" when="greater"/>
</and>
</condition>
</target>
据例如用于扩展标记 @ repository.version @
在模板文件:
<target name="index.html" depends="git.revision" description="build index.html from template">
<copy file="index.html.template" tofile="index.html" overwrite="yes">
<filterchain>
<replacetokens>
<token key="repository.version" value="${repository.version}" />
</replacetokens>
</filterchain>
</copy>
</target>
这篇关于如何查找最新的git从Ant构建脚本提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!