class Publisher::Uploaders::S3

Report upload to AWS S3 bucket

Private Instance Methods

client() click to toggle source

S3 client

@return [Aws::S3::Client]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 13
      def client
        @client ||= Aws::S3::Client.new(client_args)
      rescue Aws::Sigv4::Errors::MissingCredentialsError
        raise(<<~MSG.strip)
          missing aws credentials, provide credentials with one of the following options:
            - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
            - ~/.aws/credentials file
        MSG
      end
client_args() click to toggle source
# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 23
def client_args
  @client_args ||= {
    region: ENV["AWS_REGION"] || "us-east-1",
    force_path_style: ENV["AWS_FORCE_PATH_STYLE"] == "true",
    endpoint: ENV["AWS_ENDPOINT"]
  }.compact
end
download_history() click to toggle source

Add allure history

@return [void]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 48
def download_history
  HISTORY.each do |file|
    client.get_object(
      response_target: path(results_path, "history", file),
      key: key(prefix, "history", file),
      bucket: bucket_name
    )
  end
rescue Aws::S3::Errors::NoSuchKey
  raise(HistoryNotFoundError, "Allure history from previous runs not found!")
end
key(*args) click to toggle source

Fabricate key for s3 object

@param [String] *args @return [String]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 102
def key(*args)
  args.compact.join("/")
end
latest_report_url() click to toggle source

Latest report url

@return [String]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 41
def latest_report_url
  @latest_report_url ||= url(prefix)
end
report_url() click to toggle source

Report url

@return [String]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 34
def report_url
  @report_url ||= url(full_prefix)
end
upload_history() click to toggle source

Upload allure history

@return [void]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 63
def upload_history
  upload_to_s3(report_files.select { |file| file.fnmatch?("*/history/*") }, prefix)
end
upload_latest_copy() click to toggle source

Upload copy of latest run

@return [void]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 77
def upload_latest_copy
  upload_to_s3(report_files, prefix)
end
upload_report() click to toggle source

Upload allure report

@return [void]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 70
def upload_report
  upload_to_s3(report_files, full_prefix)
end
upload_to_s3(files, key_prefix) click to toggle source

Upload files to s3

@param [Array<Pathname>] files @param [String] key_prefix @return [Array<Hash>]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 86
def upload_to_s3(files, key_prefix)
  args = files.map do |file|
    {
      body: File.new(file),
      bucket: bucket_name,
      key: key(key_prefix, file.relative_path_from(report_path))
    }
  end

  Parallel.each(args, in_threads: 8) { |obj| client.put_object(obj) }
end
url(path_prefix) click to toggle source

Report url

@param [String] path_prefix @return [String]

# File lib/allure_report_publisher/lib/uploaders/s3.rb, line 110
def url(path_prefix)
  ["http://#{bucket_name}.s3.amazonaws.com", path_prefix, "index.html"].compact.join("/")
end