-
-
Save michealbenedict/1164300 to your computer and use it in GitHub Desktop.
Ant target for autogenerating changelog based on Git tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Ant target for autogenerating a changelog based on Git tags | |
Workflow: | |
1. Do all of your checkins for a given version. | |
2. When you're ready to officially create a new version, tag it using git tag, such as "git tag v0.3.0". | |
3. If you don't already have a file named CHANGELOG in the root directory, make one. | |
4. Run "ant changelog.update" | |
Assumptions: | |
1. You only use tags for version numbers, that's it. | |
2. You have a file named CHANGELOG that you want to auto-update. | |
3. You want today's date stamped in the CHANGELOG file/ | |
4. Your project name is "project". That's dumb, it should be something better. | |
--> | |
<target name="changelog.update"> | |
<exec executable="git" failonerror="true" outputproperty="git.tag"> | |
<arg line="tag"/> | |
</exec> | |
<script language="javascript"><![CDATA[ | |
//get the two most recent tags to get the diff | |
var tags = project.getProperty("git.tag").replace("\r", "").split("\n"), | |
curTag = tags[tags.length-1], | |
priorTag = tags[tags.length-2]; | |
project.setProperty("project.current", curTag); | |
project.setProperty("git.log.range", priorTag + ".." + curTag); | |
]]></script> | |
<!-- git log -pretty=format:'* %s (%an)' v0.4.0..v0.5.0--> | |
<exec executable="git" failonerror="true" outputproperty="git.changelog"> | |
<arg line="log --pretty=format:'* %s (%an)' ${git.log.range}"/> | |
</exec> | |
<concat destfile="CHANGELOG.tmp" fixlastline="true"> | |
<header trimleading="yes">${SIMPLE_DATE} - v${project.current} | |
${git.changelog} | |
</header> | |
<fileset dir="." includes="CHANGELOG" /> | |
</concat> | |
<delete file="CHANGELOG"/> | |
<move file="CHANGELOG.tmp" tofile="CHANGELOG"/> | |
</target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment