Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/krausefx/sigh
Browse files Browse the repository at this point in the history
  • Loading branch information
KrauseFx committed Feb 2, 2016
2 parents db73b27 + 5db9f5e commit 9e88528
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 73 deletions.
8 changes: 4 additions & 4 deletions lib/sigh/download_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ module Sigh
class DownloadAll
# Download all valid provisioning profiles
def download_all
Helper.log.info "Starting login with user '#{Sigh.config[:username]}'"
UI.message "Starting login with user '#{Sigh.config[:username]}'"
Spaceship.login(Sigh.config[:username], nil)
Spaceship.select_team
Helper.log.info "Successfully logged in"
UI.message "Successfully logged in"

Spaceship.provisioning_profile.all.each do |profile|
if profile.valid?
Helper.log.info "Downloading profile '#{profile.name}'...".green
UI.message "Downloading profile '#{profile.name}'..."
download_profile(profile)
else
Helper.log.info "Skipping invalid/expired profile '#{profile.name}'".yellow
UI.important "Skipping invalid/expired profile '#{profile.name}'"
end
end
end
Expand Down
48 changes: 23 additions & 25 deletions lib/sigh/local_manage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.start(options, args)
end

def self.install_profile(profile)
Helper.log.info "Installing provisioning profile..."
UI.message "Installing provisioning profile..."
profile_path = File.expand_path("~") + "/Library/MobileDevice/Provisioning Profiles/"
profile_filename = ENV["SIGH_UDID"] + ".mobileprovision"
destination = profile_path + profile_filename
Expand All @@ -27,9 +27,9 @@ def self.install_profile(profile)
FileUtils.copy profile, destination

if File.exist? destination
Helper.log.info "Profile installed at \"#{destination}\""
UI.success "Profile installed at \"#{destination}\""
else
raise "Failed installation of provisioning profile at location: #{destination}".red
UI.user_error!("Failed installation of provisioning profile at location: #{destination}")
end
end

Expand All @@ -40,7 +40,6 @@ def self.get_inputs(options, _args)
return command, clean_expired, clean_pattern
end

# rubocop:disable Metrics/AbcSize
def self.list_profiles
profiles = load_profiles

Expand All @@ -49,62 +48,61 @@ def self.list_profiles

profiles_valid = profiles.select { |profile| profile["ExpirationDate"] > now && profile["ExpirationDate"] > soon }
if profiles_valid.count > 0
Helper.log.info "Provisioning profiles installed"
Helper.log.info "Valid:"
UI.message "Provisioning profiles installed"
UI.message "Valid:"
profiles_valid.each do |profile|
Helper.log.info profile["Name"].green
UI.message profile["Name"].green
end
end

profiles_soon = profiles.select { |profile| profile["ExpirationDate"] > now && profile["ExpirationDate"] < soon }
if profiles_soon.count > 0
Helper.log.info ""
Helper.log.info "Expiring within 30 day:"
UI.message ""
UI.message "Expiring within 30 day:"
profiles_soon.each do |profile|
Helper.log.info profile["Name"].yellow
UI.message profile["Name"].yellow
end
end

profiles_expired = profiles.select { |profile| profile["ExpirationDate"] < now }
if profiles_expired.count > 0
Helper.log.info ""
Helper.log.info "Expired:"
UI.message ""
UI.message "Expired:"
profiles_expired.each do |profile|
Helper.log.info profile["Name"].red
UI.message profile["Name"].red
end
end

Helper.log.info ""
Helper.log.info "Summary"
Helper.log.info "#{profiles.count} installed profiles"
Helper.log.info "#{profiles_expired.count} are expired".red
Helper.log.info "#{profiles_soon.count} are valid but will expire within 30 days".yellow
Helper.log.info "#{profiles_valid.count} are valid".green
UI.message ""
UI.message "Summary"
UI.message "#{profiles.count} installed profiles"
UI.message "#{profiles_expired.count} are expired".red
UI.message "#{profiles_soon.count} are valid but will expire within 30 days".yellow
UI.message "#{profiles_valid.count} are valid".green

Helper.log.info "You can remove all expired profiles using `sigh manage -e`" if profiles_expired.count > 0
UI.message "You can remove all expired profiles using `sigh manage -e`" if profiles_expired.count > 0
end
# rubocop:enable Metrics/AbcSize

def self.cleanup_profiles(expired = false, pattern = nil)
now = DateTime.now

profiles = load_profiles.select { |profile| (expired && profile["ExpirationDate"] < now) || (!pattern.nil? && profile["Name"] =~ pattern) }

Helper.log.info "The following provisioning profiles are either expired or matches your pattern:"
UI.message "The following provisioning profiles are either expired or matches your pattern:"
profiles.each do |profile|
Helper.log.info profile["Name"].red
UI.message profile["Name"].red
end

if agree("Delete these provisioning profiles #{profiles.length}? (y/n) ", true)
profiles.each do |profile|
File.delete profile["Path"]
end
Helper.log.info "\n\nDeleted #{profiles.length} profiles".green
UI.success "\n\nDeleted #{profiles.length} profiles"
end
end

def self.load_profiles
Helper.log.info "Loading Provisioning profiles from ~/Library/MobileDevice/Provisioning Profiles/"
UI.message "Loading Provisioning profiles from ~/Library/MobileDevice/Provisioning Profiles/"
profiles_path = File.expand_path("~") + "/Library/MobileDevice/Provisioning Profiles/*.mobileprovision"
profile_paths = Dir[profiles_path]

Expand Down
2 changes: 1 addition & 1 deletion lib/sigh/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def self.available_options
optional: true,
description: "Filename to use for the generated provisioning profile (must include .mobileprovision)",
verify_block: proc do |value|
raise "The output name must end with .mobileprovision".red unless value.end_with? ".mobileprovision"
UI.user_error!("The output name must end with .mobileprovision") unless value.end_with?(".mobileprovision")
end),
FastlaneCore::ConfigItem.new(key: :skip_fetch_profiles,
env_name: "SIGH_SKIP_FETCH_PROFILES",
Expand Down
12 changes: 6 additions & 6 deletions lib/sigh/repair.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
module Sigh
class Repair
def repair_all
Helper.log.info "Starting login with user '#{Sigh.config[:username]}'"
UI.message "Starting login with user '#{Sigh.config[:username]}'"
Spaceship.login(Sigh.config[:username], nil)
Spaceship.select_team
Helper.log.info "Successfully logged in"
UI.message "Successfully logged in"

# Select all 'Invalid' or 'Expired' provisioning profiles
broken_profiles = Spaceship.provisioning_profile.all.find_all do |profile|
(profile.status == "Invalid" or profile.status == "Expired")
end

if broken_profiles.count == 0
Helper.log.info "All provisioning profiles are valid, nothing to do".green
UI.success "All provisioning profiles are valid, nothing to do"
return
end

Helper.log.info "Going to repair #{broken_profiles.count} provisioning profiles".green
UI.success "Going to repair #{broken_profiles.count} provisioning profiles"

# Iterate over all broken profiles and repair them
broken_profiles.each do |profile|
Helper.log.info "Repairing profile '#{profile.name}'..."
UI.message "Repairing profile '#{profile.name}'..."
profile.repair! # yes, that's all you need to repair a profile
end

Helper.log.info "Successfully repaired #{broken_profiles.count} provisioning profiles".green
UI.success "Successfully repaired #{broken_profiles.count} provisioning profiles"
end
end
end
16 changes: 9 additions & 7 deletions lib/sigh/resign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def resign(ipa, signing_identity, provisioning_profiles, entitlements)
puts `#{command}`

if $?.to_i == 0
Helper.log.info "Successfully signed #{ipa}!".green
UI.success "Successfully signed #{ipa}!"
true
else
Helper.log.fatal "Something went wrong while code signing #{ipa}".red
UI.error "Something went wrong while code signing #{ipa}"
false
end
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def find_entitlements

def find_signing_identity(signing_identity)
until installed_identies.include?(signing_identity)
Helper.log.error "Couldn't find signing identity '#{signing_identity}'."
UI.error "Couldn't find signing identity '#{signing_identity}'."
signing_identity = ask_for_signing_identity
end

Expand All @@ -90,19 +90,21 @@ def validate_params(resign_path, ipa, provisioning_profiles)
end

def validate_resign_path(resign_path)
raise 'Could not find resign.sh file. Please try re-installing the gem.'.red unless File.exist?(resign_path)
UI.user_error!('Could not find resign.sh file. Please try re-installing the gem') unless File.exist?(resign_path)
end

def validate_ipa_file(ipa)
raise "ipa file could not be found or is not an ipa file (#{ipa})".red unless File.exist?(ipa) && ipa.end_with?('.ipa')
UI.user_error!("ipa file could not be found or is not an ipa file (#{ipa})") unless File.exist?(ipa) && ipa.end_with?('.ipa')
end

def validate_provisioning_file(provisioning_profile)
raise "Provisioning profile file could not be found or is not a .mobileprovision file (#{provisioning_profile})".red unless File.exist?(provisioning_profile) && provisioning_profile.end_with?('.mobileprovision')
unless File.exist?(provisioning_profile) && provisioning_profile.end_with?('.mobileprovision')
UI.user_error!("Provisioning profile file could not be found or is not a .mobileprovision file (#{provisioning_profile})")
end
end

def print_available_identities
Helper.log.info "Available identities: \n\t#{installed_identies.join("\n\t")}\n"
UI.message "Available identities: \n\t#{installed_identies.join("\n\t")}\n"
end

def ask_for_signing_identity
Expand Down
58 changes: 29 additions & 29 deletions lib/sigh/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ def run
hide_keys: [:output_path],
title: "Summary for sigh #{Sigh::VERSION}")

Helper.log.info "Starting login with user '#{Sigh.config[:username]}'"
UI.message "Starting login with user '#{Sigh.config[:username]}'"
Spaceship.login(Sigh.config[:username], nil)
Spaceship.select_team
Helper.log.info "Successfully logged in"
UI.message "Successfully logged in"

profiles = [] if Sigh.config[:skip_fetch_profiles]
profiles ||= fetch_profiles # download the profile if it's there

if profiles.count > 0
Helper.log.info "Found #{profiles.count} matching profile(s)".yellow
UI.success "Found #{profiles.count} matching profile(s)"
profile = profiles.first

if Sigh.config[:force]
if profile_type == Spaceship.provisioning_profile::AppStore or profile_type == Spaceship.provisioning_profile::InHouse
Helper.log.info "Updating the provisioning profile".yellow
UI.important "Updating the provisioning profile"
else
Helper.log.info "Updating the profile to include all devices".yellow
UI.important "Updating the profile to include all devices"
profile.devices = Spaceship.device.all_for_profile_type(profile.type)
end

profile = profile.update! # assign it, as it's a new profile
end
else
Helper.log.info "No existing profiles found, that match the certificates you have installed, creating a new one for you".yellow
UI.important "No existing profiles found, that match the certificates you have installed, creating a new one for you"
ensure_app_exists!
profile = create_profile!
end

raise "Something went wrong fetching the latest profile".red unless profile
UI.user_error!("Something went wrong fetching the latest profile") unless profile

if profile_type == Spaceship.provisioning_profile.in_house
ENV["SIGH_PROFILE_ENTERPRISE"] = "1"
Expand All @@ -64,7 +64,7 @@ def profile_type

# Fetches a profile matching the user's search requirements
def fetch_profiles
Helper.log.info "Fetching profiles..."
UI.message "Fetching profiles..."
results = profile_type.find_by_bundle_id(Sigh.config[:app_identifier]).find_all(&:valid?)

# Take the provisioning profile name into account
Expand Down Expand Up @@ -100,12 +100,12 @@ def create_profile!

unless Sigh.config[:skip_fetch_profiles]
if Spaceship.provisioning_profile.all.find { |p| p.name == name }
Helper.log.error "The name '#{name}' is already taken, using another one."
UI.error "The name '#{name}' is already taken, using another one."
name += " #{Time.now.to_i}"
end
end

Helper.log.info "Creating new provisioning profile for '#{Sigh.config[:app_identifier]}' with name '#{name}'".yellow
UI.important "Creating new provisioning profile for '#{Sigh.config[:app_identifier]}' with name '#{name}'"
profile = profile_type.create!(name: name,
bundle_id: bundle_id,
certificate: cert)
Expand Down Expand Up @@ -137,20 +137,20 @@ def certificate_to_use
end

if certificates.count > 1 and !Sigh.config[:development]
Helper.log.info "Found more than one code signing identity. Choosing the first one. Check out `sigh --help` to see all available options.".yellow
Helper.log.info "Available Code Signing Identities for current filters:".green
UI.important "Found more than one code signing identity. Choosing the first one. Check out `sigh --help` to see all available options."
UI.important "Available Code Signing Identities for current filters:"
certificates.each do |c|
str = ["\t- Name:", c.owner_name, "- ID:", c.id + "- Expires", c.expires.strftime("%d/%m/%Y")].join(" ")
Helper.log.info str.green
UI.message str.green
end
end

if certificates.count == 0
filters = ""
filters << "Owner Name: '#{Sigh.config[:cert_owner_name]}' " if Sigh.config[:cert_owner_name]
filters << "Certificate ID: '#{Sigh.config[:cert_id]}' " if Sigh.config[:cert_id]
Helper.log.info "No certificates for filter: #{filters}".yellow if filters.length > 0
raise "Could not find a matching code signing identity for #{profile_type}. You can use cert to generate one (https://github.com/fastlane/cert)".red
UI.important "No certificates for filter: #{filters}" if filters.length > 0
UI.user_error!("Could not find a matching code signing identity for #{profile_type}. You can use cert to generate one (https://github.com/fastlane/cert)")
end

return certificates if Sigh.config[:development] # development profiles support multiple certificates
Expand All @@ -160,7 +160,7 @@ def certificate_to_use

# Downloads and stores the provisioning profile
def download_profile(profile)
Helper.log.info "Downloading provisioning profile...".yellow
UI.important "Downloading provisioning profile..."
profile_name ||= "#{profile.class.pretty_type}_#{Sigh.config[:app_identifier]}.mobileprovision" # default name
profile_name += '.mobileprovision' unless profile_name.include? 'mobileprovision'

Expand All @@ -170,29 +170,29 @@ def download_profile(profile)
f.write(profile.download)
end

Helper.log.info "Successfully downloaded provisioning profile...".green
UI.success "Successfully downloaded provisioning profile..."
return output_path
end

# Makes sure the current App ID exists. If not, it will show an appropriate error message
def ensure_app_exists!
return if Spaceship::App.find(Sigh.config[:app_identifier])
print_produce_command(Sigh.config)
raise "Could not find App with App Identifier '#{Sigh.config[:app_identifier]}'"
UI.user_error!("Could not find App with App Identifier '#{Sigh.config[:app_identifier]}'")
end

def print_produce_command(config)
Helper.log.info ""
Helper.log.info "==========================================".yellow
Helper.log.info "Could not find App ID with bundle identifier '#{config[:app_identifier]}'"
Helper.log.info "You can easily generate a new App ID on the Developer Portal using 'produce':"
Helper.log.info ""
Helper.log.info "produce -u #{config[:username]} -a #{config[:app_identifier]} --skip_itc".yellow
Helper.log.info ""
Helper.log.info "You will be asked for any missing information, like the full name of your app"
Helper.log.info "If the app should also be created on iTunes Connect, remove the " + "--skip_itc".yellow + " from the command above"
Helper.log.info "==========================================".yellow
Helper.log.info ""
UI.message ""
UI.message "==========================================".yellow
UI.message "Could not find App ID with bundle identifier '#{config[:app_identifier]}'"
UI.message "You can easily generate a new App ID on the Developer Portal using 'produce':"
UI.message ""
UI.message "produce -u #{config[:username]} -a #{config[:app_identifier]} --skip_itc".yellow
UI.message ""
UI.message "You will be asked for any missing information, like the full name of your app"
UI.message "If the app should also be created on iTunes Connect, remove the " + "--skip_itc".yellow + " from the command above"
UI.message "==========================================".yellow
UI.message ""
end
end
end
2 changes: 1 addition & 1 deletion sigh.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency 'fastlane_core', '>= 0.30.0', '< 1.0.0' # all shared code and dependencies
spec.add_dependency 'fastlane_core', '>= 0.36.1', '< 1.0.0' # all shared code and dependencies
spec.add_dependency 'plist', '~> 3.1' # for reading the provisioning profile
spec.add_dependency 'spaceship', '>= 0.12.3' # communication with Apple

Expand Down

0 comments on commit 9e88528

Please sign in to comment.