<commit_before>require 'capistrano/recipes/deploy/strategy/base'

module Capistrano
  module Deploy
    module Strategy

      class Awesome < Base

        def setup!
          run "sudo rm -rf #{configuration[:deploy_to]}"
          run "sudo mkdir -p #{configuration[:deploy_to]} && sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_user]} #{configuration[:deploy_to]}"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git clone #{configuration[:repository]} ."
          run "sudo mkdir -p #{configuration[:deploy_to]}/log && sudo mkdir -p #{configuration[:deploy_to]}/tmp"
          deploy_no_tag
        end

        def check!

        end

        def deploy!
          puts "\n\n### DEPLOY!: Deploying...\n\n"
          unless @tag_created
            create_tag
            @tag_created = true
          end
          get_tag
          deploy_no_tag
        end

        def rollback!
          puts "\n\n### ROLLBACK!: Rolling back...\n\n"
          unless @got_tag
            get_tag
            @got_tag = true
          end
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout ."
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{@tag}"
        end

        def migrate!
          puts "\n\n### MIGRATE!: Migrating...\n\n"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{configuration[:branch]}"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git pull"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} #{configuration[:ruby_bin_dir]}/bundle exec rake db:migrate --trace RAILS_ENV=#{configuration[:rails_env]}"
        end

        def restart!
          puts "\n\n### RESTART!: Restarting the Passengers...\n\n"
          run "sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_group]} #{configuration[:deploy_to]}"
          run "sudo touch #{configuration[:deploy_to]}/tmp/restart.txt"
        end

        protected

          def create_tag
            puts "\n\n### CREATE TAG: Tagging the current version before updating...\n\n"
            @tag = "#{configuration[:application]}_#{Time.now.strftime("%Y%m%d%H%M%S")}"
            run "cd #{configuration[:deploy_to]} &&  sudo -u #{configuration[:sudo_user]} git tag #{@tag}", :roles => :app, :only => { :primary => true }
            run "cd #{configuration[:deploy_to]} &&  sudo -u #{configuration[:sudo_user]} git push --tags", :roles => :app, :only => { :primary => true }
            # Create an empty file with our tag name, so we can easily go grab the tagname for rollback
            run "sudo rm -f #{File.join(configuration[:latest_tag_dir], '*')}"
            run "sudo mkdir -p #{configuration[:latest_tag_dir]}"
            run "sudo touch #{File.join(configuration[:latest_tag_dir], @tag)}"
            puts "\nSetting latest tag as #{@tag}\n"
          end

          def get_tag<commit_msg>fixing up a bundler in migration issue<commit_after>require 'capistrano/recipes/deploy/strategy/base'

module Capistrano
  module Deploy
    module Strategy

      class Awesome < Base

        def setup!
          run "sudo rm -rf #{configuration[:deploy_to]}"
          run "sudo mkdir -p #{configuration[:deploy_to]} && sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_user]} #{configuration[:deploy_to]}"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git clone #{configuration[:repository]} ."
          run "sudo mkdir -p #{configuration[:deploy_to]}/log && sudo mkdir -p #{configuration[:deploy_to]}/tmp"
          deploy_no_tag
        end

        def check!

        end

        def deploy!
          puts "\n\n### DEPLOY!: Deploying...\n\n"
          unless @tag_created
            create_tag
            @tag_created = true
          end
          get_tag
          deploy_no_tag
        end

        def rollback!
          puts "\n\n### ROLLBACK!: Rolling back...\n\n"
          unless @got_tag
            get_tag
            @got_tag = true
          end
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout ."
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{@tag}"
        end

        def migrate!
          puts "\n\n### MIGRATE!: Migrating...\n\n"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git checkout #{configuration[:branch]}"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} git pull"
          rake_command = configuration[:without_bundler] ? "#{configuration[:ruby_bin_dir]}/rake" : "#{configuration[:ruby_bin_dir]}/bundle exec rake"
          run "cd #{configuration[:deploy_to]} && sudo -u #{configuration[:sudo_user]} #{rake_command} db:migrate --trace RAILS_ENV=#{configuration[:rails_env]}"
        end

        def restart!
          puts "\n\n### RESTART!: Restarting the Passengers...\n\n"
          run "sudo chown -R #{configuration[:passenger_user]}:#{configuration[:passenger_group]} #{configuration[:deploy_to]}"
          run "sudo touch #{configuration[:deploy_to]}/tmp/restart.txt"
        end

        protected

          def create_tag
            puts "\n\n### CREATE TAG: Tagging the current version before updating...\n\n"
            @tag = "#{configuration[:application]}_#{Time.now.strftime("%Y%m%d%H%M%S")}"
            run "cd #{configuration[:deploy_to]} &&  sudo -u #{configuration[:sudo_user]} git tag #{@tag}", :roles => :app, :only => { :primary => true }
            run "cd #{configuration[:deploy_to]} &&  sudo -u #{configuration[:sudo_user]} git push --tags", :roles => :app, :only => { :primary => true }
            # Create an empty file with our tag name, so we can easily go grab the tagname for rollback
            run "sudo rm -f #{File.join(configuration[:latest_tag_dir], '*')}"
            run "sudo mkdir -p #{configuration[:latest_tag_dir]}"
            run "sudo touch #{File.join(configuration[:latest_tag_dir], @tag)}"
            puts "\nSetting latest tag as #{@tag}\n"
          end

          def get_tag
{'fraction_non_alphanumeric': 0.14906047686720353, 'fraction_numerical': 0.0, 'mean_word_length': 2.5765104460756634, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7634696', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1801, 'n_words': 483}