-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
193 additions
and
8 deletions.
There are no files selected for viewing
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
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
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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.4.0 |
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
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
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
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 |
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
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 |
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
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 |