Skip to content

Commit

Permalink
Use ENV for rake options
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsoman committed Oct 13, 2013
1 parent e488050 commit 3f0c831
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 12 deletions.
10 changes: 8 additions & 2 deletions README.markdown
Expand Up @@ -65,13 +65,19 @@ This will automatically:
* Use `git` to tag `v0.1.0` and push it
* Build `hello-gem-0.1.0.gem` and push it to [rubygems.org](http://rubygems.org/gems/)

`rake release` accepts remote(default: `origin`), local branch(default: `master`) and remote branch(default: `master`)as optional arguments.
`rake release` accepts REMOTE(default: `origin`), LOCAL_BRANCH(default: `master`), REMOTE_BRANCH(default: `master`) and BRANCH(default: master)as options.

$ rake release[upstream,critical-security-fix,v3]
$ rake release REMOTE=upstream LOCAL_BRANCH=critical-security-fix REMOTE_BRANCH=v3

This will tag and push the commits on your local branch named `critical-security-fix` to branch named `v3` in remote named `upstream` (if you have commit rights
on `upstream`) and release the gem.

$ rake release BRANCH=v3

If both remote and local branches are the same, use `BRANCH` option to simplify.
This will tag and push the commits on your local branch named `v3` to branch named `v3` in remote named `origin` (if you have commit rights
on `origin`) and release the gem.

### Version bumping

It feels good to release code. Do it, do it often. But before that, bump the version. Then release it. There's a few ways to update the version:
Expand Down
5 changes: 3 additions & 2 deletions lib/jeweler/commands/release_gemspec.rb
Expand Up @@ -14,9 +14,10 @@ def initialize(attributes = {})
end

def run(args = {})
local_branch = args[:local_branch] || 'master'
remote_branch = args[:remote_branch] || 'master'
remote = args[:remote] || 'origin'
branch = args[:branch] || 'master'
local_branch = args[:local_branch] || branch
remote_branch = args[:remote_branch] || branch

unless clean_staging_area?
system "git status"
Expand Down
5 changes: 3 additions & 2 deletions lib/jeweler/commands/release_to_git.rb
Expand Up @@ -12,9 +12,10 @@ def initialize(attributes = {})
end

def run(args = {})
local_branch = args[:local_branch] || 'master'
remote_branch = args[:remote_branch] || 'master'
remote = args[:remote] || 'origin'
branch = args[:branch] || 'master'
local_branch = args[:local_branch] || branch
remote_branch = args[:remote_branch] || branch

unless clean_staging_area?
system "git status"
Expand Down
21 changes: 15 additions & 6 deletions lib/jeweler/tasks.rb
Expand Up @@ -68,6 +68,15 @@ def yield_gemspec_set_version?
! yielded_gemspec.version.nil?
end

def release_args
args = {}
args[:remote] = ENV['REMOTE']
args[:branch] = ENV['BRANCH']
args[:local_branch] = ENV['LOCAL_BRANCH']
args[:remote_branch] = ENV['REMOTE_BRANCH']
return args
end

def define
task :version_required do
if jeweler.expects_version_file? && !jeweler.version_file_exists?
Expand Down Expand Up @@ -129,12 +138,12 @@ def define
end

desc "Regenerate and validate gemspec, and then commits and pushes to git"
task :release, :remote, :local_branch, :remote_branch do |task, args|
jeweler.release_gemspec(args)
task :release do
jeweler.release_gemspec(release_args)
end
end

task :release, [:remote, :local_branch, :remote_branch] => 'gemspec:release'
task :release => 'gemspec:release'


unless yield_gemspec_set_version?
Expand Down Expand Up @@ -171,12 +180,12 @@ def define

namespace :git do
desc "Tag and push release to git. (happens by default with `rake release`)"
task :release, :remote, :local_branch, :remote_branch do |task, args|
jeweler.release_to_git(args)
task :release do
jeweler.release_to_git(release_args)
end
end

task :release, [:remote, :local_branch, :remote_branch] => 'git:release'
task :release => 'git:release'

unless File.exist?('Gemfile')
desc "Check that runtime and development dependencies are installed"
Expand Down
31 changes: 31 additions & 0 deletions test/jeweler/commands/test_release_to_git.rb
Expand Up @@ -64,6 +64,37 @@ class TestReleaseToGit < Test::Unit::TestCase

end

context "happily with different branch" do
setup do
stub(@command).clean_staging_area? { true }
stub(@command).release_tag { "v3.2.0" }

stub(@repo).checkout(anything)
stub(@repo) do
add_tag(anything)
push(anything, anything)
end

stub(@repo).push

stub(@command).release_not_tagged? { true }

@command.run({:branch => 'v3'})
end

should "checkout master" do
assert_received(@repo) {|repo| repo.checkout('v3') }
end

should "tag version" do
assert_received(@repo) {|repo| repo.add_tag('v3.2.0') }
end

should "push" do
assert_received(@repo) {|repo| repo.push('origin', 'v3:v3') }
end
end

context "with an unclean staging area" do
setup do
stub(@command).clean_staging_area? { false }
Expand Down
35 changes: 35 additions & 0 deletions test/jeweler/commands/test_release_to_github.rb
Expand Up @@ -78,6 +78,41 @@ class TestReleaseGemspec < Test::Unit::TestCase

end

context "happily with different branch" do
setup do
stub(@command).clean_staging_area? { true }

stub(@repo).checkout(anything)

stub(@command).regenerate_gemspec!

stub(@command).gemspec_changed? { true }
stub(@command).commit_gemspec! { true }

stub(@repo).push

stub(@command).release_not_tagged? { true }

@command.run({:branch => 'v3'})
end

should "checkout local branch" do
assert_received(@repo) {|repo| repo.checkout('v3') }
end

should "regenerate gemspec" do
assert_received(@command) {|command| command.regenerate_gemspec! }
end

should "commit gemspec" do
assert_received(@command) {|command| command.commit_gemspec! }
end

should "push" do
assert_received(@repo) {|repo| repo.push('origin', 'v3:v3') }
end
end

context "with an unclean staging area" do
setup do
stub(@command).clean_staging_area? { false }
Expand Down

0 comments on commit 3f0c831

Please sign in to comment.