Skip to content

Instantly share code, notes, and snippets.

@andrewdavidcostello
Created August 7, 2014 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewdavidcostello/38c0458a319a9dddb066 to your computer and use it in GitHub Desktop.
Save andrewdavidcostello/38c0458a319a9dddb066 to your computer and use it in GitHub Desktop.
codebase-capistrano-3-task
namespace :codebase do
desc "Logs the deployment of your Codebase 4 repository"
task :log_deployment do
previous_revision = fetch :previous_revision
current_revision = fetch :current_revision
if previous_revision == current_revision
puts "\e[31m The old revision & new revision are the same - you didn't deploy anything new. Skipping logging.\e[0m"
next
end
cmd = ["cb deploy #{previous_revision or "0000000000000000000000000000000000000000"} #{current_revision}"]
if respond_to?(:environment)
set :environment, environment
elsif respond_to?(:rails_env)
set :environment, rails_env
end
branch = fetch :branch
roles = fetch :roles
stage = fetch :stage
app = fetch :application
cmd << "-s #{app}"
cmd << "-b #{branch}"
cmd << "-e #{stage}"
## get the repo and project name etc...
account, project, repo = nil, nil, nil
case fetch(:repo_url)
when /git\@codebasehq.com\:(.+)\/(.+)\/(.+)\.git\z/
account, project, repo = $1, $2, $3
when /ssh:\/\/.+\@codebasehq.com\/(.+)\/(.+)\/(.+)\.hg\z/
account, project, repo = $1, $2, $3
when /https?:\/\/.+\@(.+)\.codebasehq.com\/(.+)\/(.+)\.(?:hg|svn)\z/
account, project, repo = $1, $2, $3
when /https?:\/\/(?:.+\@)?(.+)\.svn\.codebasehq.com\/(.+?)\/(.+?)(?:\/.*)\z/
account, project, repo = $1, $2, $3
else
puts "! Repository path not supported by deployment logging"
next
end
cmd << "-r #{project}:#{repo}"
cmd << "-h #{account}.codebasehq.com"
cmd << "--protocol https"
run_locally do
execute cmd.join(' ') + "; true"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment