<commit_before>fiftyfive_recipe :dotenv do
  during "provision", "update"
  prior_to "deploy:publishing", "update"
end

namespace :fiftyfive do
  namespace :dotenv do
    desc "Replace/create .env file with values provided at console"
    task :replace do
      set_up_secret_prompts

      on release_roles(:all) do
        update_dotenv_file
      end
    end

    desc "Update .env file with any missing values"
    task :update do
      set_up_secret_prompts

      on release_roles(:all) do
        existing_env = capture("cat #{shared_dotenv_path} || echo")
        update_dotenv_file(existing_env)
      end
    end

    def shared_dotenv_path
      "#{shared_path}/.env"
    end

    def set_up_secret_prompts
      fetch(:fiftyfive_dotenv_keys).each { |k| ask_secretly(k) }
    end

    def update_dotenv_file(existing="")
      updated = existing.dup

      fetch(:fiftyfive_dotenv_keys).each do |key|
        next if existing =~ /^#{Regexp.escape(key.upcase)}=/
        fetch(:fiftyfive_dotenv_monitor).synchronize do
          updated << "#{key.upcase}=#{fetch(key)}\n"
        end
      end

      unless existing == updated
        put(updated, shared_dotenv_path, :mode => "600")
      end
    end
  end
end<commit_msg>Ensure each key is preceeded by a newline<commit_after>fiftyfive_recipe :dotenv do
  during "provision", "update"
  prior_to "deploy:publishing", "update"
end

namespace :fiftyfive do
  namespace :dotenv do
    desc "Replace/create .env file with values provided at console"
    task :replace do
      set_up_secret_prompts

      on release_roles(:all) do
        update_dotenv_file
      end
    end

    desc "Update .env file with any missing values"
    task :update do
      set_up_secret_prompts

      on release_roles(:all) do
        existing_env = capture("cat #{shared_dotenv_path} || echo")
        update_dotenv_file(existing_env)
      end
    end

    def shared_dotenv_path
      "#{shared_path}/.env"
    end

    def set_up_secret_prompts
      fetch(:fiftyfive_dotenv_keys).each { |k| ask_secretly(k) }
    end

    def update_dotenv_file(existing="")
      updated = existing.dup

      fetch(:fiftyfive_dotenv_keys).each do |key|
        next if existing =~ /^#{Regexp.escape(key.upcase)}=/
        fetch(:fiftyfive_dotenv_monitor).synchronize do
          updated << "\n" unless updated.end_with?("\n")
          updated << "#{key.upcase}=#{fetch(key)}\n"
        end
      end

      unless existing == updated
        put(updated, shared_dotenv_path, :mode => "600")
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0963572267920094, 'fraction_numerical': 0.0023501762632197414, 'mean_word_length': 2.7558823529411764, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6517927', 'n_tokens_mistral': 841, 'n_tokens_neox': 822, 'n_words': 200}