From 9e46c68859072d3a324f74c7cbb409a76df99996 Mon Sep 17 00:00:00 2001 From: bibendi Date: Tue, 14 Oct 2014 12:35:17 +0600 Subject: [PATCH] first --- .gitignore | 23 +++++++++ Gemfile | 4 ++ LICENSE.txt | 22 ++++++++ README.md | 29 +++++++++++ Rakefile | 2 + VERSION | 1 + apress-gems.gemspec | 25 +++++++++ lib/apress/gems.rb | 7 +++ lib/apress/gems/rake_tasks.rb | 3 ++ lib/apress/gems/version.rb | 5 ++ tasks/gem.rake | 96 +++++++++++++++++++++++++++++++++++ tasks/support.rb | 41 +++++++++++++++ tasks/version.rake | 34 +++++++++++++ 13 files changed, 292 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100644 VERSION create mode 100644 apress-gems.gemspec create mode 100644 lib/apress/gems.rb create mode 100644 lib/apress/gems/rake_tasks.rb create mode 100644 lib/apress/gems/version.rb create mode 100644 tasks/gem.rake create mode 100644 tasks/support.rb create mode 100644 tasks/version.rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a69cd7 --- /dev/null +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e23dd21 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in apress-gems.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..0143e59 --- /dev/null +++ b/LICENSE.txt @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc11f4d --- /dev/null +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..c536101 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require_relative 'lib/apress/gems/rake_tasks' + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/apress-gems.gemspec b/apress-gems.gemspec new file mode 100644 index 0000000..d306ce4 --- /dev/null +++ b/apress-gems.gemspec @@ -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 = ['merkushin.m.s@gmail.com'] + 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 diff --git a/lib/apress/gems.rb b/lib/apress/gems.rb new file mode 100644 index 0000000..8e0e020 --- /dev/null +++ b/lib/apress/gems.rb @@ -0,0 +1,7 @@ +require "apress/gems/version" + +module Apress + module Gems + # Your code goes here... + end +end diff --git a/lib/apress/gems/rake_tasks.rb b/lib/apress/gems/rake_tasks.rb new file mode 100644 index 0000000..593020d --- /dev/null +++ b/lib/apress/gems/rake_tasks.rb @@ -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) } diff --git a/lib/apress/gems/version.rb b/lib/apress/gems/version.rb new file mode 100644 index 0000000..bac693f --- /dev/null +++ b/lib/apress/gems/version.rb @@ -0,0 +1,5 @@ +module Apress + module Gems + VERSION = "0.0.1" + end +end diff --git a/tasks/gem.rake b/tasks/gem.rake new file mode 100644 index 0000000..9c6317a --- /dev/null +++ b/tasks/gem.rake @@ -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 \ No newline at end of file diff --git a/tasks/support.rb b/tasks/support.rb new file mode 100644 index 0000000..bfe6681 --- /dev/null +++ b/tasks/support.rb @@ -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 \ No newline at end of file diff --git a/tasks/version.rake b/tasks/version.rake new file mode 100644 index 0000000..6446c98 --- /dev/null +++ b/tasks/version.rake @@ -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 \ No newline at end of file