Last active
August 29, 2015 14:21
-
-
Save tomquas/0dbdfba425603aefd478 to your computer and use it in GitHub Desktop.
rake task to generate version.rb file from git metadata
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
require 'fileutils' | |
require 'bundler/gem_tasks' | |
require 'git' | |
def gen_version_file(version, build, filename) | |
data = [] | |
data << "# --- GENERATED BY RAKE. DON'T MODIFY" | |
data << 'module Patugo::Search' | |
data << " VERSION = '#{version}'" | |
data << " BUILD = '#{build}'" | |
data << "end" | |
data << "" | |
File.open filename, 'w' do |f| | |
f.syswrite data.join("\n") | |
f.close | |
end | |
end | |
namespace :patugo do | |
VERSION_FILE = 'lib/patugo/version.rb'.freeze | |
desc 'generate version.rb from git metadata' | |
task :version_rb do | |
g = Git.open '.' | |
# get version and patch level from git tag | |
version = g.describe.gsub(/^v(.+)-(.+)-.*/, '\1.\2') | |
build = g.object('HEAD').sha[0, 7] | |
gen_version_file version, build, VERSION_FILE | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment