<commit_before># A lot of this taken from GitHub's deployment:
# http://github.com/blog/470-deployment-script-spring-cleaning

# Overwrite cap defaults
set :use_sudo, false
set :deploy_via, :git # not used
set :shared_children, %w[] # not relevant
set(:rails_env) { environment } ## some built-in tasks use :rails_env
default_run_options[:pty] = true

# Setup basics
_cset :user, 'deploy'
_cset(:group) { user }
_cset :environment, 'production'
_cset :required_children, %w[config log public tmp/pids]

# Server basics
_cset :server_processes, 2
_cset :server_port, 8000

# Use one directory for everything
set(:current_path)    { fetch(:deploy_to)    }
set(:latest_release)  { fetch(:current_path) }
set(:release_path)    { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }
set(:shared_path)     { fetch(:current_path) }

# Behold, the power of git
set(:current_revision) {
  capture("cd #{current_path}; git rev-parse --short HEAD").strip
}
set(:latest_revision)   {
  capture("cd #{current_path}; git rev-parse --short HEAD").strip
}
set(:previous_revision) {
  capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip
}

###########
## Tasks ##
###########

namespace :deploy do
  [:default, :cleanup, :symlink].each do |t|
    task t do
      abort "Task disabled by caplets."
    end
  end
  [:enable, :disable].each do |t|
    namespace :web do
      task t do
        abort "Task disabled by caplets. Load 'caplets/web' to re-enable."
      end
    end
  end

  desc "Setup a Git-based deploy"
  task :setup, :except => {:no_release => true} do
    run_multi(
      "if [ -d #{fetch(:current_path)}/.git ]",
      "then cd #{fetch(:current_path)}",
      "#{try_sudo} git fetch",
      "else #{try_sudo} git clone #{fetch(:repository)} #{fetch(:current_path)}",
      "fi",
      "mkdir -p " + fetch(:required_children,[]).
                      map {|dir| "#{fetch(:current_path)}/#{dir}" }.
                      join(' ')
    )
  end

  desc <<-DESC
  Do a zero-downtime deploy.

  Use this when you have small code changes that you want to go out with
  minimal impact. This does not put up the maintanance page nor run migrations,
  and  will tell your app servers to 'reload' in-place instead of restarting
  completely if they support it.
  DESC
  task :quick do
    update
    reload
  end

  task :update do
    update_code
  end

  desc "Update the deployed code from git"
  task :update_code, :except => { :no_release => true } do
    run_multi "cd #{fetch(:current_path)}",
      "git fetch origin",
      "git reset --hard #{fetch(:branch)}"
    finalize_update
  end
<commit_msg>Use && instead of ; to bomb if fetch/clone fails.<commit_after># A lot of this taken from GitHub's deployment:
# http://github.com/blog/470-deployment-script-spring-cleaning

# Overwrite cap defaults
set :use_sudo, false
set :deploy_via, :git # not used
set :shared_children, %w[] # not relevant
set(:rails_env) { environment } ## some built-in tasks use :rails_env
default_run_options[:pty] = true

# Setup basics
_cset :user, 'deploy'
_cset(:group) { user }
_cset :environment, 'production'
_cset :required_children, %w[config log public tmp/pids]

# Server basics
_cset :server_processes, 2
_cset :server_port, 8000

# Use one directory for everything
set(:current_path)    { fetch(:deploy_to)    }
set(:latest_release)  { fetch(:current_path) }
set(:release_path)    { fetch(:current_path) }
set(:current_release) { fetch(:current_path) }
set(:shared_path)     { fetch(:current_path) }

# Behold, the power of git
set(:current_revision) {
  capture("cd #{current_path}; git rev-parse --short HEAD").strip
}
set(:latest_revision)   {
  capture("cd #{current_path}; git rev-parse --short HEAD").strip
}
set(:previous_revision) {
  capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip
}

###########
## Tasks ##
###########

namespace :deploy do
  [:default, :cleanup, :symlink].each do |t|
    task t do
      abort "Task disabled by caplets."
    end
  end
  [:enable, :disable].each do |t|
    namespace :web do
      task t do
        abort "Task disabled by caplets. Load 'caplets/web' to re-enable."
      end
    end
  end

  desc "Setup a Git-based deploy"
  task :setup, :except => {:no_release => true} do
    run "if [ -d #{fetch(:current_path)}/.git ] ; "+
        "then cd #{fetch(:current_path)} && #{try_sudo} git fetch ; "+
        "else #{try_sudo} git clone #{fetch(:repository)} #{fetch(:current_path)} ; "+
        "fi && "+
        "mkdir -p " + fetch(:required_children,[]).
                        map {|dir| "#{fetch(:current_path)}/#{dir}" }.
                        join(' ')
    )
  end

  desc <<-DESC
  Do a zero-downtime deploy.

  Use this when you have small code changes that you want to go out with
  minimal impact. This does not put up the maintanance page nor run migrations,
  and  will tell your app servers to 'reload' in-place instead of restarting
  completely if they support it.
  DESC
  task :quick do
    update
    reload
  end

  task :update do
    update_code
  end

  desc "Update the deployed code from git"
  task :update_code, :except => { :no_release => true } do
    run_multi "cd #{fetch(:current_path)}",
      "git fetch origin",
      "git reset --hard #{fetch(:branch)}"
    finalize_update
  end

{'fraction_non_alphanumeric': 0.1394647568790049, 'fraction_numerical': 0.003392385978137957, 'mean_word_length': 3.3679012345679014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1837591', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1688, 'n_words': 537}