Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Oct 14, 2014
0 parents commit 9e46c68
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.bundle
*.so
*.o
*.a
mkmf.log
.idea/
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in apress-gems.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 bibendi

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Apress::Gems

Rake задачи для выпуска гема на gems.railsc.ru

## Installation

Add this line to your gemspec:

spec.add_development_dependency 'apress-gems'

Rewrite Rakefile like this:

require 'apress/gems/rake_tasks'

## Gem Releasing:

1. должен быть настроен git remote upstream и должны быть права на push
1. git checkout master
2. git pull upstream master
3. правим версию гема в файле VERSION в корне гема. (читаем правила версионирования http://semver.org/)
4. bundle exec rake release

## Contributing

1. Fork it ( https://github.com/abak-press/apress-gems/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'feature(scope): comment \n\n Closes NN-123'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative 'lib/apress/gems/rake_tasks'

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
25 changes: 25 additions & 0 deletions apress-gems.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'apress/gems/version'

Gem::Specification.new do |spec|
spec.name = 'apress-gems'
spec.version = Apress::Gems::VERSION
spec.authors = ['merkushin']
spec.email = ['[email protected]']
spec.summary = 'Набор rake задач дял выпуска гема на railsc.ru'
spec.description = 'Обязательно подключаемый гем для всех гемов apress-*'
spec.homepage = ''
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '>= 1.6'
spec.add_development_dependency 'rake'
spec.add_runtime_dependency 'changelogger', '>= 0.0.3'
spec.add_runtime_dependency 'multipart-post'
end
7 changes: 7 additions & 0 deletions lib/apress/gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "apress/gems/version"

module Apress
module Gems
# Your code goes here...
end
end
3 changes: 3 additions & 0 deletions lib/apress/gems/rake_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# coding: utf-8
# load everything from tasks/ directory
Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tasks', '*.{rb,rake}'))].each { |f| load(f) }
5 changes: 5 additions & 0 deletions lib/apress/gems/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Apress
module Gems
VERSION = "0.0.1"
end
end
96 changes: 96 additions & 0 deletions tasks/gem.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# coding: utf-8
desc 'Release gem (build and upload to gem repo)'
task :release => [
:load_gemspec,
:check_git,
'version:release',
:build,
:tag,
:push,
:upload
]

task :load_gemspec do
load_gemspec
end

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

spawn("gem build -V #{@spec_path}")
built_gem_path = Dir["#{@gemspec.name}-*.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 upstream master'
spawn 'git push --tags upstream'
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 = "#{@gemspec.name}-#{current_version}.gem"
upload_gem(uri.dup, tarball_name)
end

task :check_git do
`git rev-parse --abbrev-ref HEAD`.chomp.strip == 'master' || abort("Can be released only from `master` branch")
`git remove | grep upstream`.chomp.strip == 'upstream' || abort("Can be released only with `upstream` remote")
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
41 changes: 41 additions & 0 deletions tasks/support.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# coding: utf-8
# Helpers for root Rakefile

require 'pty'

# 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 load_gemspec
gemspecs = Dir[File.join(Dir.pwd, "{,*}.gemspec")]
raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1
@spec_path = gemspecs.first
@gemspec = Bundler.load_gemspec(@spec_path)
end

# get current version from VERSION file
def current_version
File.read(File.join(Dir.pwd, '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
34 changes: 34 additions & 0 deletions tasks/version.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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}"
end
spawn "git add VERSION"
# 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
spawn "bundle exec changelogger changelog '#{Dir.pwd}' --top_version='v#{current_version}' > CHANGELOG"
spawn "git add CHANGELOG"
end
end

0 comments on commit 9e46c68

Please sign in to comment.