-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
gym.rb
141 lines (122 loc) 路 5.91 KB
/
gym.rb
1
2
3
4
5
6
7
8
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
module Fastlane
module Actions
module SharedValues
IPA_OUTPUT_PATH = :IPA_OUTPUT_PATH
DSYM_OUTPUT_PATH = :DSYM_OUTPUT_PATH
end
class GymAction < Action
def self.run(values)
require 'gym'
unless Actions.lane_context[SharedValues::SIGH_PROFILE_TYPE].to_s == "development"
values[:export_method] ||= Actions.lane_context[SharedValues::SIGH_PROFILE_TYPE]
end
if Actions.lane_context[SharedValues::MATCH_PROVISIONING_PROFILE_MAPPING]
# Since Xcode 9 you need to explicitly provide the provisioning profile per app target
# If the user is smart and uses match and gym together with fastlane, we can do all
# the heavy lifting for them
values[:export_options] ||= {}
# It's not always a hash, because the user might have passed a string path to a ready plist file
# If that's the case, we won't set the provisioning profiles
# see https://github.com/fastlane/fastlane/issues/9490
if values[:export_options].kind_of?(Hash)
match_mapping = (Actions.lane_context[SharedValues::MATCH_PROVISIONING_PROFILE_MAPPING] || {}).dup
existing_mapping = (values[:export_options][:provisioningProfiles] || {}).dup
# Be smart about how we merge those mappings in case there are conflicts
mapping_object = Gym::CodeSigningMapping.new
hash_to_use = mapping_object.merge_profile_mapping(primary_mapping: existing_mapping,
secondary_mapping: match_mapping,
export_method: values[:export_method])
values[:export_options][:provisioningProfiles] = hash_to_use
else
self.show_xcode_9_warning
end
elsif Actions.lane_context[SharedValues::SIGH_PROFILE_PATHS]
# Since Xcode 9 you need to explicitly provide the provisioning profile per app target
# If the user used sigh we can match the profiles from sigh
values[:export_options] ||= {}
if values[:export_options].kind_of?(Hash)
# It's not always a hash, because the user might have passed a string path to a ready plist file
# If that's the case, we won't set the provisioning profiles
# see https://github.com/fastlane/fastlane/issues/9684
values[:export_options][:provisioningProfiles] ||= {}
Actions.lane_context[SharedValues::SIGH_PROFILE_PATHS].each do |profile_path|
begin
profile = FastlaneCore::ProvisioningProfile.parse(profile_path)
profile_team_id = profile["TeamIdentifier"].first
next if profile_team_id != values[:export_team_id] && !values[:export_team_id].nil?
bundle_id = profile["Entitlements"]["application-identifier"].gsub("#{profile_team_id}.", "")
values[:export_options][:provisioningProfiles][bundle_id] = profile["Name"]
rescue => ex
UI.error("Couldn't load profile at path: #{profile_path}")
UI.error(ex)
UI.verbose(ex.backtrace.join("\n"))
end
end
else
self.show_xcode_9_warning
end
end
gym_output_path = Gym::Manager.new.work(values)
if gym_output_path.nil?
UI.important("No output path received from gym")
return nil
end
absolute_ipa_path = File.expand_path(gym_output_path)
absolute_dsym_path = absolute_ipa_path.gsub(".ipa", ".app.dSYM.zip")
# This might be the mac app path, so we don't want to set it here
# https://github.com/fastlane/fastlane/issues/5757
if absolute_ipa_path.include?(".ipa")
Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] = absolute_ipa_path
ENV[SharedValues::IPA_OUTPUT_PATH.to_s] = absolute_ipa_path # for deliver
end
Actions.lane_context[SharedValues::DSYM_OUTPUT_PATH] = absolute_dsym_path if File.exist?(absolute_dsym_path)
Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE] = Gym::BuildCommandGenerator.archive_path
ENV[SharedValues::DSYM_OUTPUT_PATH.to_s] = absolute_dsym_path if File.exist?(absolute_dsym_path)
return absolute_ipa_path
end
def self.description
"Easily build and sign your app using _gym_"
end
def self.details
"More information: https://fastlane.tools/gym"
end
def self.return_value
"The absolute path to the generated ipa file"
end
def self.author
"KrauseFx"
end
def self.available_options
require 'gym'
Gym::Options.available_options
end
def self.is_supported?(platform)
[:ios, :mac].include? platform
end
def self.example_code
[
'gym(scheme: "MyApp", workspace: "MyApp.xcworkspace")',
'gym(
workspace: "MyApp.xcworkspace",
configuration: "Debug",
scheme: "MyApp",
silent: true,
clean: true,
output_directory: "path/to/dir", # Destination directory. Defaults to current directory.
output_name: "my-app.ipa", # specify the name of the .ipa file to generate (including file extension)
sdk: "10.0" # use SDK as the name or path of the base SDK when building the project.
)'
]
end
def self.category
:building
end
def self.show_xcode_9_warning
return unless Helper.xcode_at_least?("9.0")
UI.message("You passed a path to a custom plist file for exporting the binary.")
UI.message("Make sure to include information about what provisioning profiles to use with Xcode 9")
UI.message("More information: https://docs.fastlane.tools/codesigning/xcode-project/#xcode-9-and-up")
end
end
end
end