Skip to content

Commit

Permalink
add gem release tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Apr 29, 2014
1 parent 4860eab commit f17c606
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 8 deletions.
Empty file added CHANGELOG
Empty file.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'http://apress:montalcino@gems.railsc.ru'
source 'https://rubygems.org'

# Specify your gem's dependencies in ts_customizer.gemspec
Expand Down
9 changes: 5 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require "rubygems"
require "bundler/setup"
require "rspec/core/rake_task"
require "bundler/gem_tasks"
# coding: utf-8
# load everything from tasks/ directory
Dir[File.join(File.dirname(__FILE__), 'tasks', '*.{rb,rake}')].each { |f| load(f) }

require 'rspec/core/rake_task'

# setup `spec` task
RSpec::Core::RakeTask.new(:spec)
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.4.0
16 changes: 12 additions & 4 deletions lib/sphinx/integration/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ def configure
#
# Returns nothing
def remove_indexes
puts "Removing indexes:"

if config.remote?
nodes.remove_indexes
else
FileUtils.rm(Dir.glob("#{config.searchd_file_path}/*.*"))
files = Dir.glob("#{config.searchd_file_path}/*.*")
puts files.join("\n")
FileUtils.rm(files)
end
end

Expand All @@ -103,9 +107,13 @@ def remove_indexes
# Returns nothing
def remove_binlog
if (binlog_path = config.configuration.searchd.binlog_path).present?
puts "Removing binlog:"

if config.remote?
nodes.remove_binlog
else
files = Dir.glob("#{config.searchd_file_path}/*.*")
puts files.join("\n")
FileUtils.rm(Dir.glob("#{binlog_path}/*.*"))
end
end
Expand Down Expand Up @@ -144,7 +152,7 @@ def copy_config
# online - boolean (default: true) означает, что в момент индексации все апдейты будут писаться в дельту
def index(online = true)
raise 'Мастер ноду нельзя индексировать' if node.master?

puts "Start indexing"
indexer_args = []
indexer_args << '--rotate' if online

Expand Down Expand Up @@ -327,11 +335,11 @@ def config
end

def local_searchd(*params)
Rye.shell :searchd, "--config #{config.config_file(:single)}", *params
puts Rye.shell(:searchd, "--config #{config.config_file(:single)}", *params).inspect
end

def local_indexer(*params)
Rye.shell :indexer, "--config #{config.config_file(:single)} --all", *params
puts Rye.shell(:indexer, "--config #{config.config_file(:single)} --all", *params).inspect
end

# Установить блокировку на индексацию
Expand Down
6 changes: 6 additions & 0 deletions sphinx-integration.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'combustion'
gem.add_development_dependency 'mock_redis'
gem.add_development_dependency 'database_cleaner'

# automatic changelog builder
gem.add_development_dependency 'changelogger'

# a tool for uploading files to private gem repo
gem.add_development_dependency 'multipart-post'
end
92 changes: 92 additions & 0 deletions tasks/gem.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# coding: utf-8

desc 'Release gem (build and upload to gem repo)'
task :release => [
:ensure_master,
'version:release',
:build,
:tag,
:push,
:upload
]

desc 'Build project into pkg directory'
task :build do
FileUtils.mkdir_p('pkg')

gemspec = "#{project}.gemspec"
spawn("gem build -V #{gemspec}")
built_gem_path = Dir["#{project}-*.gem"].sort_by{|f| File.mtime(f)}.last

FileUtils.mv(built_gem_path, 'pkg')
end

desc 'Mark project as stable with version tag'
task :tag do
tag_name = "v#{current_version}"

spawn("git tag -a -m \"Version #{current_version}\" #{tag_name}")
puts "Tag #{tag_name} created"
end

task :push do
spawn 'git push'
spawn 'git push --tags'
end

# upload built tarballs to repo
task :upload do
require 'uri'
require 'net/http/post/multipart'

repo = gems_sources.grep(/railsc/).first
uri = URI.parse(repo)

tarball_name = "#{project}-#{current_version}.gem"
upload_gem(uri.dup, tarball_name)
end

task :ensure_master do
`git rev-parse --abbrev-ref HEAD`.chomp.strip == 'master' || abort("Can be released only from `master` branch")
end

def upload_gem(repo_uri, tarball_name)
require 'net/http/post/multipart'
repo_uri.path = '/upload'

tarball_path = File.join('pkg', tarball_name)

File.open(tarball_path) do |gem|
req = Net::HTTP::Post::Multipart.new repo_uri.path,
"file" => UploadIO.new(gem, "application/x-tar", tarball_name)

req.basic_auth(repo_uri.user, repo_uri.password) if repo_uri.user

res = Net::HTTP.start(repo_uri.host, repo_uri.port) do |http|
http.request(req)
end

if [200, 302].include?(res.code.to_i)
puts "#{tarball_name} uploaded successfully"
else
$stderr.puts "Cannot upload #{tarball_name}. Response status: #{res.code}"
exit(1)
end
end # File.open
end

task :clean do
FileUtils.rm_f 'Gemfile.lock'
end

def gems_sources
Bundler.
setup. # get bundler runtime
specs. # for each spec
map(&:source). # get its sources
select { |v| Bundler::Source::Rubygems === v }. # fetch only rubygems-like repos
map(&:remotes). # get all remotes
flatten.
uniq.
map(&:to_s)
end
40 changes: 40 additions & 0 deletions tasks/support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf-8
# Helpers for root Rakefile

require 'pty'

ROOT = File.expand_path(File.join('..', '..'), __FILE__)

# run +cmd+ in subprocess, redirect its stdout to parent's stdout
def spawn(cmd)
puts ">> #{cmd}"

cmd += ' 2>&1'
PTY.spawn cmd do |r, w, pid|
begin
r.sync
r.each_char { |chr| STDOUT.write(chr) }
rescue Errno::EIO => e
# simply ignoring this
ensure
::Process.wait pid
end
end
abort "#{cmd} failed" unless $? && $?.exitstatus == 0
end

def project
'apress_search_terms'
end

# get current version from VERSION file
def current_version
File.read(File.join(ROOT, 'VERSION')).strip.chomp
end

# get released version from git
def released_version
/\Av([\d\.]+)\z/ === `git describe --tags --abbrev=0 2>/dev/null || echo 'v0.0.0'`.chomp.strip

$1
end
36 changes: 36 additions & 0 deletions tasks/version.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding: utf-8
namespace :version do
task :current do
puts current_version
end

desc 'Write a version from VERSION file to project lib/**/version.rb'
task :update do
Dir['lib/**/version.rb'].each do |file|
contents = File.read(file)
contents.gsub!(/VERSION\s*=\s*(['"])(.*?)\1/m, "VERSION = '#{current_version}'")
File.write(file, contents)
end
end

desc 'Put version files to repo'
task :commit do
Dir['lib/**/version.rb'].each do |file|
spawn "git add #{file}"
spawn "git add VERSION"
end
# git diff --exit-code returns 0 if nothing was changed and 1 otherwise
spawn "git diff --cached --exit-code > /dev/null || git commit -m \"Release #{current_version}\" || echo -n"
end

desc 'Release new version'
task :release => [:changelog, :update, :commit]

desc 'Generate CHANGELOG file'
task :changelog do
changelog = File.join(ROOT, 'CHANGELOG')

spawn "changelogger '#{ROOT}' --top_version='v#{current_version}' > '#{changelog}'"
spawn "git add '#{changelog}'"
end
end

0 comments on commit f17c606

Please sign in to comment.