Class: Fastlane::Actions::NexusUploadAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/nexus_upload.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



187
188
189
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 187

def self.authors
  ["xfreebird", "mdio"]
end

.available_optionsObject



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

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :file,
                                 env_name: "FL_NEXUS_FILE",
                                 description: "File to be uploaded to Nexus",
                                 optional: false,
                                 verify_block: proc do |value|
                                   file_path = File.expand_path(value)
                                   UI.user_error!("Couldn't find file at path '#{file_path}'") unless File.exist?(file_path)
                                 end),
    FastlaneCore::ConfigItem.new(key: :repo_id,
                                 env_name: "FL_NEXUS_REPO_ID",
                                 description: "Nexus repository id e.g. artefacts",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :repo_group_id,
                                 env_name: "FL_NEXUS_REPO_GROUP_ID",
                                 description: "Nexus repository group id e.g. com.company",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :repo_project_name,
                                 env_name: "FL_NEXUS_REPO_PROJECT_NAME",
                                 description: "Nexus repository commandect name. Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :repo_project_version,
                                 env_name: "FL_NEXUS_REPO_PROJECT_VERSION",
                                 description: "Nexus repository commandect version",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :repo_classifier,
                                 env_name: "FL_NEXUS_REPO_CLASSIFIER",
                                 description: "Nexus repository artifact classifier (optional)",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :endpoint,
                                 env_name: "FL_NEXUS_ENDPOINT",
                                 description: "Nexus endpoint e.g. http://nexus:8081",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :mount_path,
                                 env_name: "FL_NEXUS_MOUNT_PATH",
                                 description: "Nexus mount path (Nexus 3 instances have this configured as empty by default)",
                                 default_value: "/nexus",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_NEXUS_USERNAME",
                                 description: "Nexus username",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "FL_NEXUS_PASSWORD",
                                 description: "Nexus password",
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :ssl_verify,
                                 env_name: "FL_NEXUS_SSL_VERIFY",
                                 description: "Verify SSL",
                                 type: Boolean,
                                 default_value: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :nexus_version,
                                 env_name: "FL_NEXUS_MAJOR_VERSION",
                                 description: "Nexus major version",
                                 type: Integer,
                                 default_value: 2,
                                 optional: true,
                                 verify_block: proc do |value|
                                   min_version = 2
                                   max_version = 3
                                   UI.user_error!("Unsupported version (#{value}) min. supported version: #{min_version}") unless value >= min_version
                                   UI.user_error!("Unsupported version (#{value}) max. supported version: #{max_version}") unless value <= max_version
                                 end),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 env_name: "FL_NEXUS_VERBOSE",
                                 description: "Make detailed output",
                                 type: Boolean,
                                 default_value: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :proxy_username,
                                 env_name: "FL_NEXUS_PROXY_USERNAME",
                                 description: "Proxy username",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :proxy_password,
                                 env_name: "FL_NEXUS_PROXY_PASSWORD",
                                 sensitive: true,
                                 description: "Proxy password",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :proxy_address,
                                 env_name: "FL_NEXUS_PROXY_ADDRESS",
                                 description: "Proxy address",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :proxy_port,
                                 env_name: "FL_NEXUS_PROXY_PORT",
                                 description: "Proxy port",
                                 optional: true)
  ]
end

.categoryObject



226
227
228
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 226

def self.category
  :beta
end

.descriptionObject



92
93
94
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 92

def self.description
  "Upload a file to [Sonatype Nexus platform](https://www.sonatype.com)"
end

.example_codeObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 195

def self.example_code
  [
    '# for Nexus 2
    nexus_upload(
      file: "/path/to/file.ipa",
      repo_id: "artefacts",
      repo_group_id: "com.fastlane",
      repo_project_name: "ipa",
      repo_project_version: "1.13",
      repo_classifier: "dSYM", # Optional
      endpoint: "http://localhost:8081",
      username: "admin",
      password: "admin123"
    )',
    '# for Nexus 3
    nexus_upload(
      nexus_version: 3,
      mount_path: "",
      file: "/path/to/file.ipa",
      repo_id: "artefacts",
      repo_group_id: "com.fastlane",
      repo_project_name: "ipa",
      repo_project_version: "1.13",
      repo_classifier: "dSYM", # Optional
      endpoint: "http://localhost:8081",
      username: "admin",
      password: "admin123"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



191
192
193
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 191

def self.is_supported?(platform)
  true
end

.proxy_options(params) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 78

def self.proxy_options(params)
  options = []
  if params[:proxy_address] && params[:proxy_port] && params[:proxy_username] && params[:proxy_password]
    options << "-x #{params[:proxy_address].shellescape}:#{params[:proxy_port].shellescape}"
    options << "--proxy-user #{params[:proxy_username].shellescape}:#{params[:proxy_password].shellescape}"
  end

  options
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 4

def self.run(params)
  command = []
  command << "curl"
  command << verbose(params)
  command << "--fail"
  command += ssl_options(params)
  command += proxy_options(params)
  command += upload_options(params)
  command << upload_url(params)

  Fastlane::Actions.sh(command.join(' '), log: params[:verbose])
end

.ssl_options(params) ⇒ Object



69
70
71
72
73
74
75
76
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 69

def self.ssl_options(params)
  options = []
  unless params[:ssl_verify]
    options << "--insecure"
  end

  options
end

.upload_options(params) ⇒ Object



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

def self.upload_options(params)
  file_path = File.expand_path(params[:file]).shellescape
  file_extension = file_path.split('.').last.shellescape

  options = []
  if params[:nexus_version] == 2
    options << "-F p=zip"
    options << "-F hasPom=false"
    options << "-F r=#{params[:repo_id].shellescape}"
    options << "-F g=#{params[:repo_group_id].shellescape}"
    options << "-F a=#{params[:repo_project_name].shellescape}"
    options << "-F v=#{params[:repo_project_version].shellescape}"

    if params[:repo_classifier]
      options << "-F c=#{params[:repo_classifier].shellescape}"
    end

    options << "-F e=#{file_extension}"
    options << "-F file=@#{file_path}"
  else
    options << "--upload-file #{file_path}"
  end

  options << "-u #{params[:username].shellescape}:#{params[:password].shellescape}"

  options
end

.upload_url(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 17

def self.upload_url(params)
  url = "#{params[:endpoint]}#{params[:mount_path]}"

  if params[:nexus_version] == 2
    url << "/service/local/artifact/maven/content"
  else
    file_extension = File.extname(params[:file]).shellescape

    url << "/repository/#{params[:repo_id]}"
    url << "/#{params[:repo_group_id].gsub('.', '/')}"
    url << "/#{params[:repo_project_name]}"
    url << "/#{params[:repo_project_version]}"
    url << "/#{params[:repo_project_name]}-#{params[:repo_project_version]}"
    url << "-#{params[:repo_classifier]}" if params[:repo_classifier]
    url << file_extension.to_s
  end

  url.shellescape
end

.verbose(params) ⇒ Object



37
38
39
# File 'fastlane/lib/fastlane/actions/nexus_upload.rb', line 37

def self.verbose(params)
  params[:verbose] ? "--verbose" : "--silent"
end