Skip to content

Instantly share code, notes, and snippets.

@chtz
Last active March 4, 2018 21:03
Show Gist options
  • Save chtz/f95f70ad917097a29da61c05d55e59a8 to your computer and use it in GitHub Desktop.
Save chtz/f95f70ad917097a29da61c05d55e59a8 to your computer and use it in GitHub Desktop.
require 'nokogiri'
def open_pom
File.open("pom.xml") { |f| Nokogiri::XML(f) }
end
def save_pom(pom)
File.open('pom.xml','w') {|f| pom.write_xml_to f}
end
def get_version(pom)
pom.xpath("/x:project/x:version", 'x' => 'http://maven.apache.org/POM/4.0.0').first.content
end
def set_version(pom, version)
pom.xpath("/x:project/x:version", 'x' => 'http://maven.apache.org/POM/4.0.0').first.content = version
end
def unsnapshot(version)
version =~ /(\d+\.\d+\.\d+)/
$1
end
def resnapshot(version)
version =~ /(\d+\.\d+)\.(\d+)/
$1 + "." + ($2.to_i + 1).to_s + "-SNAPSHOT"
end
SVN_PATH="svn.exe"
def calc_svn_base
`#{SVN_PATH} info`.each_line do |line|
line = line.strip
if line =~ /URL\: (.+)\/trunk/
return $1
end
end
fail "Failed to calculate svn_base"
end
def svn_commit(svn_base)
pom_version = get_version(open_pom)
`#{SVN_PATH} commit -m 'automated'`
end
def svn_create_tag(svn_base, pom_version)
`#{SVN_PATH} cp #{svn_base}/trunk #{svn_base}/tags/#{pom_version} -m 'automated'`
end
def svn_create_branch(svn_base, pom_version)
`#{SVN_PATH} cp #{svn_base}/trunk #{svn_base}/branches/#{pom_version} -m 'automated'`
end
svn_base = calc_svn_base
pom = open_pom
version = get_version(pom)
version = unsnapshot(version)
set_version(pom, version)
save_pom(pom)
svn_commit(svn_base)
svn_create_tag(svn_base, version)
svn_create_branch(svn_base, version)
version = resnapshot(version)
set_version(pom, version)
save_pom(pom)
svn_commit(svn_base)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment