Created
October 11, 2012 00:43
-
-
Save kmayer/3869451 to your computer and use it in GitHub Desktop.
Heroku_San AutoTagger sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extensions to heroku_san tasks | |
# Never runs on Heroku | |
if Rails.env.development? | |
STAGES = %w[ci acceptance staging production] | |
require 'auto_tagger' | |
def create_and_push(stage) | |
auto_tag = AutoTagger::Base.new(stages: STAGES, stage: stage, verbose: true, push_refs: false, refs_to_keep: 100) | |
auto_tag.delete_on_remote | |
auto_tag.delete_locally | |
tag = auto_tag.create_ref(auto_tag.last_ref_from_previous_stage.try(:sha)) | |
sh "git push origin #{tag.name}" | |
end | |
task :before_deploy do | |
sh 'git fetch --tags' | |
each_heroku_app do |stage| | |
sh "heroku pgbackups:capture --app #{stage.app}" if stage.name.in?(%w[staging production]) | |
end | |
end | |
task :after_deploy do | |
each_heroku_app do |stage| | |
create_and_push(stage.name) | |
revision = stage.revision.split.first | |
stage.push_config('GIT_SHA' => revision) if revision | |
end | |
Rake::Task['autotag:list'].invoke | |
end | |
namespace :autotag do | |
desc "Create an autotag for stage, default #{STAGES.first}" | |
task :create, :stage do |t, args| | |
create_and_push(args[:stage] || STAGES.first) | |
end | |
desc "Show auto tagger history" | |
task :list do | |
puts "*** AUTO TAGGER release tags ***" | |
auto_tag = AutoTagger::Base.new(stages: STAGES) | |
STAGES.each do |stage| | |
ref = auto_tag.refs_for_stage(stage).last | |
if ref | |
log = %x{git log -1 --format=oneline #{ref.sha}}.chomp | |
log = log[0..5] + log[40..-1] | |
else | |
log = "none" | |
end | |
puts " ** %-12s %s" % [stage, log] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment