<commit_before>#! /usr/bin/env ruby

require 'csv'
require 'fog'
require './fogpatch.rb' # patch for Elastic Beanstalk errors.

# stick your standard Amazon creds in the main project directory.
creds = CSV.read('../credentials.csv', :headers => true)[0]

KEY = creds['Access Key Id']
SECRET = creds['Secret Access Key']

APPNAME = "Swarmize-Mock"
LIVE_ENV = "Swarmize-Mock-Live"
S3_BUCKET = "swarmize-mock"

currentrev = `git log --pretty=format:'%h' -n 1`
package_filename = "package-#{currentrev}.zip"
package_version = "package-#{currentrev}"

s3 = Fog::Storage.new({
  :provider                 => 'AWS',
  :aws_access_key_id        => KEY,
  :aws_secret_access_key    => SECRET,
  :path_style => true,
  :region => "eu-west-1"
})

beanstalk = Fog::AWS::ElasticBeanstalk.new({
  :aws_access_key_id        => KEY,
  :aws_secret_access_key    => SECRET,
  :region => "eu-west-1",
})

beanstalk_applications = beanstalk.applications
application = beanstalk_applications.find {|a| a.name == APPNAME}

verison = nil

if application.version_names.include? package_version
  puts "Version already exists, not packaging code."
  version = application.versions.find {|v| v.label == package_version}
else
  puts "Version does not exist, packaging code."
  puts "Removing old packages"
  system "rm package*.zip"

  Dir.chdir("..") do 
    puts "Archiving website to #{package_filename}"
    system "git archive -o mock-website/#{package_filename} master:mock-website"
  end

  puts "Uploading to S3."

  directory = s3.directories.get(S3_BUCKET)
  file = directory.files.create(
    :key    => "package-#{currentrev}.zip",<commit_msg>Stupid typo.<commit_after>#! /usr/bin/env ruby

require 'csv'
require 'fog'
require './fogpatch.rb' # patch for Elastic Beanstalk errors.

# stick your standard Amazon creds in the main project directory.
creds = CSV.read('../credentials.csv', :headers => true)[0]

KEY = creds['Access Key Id']
SECRET = creds['Secret Access Key']

APPNAME = "Swarmize-Mock"
LIVE_ENV = "Swarmize-Mock-Live"
S3_BUCKET = "swarmize-mock"

currentrev = `git log --pretty=format:'%h' -n 1`
package_filename = "package-#{currentrev}.zip"
package_version = "package-#{currentrev}"

s3 = Fog::Storage.new({
  :provider                 => 'AWS',
  :aws_access_key_id        => KEY,
  :aws_secret_access_key    => SECRET,
  :path_style => true,
  :region => "eu-west-1"
})

beanstalk = Fog::AWS::ElasticBeanstalk.new({
  :aws_access_key_id        => KEY,
  :aws_secret_access_key    => SECRET,
  :region => "eu-west-1",
})

beanstalk_applications = beanstalk.applications
application = beanstalk_applications.find {|a| a.name == APPNAME}

version = nil

if application.version_names.include? package_version
  puts "Version already exists, not packaging code."
  version = application.versions.find {|v| v.label == package_version}
else
  puts "Version does not exist, packaging code."
  puts "Removing old packages"
  system "rm package*.zip"

  Dir.chdir("..") do 
    puts "Archiving website to #{package_filename}"
    system "git archive -o mock-website/#{package_filename} master:mock-website"
  end

  puts "Uploading to S3."

  directory = s3.directories.get(S3_BUCKET)
  file = directory.files.create(
    :key    => "package-#{currentrev}.zip",
{'fraction_non_alphanumeric': 0.14101382488479264, 'fraction_numerical': 0.005529953917050691, 'mean_word_length': 4.032457496136012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4474836', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1122, 'n_words': 270}