Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added feature to push specific branch #3

Merged
merged 2 commits into from

2 participants

@denro

By setting the config or as an environment variable

denro added some commits
@denro denro Added feature to push a specific branch to heroku,
can be done by setting the ENV['BRANCH'] variable or
in the config for HerokuRelease
f17ed6f
@denro denro Updated README 83870bf
@peter peter merged commit 08550e0 into peter:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2012
  1. @denro

    Added feature to push a specific branch to heroku,

    denro authored
    can be done by setting the ENV['BRANCH'] variable or
    in the config for HerokuRelease
  2. @denro

    Updated README

    denro authored
This page is out of date. Refresh to see the latest.
View
4 README.rdoc
@@ -19,11 +19,15 @@ You have a few configuration options. If you are using a Git remote other than "
HerokuRelease.config.heroku_remote = "production" # git remote for heroku, defaults to "heroku"
HerokuRelease.config.version_file_path = "public/version" # if not set no version file will be generated
HerokuRelease.config.changelog_path = "CHANGELOG" # if not set no changelog file will be generated
+ HerokuRelease.config.branch = 'production' # defaults to 'master'
To deploy the master branch to production, use the heroku_release rake task:
rake heroku_release COMMENT="This is a comment describing what changed since the last release"
+To deploy another branch to production, send the BRANCH env variable:
+ rake heroku_release BRANCH="production_branch"
+
If the deploy went horribly wrong and you need to do a rollback you can do so:
rake heroku_release:rollback
View
28 lib/heroku_release.rb
@@ -3,7 +3,8 @@
module HerokuRelease
@@config = OpenStruct.new(
:heroku_remote => "heroku",
- :prompt_for_comments => true
+ :prompt_for_comments => true,
+ :branch => "master"
)
def self.config
@@ -13,7 +14,7 @@ def self.config
def self.config=(config)
@@config = config
end
-
+
class Task
def self.tasks
{
@@ -24,12 +25,12 @@ def self.tasks
:previous_release => "Show version of previous release",
:pending => "Show git commits since last released version",
:rollback => "Rollback to previous release and remove current release tag"
- }
+ }
end
-
+
def push
- output 'Deploying site to Heroku ...'
- execute "git push #{config.heroku_remote} master"
+ output "Deploying branch #{branch} to Heroku ..."
+ execute "git push #{config.heroku_remote} #{branch}:master"
end
def tag
@@ -104,7 +105,7 @@ def single_quote(string)
end
def get_tag_comment
- return ENV['COMMENT'] if ENV['COMMENT']
+ return ENV['COMMENT'] if ENV['COMMENT']
if config.prompt_for_comments
print "Required - please enter a release comment: "
$stdin.gets.strip
@@ -113,6 +114,11 @@ def get_tag_comment
end
end
+ def branch
+ return ENV['BRANCH'] if ENV['BRANCH']
+ config.branch
+ end
+
def output(message)
puts message
end
@@ -134,7 +140,7 @@ def previous_release_version
previous
else
nil
- end
+ end
end
def update_version_file(release_name)
@@ -146,12 +152,12 @@ def update_changelog(release_name, tag_comment)
write_changelog(release_name, tag_comment)
execute "git add #{config.changelog_path}"
end
-
+
def commit(release_name, quoted_tag_comment)
execute "git commit -m '#{release_name}: #{quoted_tag_comment}'"
- execute "git push origin master"
+ execute "git push origin master"
end
-
+
def write_changelog(release_name, tag_comment)
changelog_entries_with_next = [[release_name, tag_comment]] + changelog_entries
File.open(config.changelog_path, "w") { |f| f.print(changelog_warning + changelog(changelog_entries_with_next)) }
View
25 spec/heroku_release_spec.rb
@@ -4,11 +4,11 @@
before(:each) do
@config_before = HerokuRelease.config.dup
end
-
+
after(:each) do
HerokuRelease.config = @config_before
end
-
+
describe "config" do
it "defaults heroku_remote to heroku" do
config.heroku_remote.should == "heroku"
@@ -17,31 +17,40 @@
it "defaults prompting for comments to true" do
config.prompt_for_comments.should == true
end
-
+
it "can set heroku_remote" do
config.heroku_remote = "production"
config.heroku_remote.should == "production"
end
-
+
it "defaults version_file_path to nil" do
config.version_file_path.should be_nil
end
-
+
it "can set version_file_path" do
config.version_file_path = "public/system/version"
config.version_file_path.should == "public/system/version"
end
-
+
it "defaults changelog_path to nil" do
config.changelog_path.should be_nil
end
-
+
it "can set changelog_path" do
config.changelog_path = "CHANGELOG"
config.changelog_path.should == "CHANGELOG"
end
+
+ it "defaults branch to 'master'" do
+ config.branch.should == 'master'
+ end
+
+ it "can set branch" do
+ config.branch = 'production'
+ config.branch.should == 'production'
+ end
end
-
+
def config
HerokuRelease.config
end
View
66 spec/task_spec.rb
@@ -12,24 +12,32 @@
after(:each) do
HerokuRelease.config = @config_before
end
-
+
describe "tasks" do
it "is a Hash" do
HerokuRelease::Task.tasks.is_a?(Hash).should be_true
end
-
+
it "corresponds to public instance methods" do
- HerokuRelease::Task.tasks.keys.map(&:to_s).sort.should == task_instance_methods
+ HerokuRelease::Task.tasks.keys.map(&:to_s).sort.should == task_instance_methods
end
-
+
def task_instance_methods
HerokuRelease::Task.public_instance_methods(false).map(&:to_s).sort
end
end
-
+
describe "push" do
- it "should execute a git push to heroku remote" do
- @task.expects(:execute).with("git push #{@config.heroku_remote} master")
+ it "should execute a git push to heroku remote with the branch set in config" do
+ @config.branch = 'production'
+
+ @task.expects(:execute).with("git push #{@config.heroku_remote} #{@config.branch}:master")
+ @task.push
+ end
+
+ it "should execute a git push to heroku remote with the branch set as ENV['BRANCH']" do
+ ENV['BRANCH'] = 'other_branch'
+ @task.expects(:execute).with("git push #{@config.heroku_remote} #{ENV['BRANCH']}:master")
@task.push
end
end
@@ -64,7 +72,7 @@ def task_instance_methods
$stdin = old_stdin
end
end
-
+
it "commits version file if version_file_path is set" do
ENV['COMMENT'] = nil
@config.version_file_path = "public/version"
@@ -75,7 +83,7 @@ def task_instance_methods
@task.tag
end
-
+
it "commits changelog if changelog_path is set" do
@config.changelog_path = "spec/CHANGELOG"
@task.expects(:get_release_name).returns("release-123")
@@ -83,16 +91,16 @@ def task_instance_methods
@task.expects(:update_changelog)
@task.expects(:commit)
expect_tag_created("release-123")
-
+
@task.tag
end
-
+
def expect_tag_created(release_name, comment = "Tagged release")
git = sequence('git')
quoted_comment = comment.gsub("'") { %q{'\''} }
@task.expects(:execute).with("git tag -a #{release_name} -m '#{quoted_comment}'").in_sequence(git)
@task.expects(:execute).with("git push --tags origin").in_sequence(git)
- @task.expects(:execute).with("git push --tags #{@config.heroku_remote}").in_sequence(git)
+ @task.expects(:execute).with("git push --tags #{@config.heroku_remote}").in_sequence(git)
end
end
@@ -139,11 +147,11 @@ def expect_tag_created(release_name, comment = "Tagged release")
@task.expects(:output).with("release-20100922-115151")
@task.previous_release
end
-
+
it "says there is no previous release if there is none" do
@task.stubs(:releases).returns(%w(release-20100922-122313))
@task.expects(:output).with("no previous release found")
- @task.previous_release
+ @task.previous_release
end
end
@@ -164,7 +172,7 @@ def expect_tag_created(release_name, comment = "Tagged release")
@task.expects(:execute).with("git tag -d release-current").in_sequence(git)
@task.expects(:execute).with("git push #{@config.heroku_remote} :refs/tags/release-current").in_sequence(git)
@task.expects(:execute).with("git push origin :refs/tags/release-current").in_sequence(git)
-
+
@task.rollback
end
end
@@ -175,7 +183,7 @@ def expect_tag_created(release_name, comment = "Tagged release")
@task.send(:output, "a message")
end
end
-
+
describe "execute" do
it "executes a command and outputs the result" do
@task.expects(:output).with("foobar")
@@ -187,22 +195,22 @@ def expect_tag_created(release_name, comment = "Tagged release")
@task.send(:execute, "echo")
end
end
-
+
describe "get_release_name" do
it "generates a timestamped tag name" do
@task.send(:get_release_name).should =~ /release-\d\d\d\d\d\d\d\d-\d\d\d\d\d\d/
end
end
-
+
describe "update_version_file(release_name)" do
before(:each) do
- @path = "spec/version"
+ @path = "spec/version"
end
-
+
after(:each) do
FileUtils.rm_f(@path)
end
-
+
it "writes release_name to version_file_path and commits that file" do
@task.expects(:execute).with("git add #{@path}")
@@ -228,7 +236,7 @@ def expect_tag_created(release_name, comment = "Tagged release")
release-20100926-173016
END
)
-
+
@task.send(:releases).should == %w(release-20100922-115151 release-20100922-122313 release-20100926-173016)
end
end
@@ -238,19 +246,19 @@ def expect_tag_created(release_name, comment = "Tagged release")
@task.send(:git_tags)
end
end
-
+
describe "update_changelog" do
after(:each) do
FileUtils.rm_f(@config.changelog_path)
end
-
+
it "writes changelog to changelog_path and commits it" do
@config.changelog_path = "spec/CHANGELOG"
@task.expects(:changelog).returns("the changelog")
@task.expects(:execute).with("git add #{@config.changelog_path}")
-
+
@task.send(:update_changelog, "release-next", "Next release")
-
+
File.read(@config.changelog_path).should == (@task.send(:changelog_warning) + "the changelog")
end
end
@@ -263,18 +271,18 @@ def expect_tag_created(release_name, comment = "Tagged release")
release-20110927-083744 Third release
END
end
-
+
it "should return an array with release tags and comments in reverse chronological order" do
@task.expects(:git_tags_with_comments).returns(@git_tags_with_comments)
@task.send(:changelog_entries).should == [["release-20110927-083744", "Third release"], ["release-20110927-082753", "Second release"], ["release-20110923-132407", "First release"]]
end
end
-
+
describe "commit" do
it "does a commit followed by a push to origin" do
git = sequence('git')
@task.expects(:execute).with(regexp_matches(/git commit/)).in_sequence(git)
- @task.expects(:execute).with(regexp_matches(/git push/)).in_sequence(git)
+ @task.expects(:execute).with(regexp_matches(/git push/)).in_sequence(git)
@task.send(:commit, "test-release-name", "test tag comment")
end
end
Something went wrong with that request. Please try again.