Top Level Namespace

Defined Under Namespace

Modules: AppcastXML, AutoSparkle, BuildDirectory, Command, Constants, DMG, Distribution, Env, Packaging, Storage, Version, Xcodeproj Classes: AwsS3EnvironmentVariables, AwsS3Storage, BaseEnvironmentVariables, DefaultEnvironmentVariables

Instance Method Summary collapse

Instance Method Details

#execute_command(command, contains_sensitive_data: false) ⇒ Object

This method executes a command and returns the output It raises an error if the command fails



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/autosparkle/helpers/commands_helpers.rb', line 11

def execute_command(command, contains_sensitive_data: false)
  # if the command has --password, --secret then replace it with *****
  presented_command = command.gsub(/(--password|--secret) \S+/, '\1 *****')

  puts "\n#{presented_command}\n".cyan if Env.verbose_enabled && !contains_sensitive_data
  stdout, stderr, status = Open3.capture3(command)

  # if status is not success
  unless status.success?
    puts "\nCommand failed: #{command}\n".red
    puts "\nError: #{stderr}\n".red
    raise
  end

  puts "#{stdout}\n\n".magenta if Env.verbose_enabled && !contains_sensitive_data

  stdout
end

#puts_error(message) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/autosparkle/helpers/puts_helpers.rb', line 10

def puts_error(message)
  if message.is_a?(Array)
    puts message.map(&:red).join("\n")
  else
    puts message.red
  end
end

#puts_if_verbose(message) ⇒ Object



6
7
8
# File 'lib/autosparkle/helpers/puts_helpers.rb', line 6

def puts_if_verbose(message)
  puts message if Env.verbose_enabled
end

#puts_title(message) ⇒ Object



18
19
20
# File 'lib/autosparkle/helpers/puts_helpers.rb', line 18

def puts_title(message)
  puts "\n🔷 #{message} ...\n".yellow
end

#with_temporary_keychainObject

Execute the given block with a temporary keychain, The block will receive the application certificate name and team id as arguments. The temporary keychain will be deleted after the block has been executed.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/autosparkle/helpers/keychain_helpers.rb', line 16

def with_temporary_keychain
  original_keychain_list = `security list-keychains`.strip.split("\n").map(&:strip)
  default_keychain = execute_command('security default-keychain')
  default_keychain_path = default_keychain.gsub(/"(.*)"/, '\1').strip

  delete_temporary_keychain_if_needed

  begin
    # Create a temporary keychain
    create_temporary_keychain(original_keychain_list)
    import_certificates_in_temporary_keychain
    execute_command("security set-key-partition-list -S apple-tool:,apple:,codesign: \\
                  -s -k \"#{Constants::KEYCHAIN_PASSWORD}\" #{Constants::KEYCHAIN_PATH}")

    # Fetch the certificate names and team ids from the temporary keychain
    application_cert_name, application_team_id = fetch_application_certificate_info
    store_notarization_credentials(application_team_id)

    keychain_info = {
      application_cert_name: application_cert_name,
      application_team_id: application_team_id
    }
    yield(keychain_info) if block_given?
  ensure
    puts_if_verbose 'Ensuring cleanup of temporary keychain...'
    delete_temporary_keychain_if_needed

    # Reset the keychain to the default
    execute_command("security list-keychains -s #{original_keychain_list.join(' ')}")
    execute_command("security default-keychain -s \"#{default_keychain_path}\"")
  end
end