Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created June 5, 2010 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nesquena/426498 to your computer and use it in GitHub Desktop.
Save nesquena/426498 to your computer and use it in GitHub Desktop.
Dead simple gem packaging gemspec and tasks
# -*- encoding: utf-8 -*-
require File.expand_path("path/to/version.rb", __FILE__)
Gem::Specification.new do |s|
s.name = %q{NAME}
s.rubyforge_project = %q{NAME}
s.authors = ["Joe", "Bob"]
s.email = %q{some@email.com}
s.summary = %q{A short summary here}
s.homepage = %q{http://github.com/some/path/to/site}
s.description = %q{A longer summary here}
# s.default_executable = %q{some_bin_file}
# s.executables = ["some_bin_file"]
s.required_rubygems_version = ">= 1.3.6"
s.version = SomeName.version
s.date = Time.now.strftime("%Y-%m-%d")
s.extra_rdoc_files = Dir["*.rdoc"]
s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile name.gemspec) + Dir.glob("{bin,lib,test}/**/*")
s.rdoc_options = ["--charset=UTF-8"]
s.require_path = 'lib'
# s.add_runtime_dependency(%q<bundler>, [">= 0.9.7"])
# s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
end
# coding:utf-8
require 'rubygems'
require 'rubygems/specification'
require 'rake'
def gemspec
@gemspec ||= begin
gem_name = File.basename(File.dirname(__FILE__))
file = File.expand_path("../#{gem_name}.gemspec", __FILE__)
eval(File.read(file), binding, file)
end
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
begin
require 'rake/gempackagetask'
rescue LoadError
task(:gem) { $stderr.puts '`gem install rake` to package gems' }
else
Rake::GemPackageTask.new(gemspec) do |pkg|
pkg.gem_spec = gemspec
end
task :gem => :gemspec
end
desc "Validates the gemspec"
task :gemspec do
gemspec.validate
end
desc "Displays the current version"
task :version do
puts "Current version: #{gemspec.version}"
end
desc "Installs the gem locally"
task :install => :package do
sh "gem install pkg/#{gemspec.name}-#{gemspec.version}"
end
desc "Release the gem"
task :release => :package do
sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
end
task :package => :gemspec
task :default => :test
# rake bump[X.X.X] && rake publish
require 'rake/clean'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rake/contrib/sshpublisher'
require 'fileutils'
require File.expand_path("path/to/version.rb", __FILE__)
begin
require 'sdoc'
rescue LoadError
puts "You need to install sdoc: gem install sdoc for generate correctly ours api docs."
end
include FileUtils
ROOT = File.expand_path(File.dirname(__FILE__))
GEM_NAME = 'meta-name'
sub_gems = [
"foo",
"bar"
]
GEM_PATHS = sub_gems.freeze
def rake_command(command)
sh "#{Gem.ruby} -S rake #{command}", :verbose => true
end
%w(install gemspec package).each do |name|
desc "Run #{name} for all projects"
task name do
GEM_PATHS.each do |dir|
Dir.chdir(dir) { rake_command(name) }
end
end
end
desc "Clean pkg and other stuff"
task :clean do
GEM_PATHS.each do |dir|
Dir.chdir(dir) do
%w(tmp pkg coverage).each { |dir| FileUtils.rm_rf dir }
end
end
Dir["**/*.gem"].each { |gem| FileUtils.rm_rf gem }
end
desc "Clean pkg and other stuff"
task :uninstall do
sh "gem search --no-version meta_name | grep meta_name | xargs sudo gem uninstall -a"
end
desc "Displays the current version"
task :version do
puts "Current version: #{SomeName.version}"
end
desc "Commits all staged files"
task :commit, [:message] do |t, args|
system(%Q[git commit -a -m "#{args.message}"])
end
desc "Bumps the version number based on given version"
task :bump, [:version] do |t, args|
raise "Please specify version=x.x.x !" unless args.version
version_path = File.dirname(__FILE__) + '/padrino-core/lib/padrino-core/version.rb'
version_text = File.read(version_path).sub(/VERSION = '[\d\.]+'/, "VERSION = '#{args.version}'")
puts "Updating SomeName to version #{args.version}"
File.open(version_path, 'w') { |f| f.puts version_text }
Rake::Task['commit'].invoke("Bumped version to #{args.version.to_s}")
end
desc "Executes a fresh install removing all padrino version and then reinstall all gems"
task :fresh => [:uninstall, :install, :clean]
desc "Pushes repository to GitHub"
task :push do
puts "Pushing to github..."
sh "git tag #{SomeName.version}"
sh "git push origin master"
sh "git push origin #{SomeName.version}"
end
desc "Release all padrino gems"
task :publish => :push do
puts "Pushing to rubygems..."
GEM_PATHS.each do |dir|
Dir.chdir(dir) { rake_command("release") }
end
Rake::Task["clean"].invoke
end
desc "Run tests for all padrino stack gems"
task :test do
# Omit the padrino metagem since no tests there
GEM_PATHS[0..-2].each do |gem|
# Hardcode the 'cd' into the command and do not use Dir.chdir because this causes random tests to fail
sh "cd #{File.join(ROOT, gem)} && #{Gem.ruby} -S rake test", :verbose => true
end
end
desc "Run tests for all padrino stack gems"
task :default => :test
desc "Generate documentation for the Padrino framework"
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.options << '--fmt' << 'shtml' # explictly set shtml generator
rdoc.title = "Padrino Framework Documentation"
rdoc.main = 'padrino-core/README.rdoc'
rdoc.rdoc_files.include('padrino-core/lib/{*.rb,padrino-core}/*.rb')
rdoc.rdoc_files.include('padrino-core/lib/padrino-core/application/**/*.rb')
rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/cli.rb')
rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/support_lite.rb')
rdoc.rdoc_files.exclude('padrino-core/lib/padrino-core/server.rb')
rdoc.rdoc_files.include('padrino-core/README.rdoc')
rdoc.rdoc_files.include('padrino-admin/lib/**/*.rb')
rdoc.rdoc_files.exclude('padrino-admin/lib/padrino-admin/generators')
rdoc.rdoc_files.include('padrino-admin/README.rdoc')
rdoc.rdoc_files.include('padrino-helpers/lib/**/*.rb')
rdoc.rdoc_files.include('padrino-helpers/README.rdoc')
rdoc.rdoc_files.include('padrino-mailer/lib/**/*.rb')
rdoc.rdoc_files.include('padrino-mailer/README.rdoc')
end
desc "Publish doc on padrino.github.com"
task :pdoc => :rdoc do
puts "Publishing doc on padrinorb.com ..."
Rake::SshDirPublisher.new("root@lipsiasoft.biz", "/mnt/www/apps/padrino/public/api", "doc").upload
FileUtils.rm_rf "doc"
end
module SomeName
VERSION = '0.9.10' unless defined?(SomeName::VERSION)
##
# Return the current version
#
def self.version
VERSION
end
end # SomeName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment