Running the JGitFlow library from within Gradle

on Monday, 13 May 2013
I recently seen this blog post and thought it would be really cool if I could integrate git flow into my build scripts. Whats great about this is that because this is a java library it was extremely painless to integrate.

With a little effort this could easily be converted into a plugin for Gradle, but here's my example:


buildscript{
repositories{
mavenCentral()
}
dependencies{
classpath 'com.atlassian.jgitflow:jgit-flow-core:0.9'
}
}
import com.atlassian.jgitflow.core.*
import com.atlassian.jgitflow.core.exception.*
task initFlow << {
//your local working copy is now on the develop branch
JGitFlow flow = JGitFlow.getOrInit(new File("."))
}
task releaseStart << {
JGitFlow flow = JGitFlow.getOrInit(new File("."))
//try to start our release
try
{
flow.releaseStart("1.0").call()
}
catch (ReleaseBranchExistsException e)
{
//the release branch already exists, just check it out
try
{
flow.git().checkout().setName(flow.getReleaseBranchPrefix() + "1.0").call()
}
catch (JGitFlowGitAPIException e1)
{
logger.error("Something went wrong checking out the release branch")
}
}
catch (DirtyWorkingTreeException e)
{
logger.error("you have un-committed changes!")
}
catch (BranchOutOfDateException e)
{
logger.error("your local develop branch is behind the remote, please do a git pull")
}
//Note: your local working copy is now on release/1.0
}
task releaseFinish << {
JGitFlow flow = JGitFlow.getOrInit(new File("."))
//finish the release and push to the origin
try
{
flow.releaseFinish("1.0").setPush(true).call();
}
catch (DirtyWorkingTreeException e)
{
logger.error("you have un-committed changes!")
}
}
view raw jgitflow.gradle hosted with ❤ by GitHub
This is only a snippet, so not all of the library is shown, but it works very well as a proof of concept.

0 comments:

Post a Comment