Class: Fastlane::Actions::SpmAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/spm.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, details, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



148
149
150
# File 'fastlane/lib/fastlane/actions/spm.rb', line 148

def self.authors
  ["fjcaetano", "nxtstep"]
end

.available_commandsObject



186
187
188
# File 'fastlane/lib/fastlane/actions/spm.rb', line 186

def self.available_commands
  %w(build test) + self.package_commands
end

.available_optionsObject



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
142
143
144
145
146
# File 'fastlane/lib/fastlane/actions/spm.rb', line 54

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :command,
                                 env_name: "FL_SPM_COMMAND",
                                 description: "The swift command (one of: #{available_commands.join(', ')})",
                                 default_value: "build",
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid command. Use one of the following: #{available_commands.join(', ')}") unless available_commands.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :enable_code_coverage,
                                 env_name: "FL_SPM_ENABLE_CODE_COVERAGE",
                                 description: "Enables code coverage for the generated Xcode project when using the 'generate-xcodeproj' and the 'test' command",
                                 type: Boolean,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :scratch_path,
                                 env_name: "FL_SPM_SCRATCH_PATH",
                                 description: "Specify build/cache directory [default: ./.build]",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :parallel,
                                 env_name: "FL_SPM_PARALLEL",
                                 description: "Enables running tests in parallel when using the 'test' command",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :build_path,
                                 env_name: "FL_SPM_BUILD_PATH",
                                 description: "Specify build/cache directory [default: ./.build]",
                                 deprecated: "`build_path` option is deprecated, use `scratch_path` instead",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :package_path,
                                 env_name: "FL_SPM_PACKAGE_PATH",
                                 description: "Change working directory before any other operation",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :xcconfig,
                                 env_name: "FL_SPM_XCCONFIG",
                                 description: "Use xcconfig file to override swift package generate-xcodeproj defaults",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :configuration,
                                 short_option: "-c",
                                 env_name: "FL_SPM_CONFIGURATION",
                                 description: "Build with configuration (debug|release) [default: debug]",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid configuration: (debug|release)") unless valid_configurations.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :disable_sandbox,
                                 env_name: "FL_SPM_DISABLE_SANDBOX",
                                 description: "Disable using the sandbox when executing subprocesses",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :xcpretty_output,
                                 env_name: "FL_SPM_XCPRETTY_OUTPUT",
                                 description: "Specifies the output type for xcpretty. eg. 'test', or 'simple'",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid xcpretty output type: (#{xcpretty_output_types.join('|')})") unless xcpretty_output_types.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :xcpretty_args,
                                 env_name: "FL_SPM_XCPRETTY_ARGS",
                                 description: "Pass in xcpretty additional command line arguments (e.g. '--test --no-color' or '--tap --no-utf'), requires xcpretty_output to be specified also",
                                 type: String,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 short_option: "-v",
                                 env_name: "FL_SPM_VERBOSE",
                                 description: "Increase verbosity of informational output",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :very_verbose,
                                 short_option: "-V",
                                 env_name: "FL_SPM_VERY_VERBOSE",
                                 description: "Increase verbosity to include debug output",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :simulator,
                                 env_name: "FL_SPM_SIMULATOR",
                                 description: "Specifies the simulator to pass for Swift Compiler (one of: #{valid_simulators.join(', ')})",
                                 type: String,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid simulator. Use one of the following: #{valid_simulators.join(', ')}") unless valid_simulators.include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :simulator_arch,
                                 env_name: "FL_SPM_SIMULATOR_ARCH",
                                 description: "Specifies the architecture of the simulator to pass for Swift Compiler (one of: #{valid_architectures.join(', ')}). Requires the simulator option to be specified also, otherwise, it's ignored",
                                 type: String,
                                 optional: false,
                                 default_value: "arm64",
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass a valid simulator architecture. Use one of the following: #{valid_architectures.join(', ')}") unless valid_architectures.include?(value)
                                 end)
  ]
end

.categoryObject



182
183
184
# File 'fastlane/lib/fastlane/actions/spm.rb', line 182

def self.category
  :building
end

.descriptionObject



50
51
52
# File 'fastlane/lib/fastlane/actions/spm.rb', line 50

def self.description
  "Runs Swift Package Manager on your project"
end

.example_codeObject



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
# File 'fastlane/lib/fastlane/actions/spm.rb', line 156

def self.example_code
  [
    'spm',
    'spm(
      command: "build",
      scratch_path: "./build",
      configuration: "release"
    )',
    'spm(
      command: "generate-xcodeproj",
      xcconfig: "Package.xcconfig"
    )',
    'spm(
      command: "test",
      parallel: true
    )',
    'spm(
      simulator: "iphonesimulator"
    )',
    'spm(
      simulator: "macosx",
      simulator_arch: "arm64"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



152
153
154
# File 'fastlane/lib/fastlane/actions/spm.rb', line 152

def self.is_supported?(platform)
  true
end

.package_commandsObject



190
191
192
# File 'fastlane/lib/fastlane/actions/spm.rb', line 190

def self.package_commands
  %w(clean reset update resolve generate-xcodeproj init)
end

.run(params) ⇒ Object



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
# File 'fastlane/lib/fastlane/actions/spm.rb', line 4

def self.run(params)
  cmd = ["swift"]

  cmd << (package_commands.include?(params[:command]) ? "package" : params[:command])
  cmd << "--scratch-path #{params[:scratch_path]}" if params[:scratch_path]
  cmd << "--build-path #{params[:build_path]}" if params[:build_path]
  cmd << "--package-path #{params[:package_path]}" if params[:package_path]
  cmd << "--configuration #{params[:configuration]}" if params[:configuration]
  cmd << "--disable-sandbox" if params[:disable_sandbox]
  cmd << "--verbose" if params[:verbose]
  cmd << "--very-verbose" if params[:very_verbose]
  if params[:simulator]
    simulator_platform = simulator_platform(simulator: params[:simulator], simulator_arch: params[:simulator_arch])
    simulator_sdk = simulator_sdk(simulator: params[:simulator])
    simulator_sdk_suffix = simulator_sdk_suffix(simulator: params[:simulator])
    simulator_flags = [
      "-Xswiftc", "-sdk",
      "-Xswiftc", "$(xcrun --sdk #{params[:simulator]} --show-sdk-path)",
      "-Xswiftc", "-target",
      "-Xswiftc", "#{simulator_platform}#{simulator_sdk}#{simulator_sdk_suffix}"
    ]
    cmd += simulator_flags
  end
  cmd << params[:command] if package_commands.include?(params[:command])
  cmd << "--enable-code-coverage" if params[:enable_code_coverage] && (params[:command] == 'generate-xcodeproj' || params[:command] == 'test')
  cmd << "--parallel" if params[:parallel] && params[:command] == 'test'
  if params[:xcconfig]
    cmd << "--xcconfig-overrides #{params[:xcconfig]}"
  end
  if params[:xcpretty_output]
    cmd += ["2>&1", "|", "xcpretty", "--#{params[:xcpretty_output]}"]
    if params[:xcpretty_args]
      cmd << (params[:xcpretty_args]).to_s
    end
    cmd = %w(set -o pipefail &&) + cmd
  end

  FastlaneCore::CommandExecutor.execute(command: cmd.join(" "),
                                        print_all: true,
                                        print_command: true)
end

.simulator_platform(params) ⇒ Object



210
211
212
213
# File 'fastlane/lib/fastlane/actions/spm.rb', line 210

def self.simulator_platform(params)
  platform_suffix = params[:simulator] == "iphonesimulator" ? "ios" : "macosx"
  "#{params[:simulator_arch]}-apple-#{platform_suffix}"
end

.simulator_sdk(params) ⇒ Object



215
216
217
# File 'fastlane/lib/fastlane/actions/spm.rb', line 215

def self.simulator_sdk(params)
  "$(xcrun --sdk #{params[:simulator]} --show-sdk-version | cut -d '.' -f 1)"
end

.simulator_sdk_suffix(params) ⇒ Object



219
220
221
222
# File 'fastlane/lib/fastlane/actions/spm.rb', line 219

def self.simulator_sdk_suffix(params)
  return "" unless params[:simulator] == "iphonesimulator"
  "-simulator"
end

.valid_architecturesObject



206
207
208
# File 'fastlane/lib/fastlane/actions/spm.rb', line 206

def self.valid_architectures
  %w(x86_64 arm64)
end

.valid_configurationsObject



194
195
196
# File 'fastlane/lib/fastlane/actions/spm.rb', line 194

def self.valid_configurations
  %w(debug release)
end

.valid_simulatorsObject



202
203
204
# File 'fastlane/lib/fastlane/actions/spm.rb', line 202

def self.valid_simulators
  %w(iphonesimulator macosx)
end

.xcpretty_output_typesObject



198
199
200
# File 'fastlane/lib/fastlane/actions/spm.rb', line 198

def self.xcpretty_output_types
  %w(simple test knock tap)
end