Class: Sigh::Runner
- Inherits:
-
Object
- Object
- Sigh::Runner
- Defined in:
- lib/sigh/runner.rb
Instance Attribute Summary collapse
-
#spaceship ⇒ Object
Returns the value of attribute spaceship.
Instance Method Summary collapse
-
#certificate_to_use ⇒ Object
Certificate to use based on the current distribution mode.
-
#create_profile! ⇒ Object
Create a new profile and return it.
-
#download_profile(profile) ⇒ Object
Downloads and stores the provisioning profile.
-
#ensure_app_exists! ⇒ Object
Makes sure the current App ID exists.
-
#fetch_profiles ⇒ Object
Fetches a profile matching the user's search requirements.
- #print_produce_command(config) ⇒ Object
-
#profile_type ⇒ Object
The kind of provisioning profile we're interested in.
-
#run ⇒ Object
Uses the spaceship to create or download a provisioning profile returns the path the newly created provisioning profile (in /tmp usually).
Instance Attribute Details
#spaceship ⇒ Object
Returns the value of attribute spaceship.
5 6 7 |
# File 'lib/sigh/runner.rb', line 5 def spaceship @spaceship end |
Instance Method Details
#certificate_to_use ⇒ Object
Certificate to use based on the current distribution mode
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/sigh/runner.rb', line 142 def certificate_to_use if profile_type == Spaceship.provisioning_profile.Development certificates = Spaceship.certificate.development.all elsif profile_type == Spaceship.provisioning_profile.InHouse certificates = Spaceship.certificate.in_house.all else certificates = Spaceship.certificate.production.all # Ad hoc or App Store end # Filter them certificates = certificates.find_all do |c| if Sigh.config[:cert_id] next unless c.id == Sigh.config[:cert_id].strip end if Sigh.config[:cert_owner_name] next unless c.owner_name.strip == Sigh.config[:cert_owner_name].strip end true end unless Sigh.config[:skip_certificate_verification] certificates = certificates.find_all do |c| file = Tempfile.new('cert') file.write(c.download_raw) file.close FastlaneCore::CertChecker.installed?(file.path) end end if certificates.count > 1 and !Sigh.config[:development] 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(" ") UI. 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] UI.important "No certificates for filter: #{filters}" if filters.length > 0 = "Could not find a matching code signing identity for type '#{profile_type.to_s.split(':').last}'. " += "It is recommended to use match to manage code signing for you, more information on https://codesigning.guide." += "If you don't want to do so, you can also use cert to generate a new one: https://fastlane.tools/cert" UI.user_error!() end return certificates if Sigh.config[:development] # development profiles support multiple certificates return certificates.first end |
#create_profile! ⇒ Object
Create a new profile and return it
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/sigh/runner.rb', line 122 def create_profile! cert = certificate_to_use bundle_id = Sigh.config[:app_identifier] name = Sigh.config[:provisioning_name] || [bundle_id, profile_type.pretty_type].join(' ') unless Sigh.config[:skip_fetch_profiles] if Spaceship.provisioning_profile.all.find { |p| p.name == name } UI.error "The name '#{name}' is already taken, using another one." name += " #{Time.now.to_i}" end end 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) profile end |
#download_profile(profile) ⇒ Object
Downloads and stores the provisioning profile
199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/sigh/runner.rb', line 199 def download_profile(profile) UI.important "Downloading provisioning profile..." profile_name ||= "#{profile_type.pretty_type}_#{Sigh.config[:app_identifier]}.mobileprovision" # default name profile_name += '.mobileprovision' unless profile_name.include? 'mobileprovision' tmp_path = Dir.mktmpdir("profile_download") output_path = File.join(tmp_path, profile_name) File.open(output_path, "wb") do |f| f.write(profile.download) end UI.success "Successfully downloaded provisioning profile..." return output_path end |
#ensure_app_exists! ⇒ Object
Makes sure the current App ID exists. If not, it will show an appropriate error message
215 216 217 218 219 |
# File 'lib/sigh/runner.rb', line 215 def ensure_app_exists! return if Spaceship::App.find(Sigh.config[:app_identifier]) print_produce_command(Sigh.config) UI.user_error!("Could not find App with App Identifier '#{Sigh.config[:app_identifier]}'") end |
#fetch_profiles ⇒ Object
Fetches a profile matching the user's search requirements
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sigh/runner.rb', line 66 def fetch_profiles UI. "Fetching profiles..." results = profile_type.find_by_bundle_id(Sigh.config[:app_identifier]) results = results.find_all do |current_profile| if current_profile.valid? true else UI.("Provisioning Profile '#{current_profile.name}' is not valid, skipping this one...") false end end # Take the provisioning profile name into account if Sigh.config[:provisioning_name].to_s.length > 0 filtered = results.select { |p| p.name.strip == Sigh.config[:provisioning_name].strip } if Sigh.config[:ignore_profiles_with_different_name] results = filtered elsif (filtered || []).count > 0 results = filtered end end # Since September 20, 2016 spaceship doesn't distinguish between AdHoc and AppStore profiles # any more, since it requires an additional request # Instead we only call is_adhoc? on the matching profiles to speed up spaceship results = results.find_all do |current_profile| if profile_type == Spaceship.provisioning_profile.ad_hoc current_profile.is_adhoc? elsif profile_type == Spaceship.provisioning_profile.app_store !current_profile.is_adhoc? else true end end return results if Sigh.config[:skip_certificate_verification] return results.find_all do |a| # Also make sure we have the certificate installed on the local machine installed = false a.certificates.each do |cert| file = Tempfile.new('cert') file.write(cert.download_raw) file.close if FastlaneCore::CertChecker.installed?(file.path) installed = true else UI.("Certificate for Provisioning Profile '#{a.name}' not available locally: #{cert.id}, skipping this one...") end end installed && a.certificate_valid? end end |
#print_produce_command(config) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/sigh/runner.rb', line 221 def print_produce_command(config) UI. "" UI. "==========================================".yellow UI. "Could not find App ID with bundle identifier '#{config[:app_identifier]}'" UI. "You can easily generate a new App ID on the Developer Portal using 'produce':" UI. "" UI. "produce -u #{config[:username]} -a #{config[:app_identifier]} --skip_itc".yellow UI. "" UI. "You will be asked for any missing information, like the full name of your app" UI. "If the app should also be created on iTunes Connect, remove the " + "--skip_itc".yellow + " from the command above" UI. "==========================================".yellow UI. "" end |
#profile_type ⇒ Object
The kind of provisioning profile we're interested in
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sigh/runner.rb', line 54 def profile_type return @profile_type if @profile_type @profile_type = Spaceship.provisioning_profile.app_store @profile_type = Spaceship.provisioning_profile.in_house if Spaceship.client.in_house? @profile_type = Spaceship.provisioning_profile.ad_hoc if Sigh.config[:adhoc] @profile_type = Spaceship.provisioning_profile.development if Sigh.config[:development] @profile_type end |
#run ⇒ Object
Uses the spaceship to create or download a provisioning profile returns the path the newly created provisioning profile (in /tmp usually)
9 10 11 12 13 14 15 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 48 49 50 51 |
# File 'lib/sigh/runner.rb', line 9 def run FastlaneCore::PrintTable.print_values(config: Sigh.config, hide_keys: [:output_path], title: "Summary for sigh #{Sigh::VERSION}") UI. "Starting login with user '#{Sigh.config[:username]}'" Spaceship.login(Sigh.config[:username], nil) Spaceship.select_team UI. "Successfully logged in" profiles = [] if Sigh.config[:skip_fetch_profiles] profiles ||= fetch_profiles # download the profile if it's there if profiles.count > 0 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 UI.important "Updating the provisioning profile" else 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 UI.important "No existing profiles found, that match the certificates you have installed locally! Creating a new provisioning profile for you" ensure_app_exists! profile = create_profile! end 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" else ENV.delete("SIGH_PROFILE_ENTERPRISE") end return download_profile(profile) end |