Skip to content
Browse files

add integration test for ordering refs from a team-city-like ci serve…

…r and use ordered refs everywhere so we don't delete the wrong refs.
  • Loading branch information...
1 parent 21c510b commit 05d1af81aca70a0d300dc5e963afb549af023e2f Rachel Heaton committed
View
8 features/deployment.feature
@@ -39,3 +39,11 @@ Feature: Deployment
And a ci tag
When I deploy to staging
Then I should see "release tag history is:"
+
+ @0.2.5
+ Scenario: user deploys with cap-ext multistage using Team City-like ci tags
+ Given a three-stage app using cap-multistage
+ And ci tags from team city
+ When I deploy to staging
+ Then the last ci build should have been the staging tag added to git
+
View
19 features/step_definitions/deployment_steps.rb
@@ -38,6 +38,16 @@
end
end
+Given /^ci tags from team city$/ do
+ with_or_without_debugging do
+ helpers = StepHelpers.new
+ helpers.team_city_tag("ci", "999")
+ helpers.create_and_push_another_commit
+ helpers.team_city_tag("ci", "1007")
+ @refs = helpers.refs
+ end
+end
+
When /^I deploy to (.*)$/ do |environment|
with_or_without_debugging do
helpers = StepHelpers.new
@@ -59,3 +69,12 @@
@refs.length.should < new_tags.length
end
end
+
+Then /^the last ci build should have been the staging tag added to git$/ do
+ helpers = StepHelpers.new
+ last_ref = helpers.refs.split("\n").last
+ last_ref.should match(/\/staging\//)
+ last_ci_ref = @refs.split("\n").detect { |ref| ref.match("1007") }
+
+ last_ref.split(" ").first.should == last_ci_ref.split(" ").first
+end
View
13 features/support/step_helpers.rb
@@ -64,6 +64,10 @@ def autotag(stage)
system "cd #{app_dir} && git tag #{stage}/#{Time.now.utc.strftime('%Y%m%d%H%M%S')} && git push origin --tags"
end
+ def team_city_tag(stage, build_number)
+ system "cd #{app_dir} && git tag #{stage}/#{build_number} && git push origin --tags"
+ end
+
def refs(namespace = "tags")
system "cd #{app_dir} && git fetch origin refs/#{namespace}/*:refs/#{namespace}/*"
refs = `cd #{app_dir} && git show-ref | grep #{namespace}`
@@ -84,6 +88,15 @@ def create_app
]
end
+ def create_and_push_another_commit
+ run_commands [
+ "cd #{app_dir}",
+ "touch MY_LICENSE",
+ "git add .",
+ %Q{git commit -m "another commit"},
+ "git push origin master"
+ ]
+ end
private
def capify_app
View
19 lib/auto_tagger/base.rb
@@ -25,7 +25,7 @@ def repo
def last_ref_from_previous_stage
return unless previous_stage
- ordered_refs_for_stage(previous_stage).last
+ refs_for_stage(previous_stage).last
end
def create_ref(commit = nil)
@@ -104,16 +104,8 @@ def release_tag_entries
def refs_for_stage(stage)
raise StageCannotBeBlankError if stage.to_s.strip == ""
ref_path = Regexp.escape(configuration.ref_path)
- matcher = /refs\/#{ref_path}\/#{Regexp.escape(stage)}\/.*/
- repo.refs.all.select do |ref|
- (ref.name =~ matcher) ? ref : nil
- end
- end
-
- def ordered_refs_for_stage(stage)
- ref_path = Regexp.escape(configuration.ref_path)
matcher = /refs\/#{ref_path}\/#{Regexp.escape(stage)}\/(.*)/
- refs_for_stage(stage).sort do |ref1, ref2|
+ select_refs_for_stage(stage).sort do |ref1, ref2|
name1 = ref1.name.match(matcher)[1].gsub(configuration.date_separator, "")
name2 = ref2.name.match(matcher)[1].gsub(configuration.date_separator, "")
name1.to_i <=> name2.to_i
@@ -121,6 +113,13 @@ def ordered_refs_for_stage(stage)
end
private
+ def select_refs_for_stage(stage)
+ ref_path = Regexp.escape(configuration.ref_path)
+ matcher = /refs\/#{ref_path}\/#{Regexp.escape(stage)}\/.*/
+ repo.refs.all.select do |ref|
+ (ref.name =~ matcher) ? ref : nil
+ end
+ end
def refs_to_remove
self.class.items_to_remove(refs_for_stage(configuration.stage), configuration.refs_to_keep)
View
13 spec/auto_tagger/base_spec.rb
@@ -257,6 +257,19 @@
AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/2009")
]
end
+
+ it "orders refs based on last part of tag" do
+ base = AutoTagger::Base.new :stage => "ci"
+ base.repo.stub(:exec) { true }
+ refs = [
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/1001"),
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/999"),
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/tags/ci/1002"),
+ AutoTagger::Git::Ref.new(base.repo, "abc123", "refs/heads/master")
+ ]
+ base.repo.stub(:refs) { mock("RefSet", :all => refs) }
+ base.refs_for_stage("ci").map(&:name).should == [ "refs/tags/ci/999", "refs/tags/ci/1001", "refs/tags/ci/1002" ]
+ end
end
describe "#list" do

0 comments on commit 05d1af8

Please sign in to comment.
Something went wrong with that request. Please try again.