Permalink
Browse files

Update release task

  • Loading branch information...
1 parent 444552f commit 168be2dda4c4025f1e8722da59f648bfb7fa4058 @rymai rymai committed Nov 17, 2013
Showing with 48 additions and 16 deletions.
  1. +48 −16 Rakefile
View
@@ -7,17 +7,24 @@ task default: :spec
require 'guard/rake_task'
Guard::RakeTask.new(:guard, '--plugin ronn')
-namespace :release do
- require 'guard/version'
+class Releaser
- desc "Push Guard #{Guard::VERSION} to RubyGems and publish its GitHub release"
- task full: ['release:gem', 'release:github']
+ def initialize(options = {})
+ @project_name = options.delete(:project_name) { raise 'project_name is needed!' }
+ @gem_name = options.delete(:gem_name) { raise 'gem_name is needed!' }
+ @github_repo = options.delete(:github_repo) { raise 'github_repo is needed!' }
+ @version = options.delete(:version) { raise 'version is needed!' }
+ end
- desc "Push Guard #{Guard::VERSION} to RubyGems"
- task :gem do
+ def full
+ rubygems
+ github
+ end
+
+ def rubygems
input = ''
begin
- puts "Release Guard #{Guard::VERSION} to RubyGems? (y/n)"
+ puts "Release #{@project_name} #{@version} to RubyGems? (y/n)"
input = STDIN.gets.chomp.downcase
end while !%w[y n].include?(input)
@@ -26,26 +33,26 @@ namespace :release do
Rake::Task['release'].invoke
end
- desc "Publish Guard #{Guard::VERSION} GitHub release"
- task :github do
+ def github
require 'gems'
- if Guard::VERSION != Gems.info('guard')['version']
- puts "Guard #{Guard::VERSION} is not yet released."
+
+ if @version != Gems.info(@gem_name)['version']
+ puts "#{@project_name} #{@version} is not yet released."
puts "Please release it first with: rake release:gem"
exit
end
tags = `git ls-remote --tags origin`.split("\n")
- unless tags.find { |tag| tag =~ /v#{Guard::VERSION}$/ }
- puts "The tag v#{Guard::VERSION} has not yet been pushed."
+ unless tags.find { |tag| tag =~ /v#{@version}$/ }
+ puts "The tag v#{@version} has not yet been pushed."
puts "Please push it first with: rake release:gem"
exit
end
require 'octokit'
gh_client = Octokit::Client.new(netrc: true)
- gh_releases = gh_client.releases('guard/guard')
- tag_name = "v#{Guard::VERSION}"
+ gh_releases = gh_client.releases(@github_repo)
+ tag_name = "v#{@version}"
if gh_release = gh_releases.find { |r| r.tag_name == tag_name && r.draft == true }
input = ''
@@ -60,13 +67,38 @@ namespace :release do
exit if input == 'n'
if gh_client.update_release(gh_release.rels[:self].href, draft: false)
+ gh_release = gh_client.releases(@github_repo).find { |r| r.tag_name == tag_name && r.draft == false }
puts "GitHub release #{tag_name} has been published!"
puts "\nPlease enjoy and spread the word!"
puts "Lack of inspiration? Here's a tweet you could improve:\n\n"
- puts "Just released Guard #{Guard::VERSION}! #{gh_release.rels[:html].href}"
+ puts "Just released #{@project_name} #{@version}! #{gh_release.rels[:html].href}"
else
puts "GitHub release #{tag_name} couldn't be published!"
end
end
end
+
+end
+
+PROJECT_NAME = 'Guard'
+CURRENT_VERSION = Guard::VERSION
+
+def releaser
+ $releaser ||= Releaser.new(project_name: PROJECT_NAME, gem_name: 'guard',
+ github_repo: 'guard/guard', version: CURRENT_VERSION)
+end
+
+namespace :release do
+ desc "Push #{PROJECT_NAME} #{CURRENT_VERSION} to RubyGems and publish its GitHub release"
+ task full: ['release:gem', 'release:github']
+
+ desc "Push #{PROJECT_NAME} #{CURRENT_VERSION} to RubyGems"
+ task :gem do
+ releaser.rubygems
+ end
+
+ desc "Publish #{PROJECT_NAME} #{CURRENT_VERSION} GitHub release"
+ task :github do
+ releaser.github
+ end
end

0 comments on commit 168be2d

Please sign in to comment.