From cfd8ce39b7473fb9712404329536679ee6972a24 Mon Sep 17 00:00:00 2001 From: Jason Ardell Date: Fri, 5 Mar 2010 14:28:14 -0500 Subject: [PATCH 1/6] Added a demo stage --- gitflow.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gitflow.rb b/gitflow.rb index 0b4af2c..d39d35d 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -22,6 +22,10 @@ def last_staging_tag() return last_tag_matching('staging-*') end + def last_demo_tag() + return last_tag_matching('demo-*') + end + def last_production_tag() return last_tag_matching('production-*') end @@ -53,6 +57,8 @@ def last_production_tag() # do different things based on stage if stage == :production fromTag = last_production_tag + elsif stage == :demo + fromTag = last_demo_tag elsif stage == :staging fromTag = last_staging_tag else @@ -66,6 +72,8 @@ def last_production_tag() # do different things based on stage if stage == :production toTag = last_staging_tag + elsif stage == :demo + toTag = last_staging_tag elsif stage == :staging toTag = 'head' else @@ -114,6 +122,21 @@ def last_production_tag() set :branch, newStagingTag end + desc "Push the passed staging tag to demo. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." + task :tag_demo do + promoteToDemoTag = configuration[:tag] + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToDemoTag + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToDemoTag =~ /staging-.*/ + raise "Staging Tag #{promoteToDemoTag} does not exist." unless last_tag_matching(promoteToDemoTag) + + promoteToDemoTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + newDemoTag = "demo-#{$1}" + puts "promoting staging tag #{promoteToDemoTag} to demo as '#{newDemoTag}'" + system "git tag -a -m 'tagging current code for deployment to demo' #{newDemoTag} #{promoteToDemoTag}" + + set :branch, newDemoTag + end + desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do promoteToProductionTag = configuration[:tag] From 011126c1f8ada644f4cd46d46eb085f024487916 Mon Sep 17 00:00:00 2001 From: Sean Joyce Date: Thu, 13 Mar 2014 19:21:36 -0400 Subject: [PATCH 2/6] DEV-3288 Add UAT deploy tasks --- gitflow.rb | 102 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/gitflow.rb b/gitflow.rb index d39d35d..7a03680 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -11,7 +11,7 @@ def last_tag_matching(pattern) allTagsMatching.sort! do |a,b| String.natcmp(b,a,true) end - + if allTagsMatching.length > 0 lastTag = allTagsMatching[0] end @@ -26,6 +26,10 @@ def last_demo_tag() return last_tag_matching('demo-*') end + def last_uat_tag() + return last_tag_matching('uat-*') + end + def last_production_tag() return last_tag_matching('production-*') end @@ -55,12 +59,14 @@ def last_production_tag() toTag = nil # do different things based on stage - if stage == :production - fromTag = last_production_tag + if (stage == :production or stage = :production_vagrant) + fromTag = last_tag_matching("#{stage}-*") elsif stage == :demo fromTag = last_demo_tag - elsif stage == :staging - fromTag = last_staging_tag + elsif stage == :uat + fromTag = last_uat_tag + elsif (stage == :staging or stage = :staging_vagrant) + fromTag = last_tag_matching("#{stage}-*") else raise "Unsupported stage #{stage}" end @@ -70,11 +76,13 @@ def last_production_tag() if toTag == nil puts "Calculating 'end' tag for :update_log for '#{stage}'" # do different things based on stage - if stage == :production + if (stage == :production or stage = :production_vagrant) toTag = last_staging_tag elsif stage == :demo toTag = last_staging_tag - elsif stage == :staging + elsif stage == :uat + toTag = last_staging_tag + elsif (stage == :staging or stage = :staging_vagrant) toTag = 'head' else raise "Unsupported stage #{stage}" @@ -94,7 +102,7 @@ def last_production_tag() desc "Mark the current code as a staging/qa release" task :tag_staging do # find latest staging tag for today - newTagDate = Date.today.to_s + newTagDate = Date.today.to_s newTagSerial = 1 lastStagingTag = last_tag_matching("staging-#{newTagDate}.*") @@ -122,6 +130,21 @@ def last_production_tag() set :branch, newStagingTag end + desc "Push the passed staging tag to demo_vagrant. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." + task :tag_demo_vagrant do + promoteToDemoTag = configuration[:tag] + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToDemoTag + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToDemoTag =~ /staging-.*/ + raise "Staging Tag #{promoteToDemoTag} does not exist." unless last_tag_matching(promoteToDemoTag) + + promoteToDemoTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + newDemoTag = "demo_vagrant-#{$1}" + puts "promoting staging tag #{promoteToDemoTag} to demo_vagrant as '#{newDemoTag}'" + system "git tag -a -m 'tagging current code for deployment to demo_vagrant' #{newDemoTag} #{promoteToDemoTag}" + + set :branch, newDemoTag + end + desc "Push the passed staging tag to demo. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_demo do promoteToDemoTag = configuration[:tag] @@ -137,13 +160,28 @@ def last_production_tag() set :branch, newDemoTag end + desc "Push the passed staging tag to uat. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." + task :tag_uat do + promoteToUatTag = configuration[:tag] + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag =~ /staging-.*/ + raise "Staging Tag #{promoteToUatTag} does not exist." unless last_tag_matching(promoteToUatTag) + + promoteToUatTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + newUatTag = "uat-#{$1}" + puts "promoting staging tag #{promoteToUatTag} to uat as '#{newUatTag}'" + system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" + + set :branch, newUatTag + end + desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do promoteToProductionTag = configuration[:tag] raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToProductionTag raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToProductionTag =~ /staging-.*/ raise "Staging Tag #{promoteToProductionTag} does not exist." unless last_tag_matching(promoteToProductionTag) - + promoteToProductionTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ newProductionTag = "production-#{$1}" puts "promoting staging tag #{promoteToProductionTag} to production as '#{newProductionTag}'" @@ -151,5 +189,51 @@ def last_production_tag() set :branch, newProductionTag end + + desc "Mark the current code as a staging/qa release" + task :tag_staging_vagrant do + # find latest staging tag for today + newTagDate = Date.today.to_s + newTagSerial = 1 + + lastStagingTag = last_tag_matching("staging_vagrant-#{newTagDate}.*") + if lastStagingTag + # calculate largest serial and increment + lastStagingTag =~ /staging_vagrant-[0-9]{4}-[0-9]{2}-[0-9]{2}\.([0-9]*)/ + newTagSerial = $1.to_i + 1 + end + newStagingTag = "staging_vagrant-#{newTagDate}.#{newTagSerial}" + + shaOfCurrentCheckout = `git log --pretty=format:%H HEAD -1` + shaOfLastStagingTag = nil + if lastStagingTag + shaOfLastStagingTag = `git log --pretty=format:%H #{lastStagingTag} -1` + end + + if shaOfLastStagingTag == shaOfCurrentCheckout + puts "Not re-tagging staging_vagrant because the most recent tag (#{lastStagingTag}) already points to current head" + newStagingTag = lastStagingTag + else + puts "Tagging current branch for deployment to staging_vagrant as '#{newStagingTag}'" + system "git tag -a -m 'tagging current code for deployment to staging_vagrant' #{newStagingTag}" + end + + set :branch, newStagingTag + end + + desc "Push the passed staging tag to production_vagrant. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." + task :tag_production_vagrant do + promoteToProductionTag = configuration[:tag] + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToProductionTag + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToProductionTag =~ /staging-.*/ + raise "Staging Tag #{promoteToProductionTag} does not exist." unless last_tag_matching(promoteToProductionTag) + + promoteToProductionTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + newProductionTag = "production_vagrant-#{$1}" + puts "promoting staging tag #{promoteToProductionTag} to production_vagrant as '#{newProductionTag}'" + system "git tag -a -m 'tagging current code for deployment to production_vagrant' #{newProductionTag} #{promoteToProductionTag}" + + set :branch, newProductionTag + end end end From 69e40ce2282b19a6eb5145be02742de5b2e71de0 Mon Sep 17 00:00:00 2001 From: Sean Joyce Date: Thu, 13 Mar 2014 19:28:50 -0400 Subject: [PATCH 3/6] DEV-3288 Add UAT deploy tasks --- gitflow.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gitflow.rb b/gitflow.rb index d39d35d..3cb1721 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -22,9 +22,15 @@ def last_staging_tag() return last_tag_matching('staging-*') end +<<<<<<< Updated upstream def last_demo_tag() return last_tag_matching('demo-*') end +======= + def last_uat_tag() + return last_tag_matching('uat-*') + end +>>>>>>> Stashed changes def last_production_tag() return last_tag_matching('production-*') @@ -55,12 +61,21 @@ def last_production_tag() toTag = nil # do different things based on stage +<<<<<<< Updated upstream if stage == :production fromTag = last_production_tag elsif stage == :demo fromTag = last_demo_tag elsif stage == :staging fromTag = last_staging_tag +======= + if (stage == :production or stage = :production_vagrant) + fromTag = last_tag_matching("#{stage}-*") + elsif (stage == :staging or stage = :staging_vagrant) + fromTag = last_tag_matching("#{stage}-*") + elsif (stage == :uat) + fromTag = last_tag_matching("#{uat}-*") +>>>>>>> Stashed changes else raise "Unsupported stage #{stage}" end @@ -72,9 +87,15 @@ def last_production_tag() # do different things based on stage if stage == :production toTag = last_staging_tag +<<<<<<< Updated upstream elsif stage == :demo toTag = last_staging_tag elsif stage == :staging +======= + elsif (stage == :uat) + toTag = last_staging_tag + elsif (stage == :staging or stage = :staging_vagrant) +>>>>>>> Stashed changes toTag = 'head' else raise "Unsupported stage #{stage}" @@ -137,6 +158,21 @@ def last_production_tag() set :branch, newDemoTag end + desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." + task :tag_uat do + promoteToUatTag = configuration[:tag] + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag =~ /staging-.*/ + raise "Staging Tag #{promoteToUatTag} does not exist." unless last_tag_matching(promoteToUatTag) + + promoteToUatTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + newUatTag = "uat-#{$1}" + puts "promoting staging tag #{promoteToUatTag} to uat as '#{newUatTag}'" + system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" + + set :branch, newUatTag + end + desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do promoteToProductionTag = configuration[:tag] From 18cc91dc2cdc8b7cde74ad7b8aa3da60c80fc75d Mon Sep 17 00:00:00 2001 From: Jonathan Loesch Date: Mon, 17 Mar 2014 14:06:59 -0400 Subject: [PATCH 4/6] Reverting faulty commit "DEV-3288 Add UAT deploy tasks" This reverts commit 69e40ce2282b19a6eb5145be02742de5b2e71de0. --- gitflow.rb | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/gitflow.rb b/gitflow.rb index 3cb1721..d39d35d 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -22,15 +22,9 @@ def last_staging_tag() return last_tag_matching('staging-*') end -<<<<<<< Updated upstream def last_demo_tag() return last_tag_matching('demo-*') end -======= - def last_uat_tag() - return last_tag_matching('uat-*') - end ->>>>>>> Stashed changes def last_production_tag() return last_tag_matching('production-*') @@ -61,21 +55,12 @@ def last_production_tag() toTag = nil # do different things based on stage -<<<<<<< Updated upstream if stage == :production fromTag = last_production_tag elsif stage == :demo fromTag = last_demo_tag elsif stage == :staging fromTag = last_staging_tag -======= - if (stage == :production or stage = :production_vagrant) - fromTag = last_tag_matching("#{stage}-*") - elsif (stage == :staging or stage = :staging_vagrant) - fromTag = last_tag_matching("#{stage}-*") - elsif (stage == :uat) - fromTag = last_tag_matching("#{uat}-*") ->>>>>>> Stashed changes else raise "Unsupported stage #{stage}" end @@ -87,15 +72,9 @@ def last_production_tag() # do different things based on stage if stage == :production toTag = last_staging_tag -<<<<<<< Updated upstream elsif stage == :demo toTag = last_staging_tag elsif stage == :staging -======= - elsif (stage == :uat) - toTag = last_staging_tag - elsif (stage == :staging or stage = :staging_vagrant) ->>>>>>> Stashed changes toTag = 'head' else raise "Unsupported stage #{stage}" @@ -158,21 +137,6 @@ def last_production_tag() set :branch, newDemoTag end - desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." - task :tag_uat do - promoteToUatTag = configuration[:tag] - raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag - raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag =~ /staging-.*/ - raise "Staging Tag #{promoteToUatTag} does not exist." unless last_tag_matching(promoteToUatTag) - - promoteToUatTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ - newUatTag = "uat-#{$1}" - puts "promoting staging tag #{promoteToUatTag} to uat as '#{newUatTag}'" - system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" - - set :branch, newUatTag - end - desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do promoteToProductionTag = configuration[:tag] From 28ba98f1dcfbd30c5a8ef0d8a393558dc43ea1cc Mon Sep 17 00:00:00 2001 From: Sean Joyce Date: Tue, 1 Sep 2015 11:09:27 -0400 Subject: [PATCH 5/6] DEV-6611 Allow for direct deploy to uat --- gitflow.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/gitflow.rb b/gitflow.rb index 7a03680..314d9f2 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -160,20 +160,58 @@ def last_production_tag() set :branch, newDemoTag end - desc "Push the passed staging tag to uat. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." - task :tag_uat do - promoteToUatTag = configuration[:tag] - raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag + def generate_uat_tag() + # find latest uat tag for today + newTagDate = Date.today.to_s + newTagSerial = 1 + + lastUatTag = last_tag_matching("uat-#{newTagDate}.*") + if lastUatTag + # calculate largest serial and increment + lastUatTag =~ /uat-[0-9]{4}-[0-9]{2}-[0-9]{2}\.([0-9]*)/ + newTagSerial = $1.to_i + 1 + end + newUatTag = "uat-#{newTagDate}.#{newTagSerial}" + + shaOfCurrentCheckout = `git log --pretty=format:%H HEAD -1` + shaOfLastUatTag = nil + if lastUatTag + shaOfLastUatTag = `git log --pretty=format:%H #{lastUatTag} -1` + end + + if shaOfLastUatTag == shaOfCurrentCheckout + puts "Not re-tagging uat because the most recent tag (#{lastUatTag}) already points to current head" + newUatTag = lastUatTag + else + puts "Tagging current branch for deployment to uat as '#{newUatTag}'" + system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag}" + end + return newUatTag + end + + def staging_to_uat(promoteToUatTag) raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag =~ /staging-.*/ raise "Staging Tag #{promoteToUatTag} does not exist." unless last_tag_matching(promoteToUatTag) - + promoteToUatTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ newUatTag = "uat-#{$1}" puts "promoting staging tag #{promoteToUatTag} to uat as '#{newUatTag}'" system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" + return newUatTag + end + desc "Mark the current code as a uat release" + task :tag_uat do + promoteToUatTag = configuration[:tag] + #if the user inputs a -s tag=staging ... + if promoteToUatTag + newUatTag = staging_to_uat(promoteToUatTag) + else + newUatTag = generate_uat_tag + end set :branch, newUatTag - end + end + desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do From 8236c35a38e6c0d07cda72c9bd295a4e6942e31f Mon Sep 17 00:00:00 2001 From: Sean Joyce Date: Tue, 1 Sep 2015 16:25:29 -0400 Subject: [PATCH 6/6] DEV-6611 update so we always generate a new uat tag even when promoting --- gitflow.rb | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/gitflow.rb b/gitflow.rb index 314d9f2..cca128a 100644 --- a/gitflow.rb +++ b/gitflow.rb @@ -172,20 +172,6 @@ def generate_uat_tag() newTagSerial = $1.to_i + 1 end newUatTag = "uat-#{newTagDate}.#{newTagSerial}" - - shaOfCurrentCheckout = `git log --pretty=format:%H HEAD -1` - shaOfLastUatTag = nil - if lastUatTag - shaOfLastUatTag = `git log --pretty=format:%H #{lastUatTag} -1` - end - - if shaOfLastUatTag == shaOfCurrentCheckout - puts "Not re-tagging uat because the most recent tag (#{lastUatTag}) already points to current head" - newUatTag = lastUatTag - else - puts "Tagging current branch for deployment to uat as '#{newUatTag}'" - system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag}" - end return newUatTag end @@ -198,20 +184,42 @@ def staging_to_uat(promoteToUatTag) puts "promoting staging tag #{promoteToUatTag} to uat as '#{newUatTag}'" system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" return newUatTag - end + end desc "Mark the current code as a uat release" task :tag_uat do promoteToUatTag = configuration[:tag] - #if the user inputs a -s tag=staging ... if promoteToUatTag - newUatTag = staging_to_uat(promoteToUatTag) + #if the user inputs -s tag=staging.... + raise "Staging tag required; use '-s tag=staging-YYYY-MM-DD.X'" unless promoteToUatTag =~ /staging-.*/ + raise "Staging Tag #{promoteToUatTag} does not exist." unless last_tag_matching(promoteToUatTag) + promoteToUatTag =~ /staging-([0-9]{4}-[0-9]{2}-[0-9]{2}\.[0-9]*)/ + end + + lastUatTag = last_tag_matching("uat-#{Date.today.to_s}.*") + + newUatTag = generate_uat_tag + shaOfCurrentCheckout = `git log --pretty=format:%H HEAD -1` + shaOfLastUatTag = nil + + if lastUatTag + shaOfLastUatTag = `git log --pretty=format:%H #{lastUatTag} -1` + end + + if shaOfLastUatTag == shaOfCurrentCheckout + puts "Not re-tagging uat because the most recent tag (#{lastUatTag}) already points to current head" + newUatTag = lastUatTag + elsif promoteToUatTag + # if there was a staging tag... + puts "Tagging current branch for deployment to uat as '#{newUatTag}'" + system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag} #{promoteToUatTag}" else - newUatTag = generate_uat_tag + # there was no staging tag --> we generated a new uat tag + puts "Tagging current branch for deployment to uat as '#{newUatTag}'" + system "git tag -a -m 'tagging current code for deployment to uat' #{newUatTag}" end set :branch, newUatTag - end - + end desc "Push the passed staging tag to production. Pass in tag to deploy with '-s tag=staging-YYYY-MM-DD.X'." task :tag_production do