Class: Fastlane::Actions::FotaMailAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/polidea/actions/fota_mail.rb

Class Method Summary collapse

Class Method Details

.authorObject



107
108
109
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 107

def self.author
  "thiagolioy"
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 27

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :postmaster,
                                 env_name: "MAILGUN_SANDBOX_POSTMASTER",
                                 description: "Mailgun sandbox domain postmaster for your mail"),
    FastlaneCore::ConfigItem.new(key: :apikey,
                                 env_name: "MAILGUN_APIKEY",
                                 description: "Mailgun apikey for your mail"),
    FastlaneCore::ConfigItem.new(key: :to,
                                 env_name: "MAILGUN_TO",
                                 description: "Destination of your mail"),
    FastlaneCore::ConfigItem.new(key: :from,
                                 env_name: "MAILGUN_FROM",
                                 optional: true,
                                 description: "Mailgun sender name",
                                 default_value: "Polidea"),
    FastlaneCore::ConfigItem.new(key: :success,
                                env_name: "MAILGUN_SUCCESS",
                                description: "Was this build successful? (true/false)",
                                optional: true,
                                default_value: true,
                                is_string: false),
    FastlaneCore::ConfigItem.new(key: :ci_build_link,
                                env_name: "MAILGUN_CI_BUILD_LINK",
                                description: "CI Build Link",
                                optional: true,
                                is_string: true),
    FastlaneCore::ConfigItem.new(key: :template_path,
                                env_name: "MAILGUN_TEMPLATE_PATH",
                                description: "Mail HTML template",
                                optional: true,
                                is_string: true),
    FastlaneCore::ConfigItem.new(key: :platform,
                                env_name: "MAILGUN_PLATFORM",
                                description: "Platform used in mail template",
                                optional: true,
                                default_value: Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]),
    FastlaneCore::ConfigItem.new(key: :app_icon,
                                env_name: "MAILGUN_APP_ICON",
                                description: "Path to app icon file",
                                is_string: true,
                                optional: true,
                                default_value: Actions.lane_context[SharedValues::ICON_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :app_name,
                                env_name: "MAILGUN_APP_NAME",
                                description: "Application name",
                                is_string: true,
                                default_value: Actions.lane_context[SharedValues::APP_NAME]),
    FastlaneCore::ConfigItem.new(key: :app_version,
                                env_name: "MAILGUN_APP_VERSION",
                                description: "Application version",
                                is_string: true,
                                default_value: Actions.lane_context[SharedValues::APP_VERSION]),
    FastlaneCore::ConfigItem.new(key: :build_number,
                                env_name: "MAILGUN_BUILD_NUMBER",
                                description: "Build number",
                                default_value: Actions.lane_context[SharedValues::BUILD_NUMBER]),
    FastlaneCore::ConfigItem.new(key: :installation_link,
                                env_name: "MAILGUN_INSTALLATION_LINK",
                                description: "Link to installation page",
                                is_string: true,
                                default_value: Actions.lane_context[SharedValues::S3_HTML_OUTPUT_PATH]),
    FastlaneCore::ConfigItem.new(key: :release_notes,
                                env_name: "MAILGUN_RELEASE_NOTES",
                                description: "Release notes",
                                type: String,
                                optional: true,
                                default_value: Actions.lane_context[SharedValues::RELEASE_NOTES]),
    FastlaneCore::ConfigItem.new(key: :binary_size,
                                env_name: "MAILGUN_BINARY_SIZE",
                                description: "Binary size",
                                type: Integer,
                                default_value: Actions.lane_context[SharedValues::BINARY_SIZE]),
    FastlaneCore::ConfigItem.new(key: :inline,
                                type: Array,
                                optional: true,
                                default_value: [])
  ]
end

.descriptionObject



23
24
25
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 23

def self.description
  "Send a success/error message to an email group"
end

.human_platform(platform) ⇒ Object



174
175
176
177
178
179
180
181
182
183
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 174

def self.human_platform(platform)
  case platform
  when :ios
    "iOS"
  when :android
    "Android"
  else
    platform.to_s
  end
end

.inline_images(options) ⇒ Object



111
112
113
114
115
116
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 111

def self.inline_images(options)
  options[:inline] = [
    qr_code(options[:installation_link])
  ]
  options[:inline] << File.new(options[:app_icon]) if options[:app_icon]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 7

def self.is_supported?(platform)
  true
end

.mail_template(options) ⇒ Object



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
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 138

def self.mail_template(options)
  hash = {
    author: Actions.git_author_email,
    last_commit: Actions.last_git_commit_message,
    is_android: options[:platform] == :android,
    app_icon: options[:app_icon] ? File.basename(options[:app_icon]) : nil,
    app_name: options[:app_name],
    app_version: options[:app_version],
    build_number: options[:build_number],
    installation_link: options[:installation_link],
    release_notes: options[:release_notes],
    platform: options[:platform],
    release_date: DateTime.now.strftime('%b %d, %Y'),
    binary_size: (options[:binary_size] / 1024.0 / 1024.0).round(2).to_s,
    qr_code: "qr_code.png"
  }
  hash[:success] = options[:success]
  hash[:ci_build_link] = options[:ci_build_link]

  # create html from template
  html_template_path = options[:template_path]
  if html_template_path && File.exist?(html_template_path)
    eth = Fastlane::ErbTemplateHelper
    html_template = eth.load_from_path(html_template_path)
    mail_html = eth.render(html_template, hash)
  else
    mail_html = PageGenerator.mail(hash)
  end

  premailer = Premailer.new(
    mail_html,
    { warn_level: Premailer::Warnings::SAFE, with_html_string: true }
  )
  premailer.to_inline_css
end

.mailgunit(options) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 124

def self.mailgunit(options)
  sandbox_domain = options[:postmaster].split("@").last
  body = mail_template(options)

  sh """curl -s --user 'api:#{options[:apikey]}' \
    https://api.mailgun.net/v3/#{sandbox_domain}/messages \
    -F from='#{options[:from]} <#{options[:postmaster]}>' \
    -F to='#{options[:to]}' \
    -F subject='#{options[:app_name]} #{options[:app_version]} (#{options[:build_number]}) for #{human_platform(options[:platform])} is ready to install' \
    --form-string html=#{Shellwords.escape(body)} \ """ + options[:inline].map { |file| "-F inline=@#{file.path}" }.join(" "), print_command: false, print_command_output: false

  return body
end

.qr_code(installation_link) ⇒ Object



118
119
120
121
122
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 118

def self.qr_code(installation_link)
  qr_code_path = "/tmp/qr_code.png"
  QRGenerator.new(installation_link, ::ChunkyPNG::Color.rgb(21, 18, 126)).generate(qr_code_path)
  File.new(qr_code_path)
end

.run(options) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 11

def self.run(options)
  Fastlane::Polidea.session.action_launched("fota_mail", options)

  Actions.verify_gem!('premailer')
  require 'premailer'
  inline_images(options)
  mailgunit(options)

  Fastlane::Polidea.session.action_completed("fota_mail")
  UI.success "Mail sent!"
end