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



103
104
105
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 103

def self.author
  "thiagolioy"
end

.available_optionsObject



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

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



19
20
21
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 19

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

.inline_images(options) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 107

def self.inline_images(options)
  base_path = "#{__dir__}/../templates/images"
  options[:inline] = [
    qr_code(options[:installation_link])
  ]
  options[:inline] << File.new(options[:app_icon]) if options[:app_icon]
  images = [
    "polidea-facebook-icon.png",
    "polidea-github-icon.png",
    "polidea-logo.png",
    "polidea-twitter-icon.png"
  ]
  images << "icon-placeholder.png" unless options[:app_icon]
  options[:inline].concat(images.map { |image| File.new("#{base_path}/#{image}") })
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



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

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] || "").split("\n"),
    platform: options[:platform],
    release_date: DateTime.now.strftime('%b %d, %Y'),
    binary_size: (options[:binary_size] / 1024.0 / 1024.0).round(2).to_s
  }
  hash[:success] = options[:success]
  hash[:ci_build_link] = options[:ci_build_link]

  # grabs module
  eth = Fastlane::ErbTemplateHelper
  # create html from template
  html_template_path = options[:template_path]
  if html_template_path && File.exist?(html_template_path)
    html_template = eth.load_from_path(html_template_path)
  else
    html_template = eth.load_from_path("#{__dir__}/../templates/mailgun_template.erb")
  end
  premailer = Premailer.new(
    eth.render(html_template, hash),
    { warn_level: Premailer::Warnings::SAFE, with_html_string: true }
  )
  premailer.to_inline_css
end

.mailgunit(options) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 129

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 #{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



123
124
125
126
127
# File 'lib/fastlane/plugin/polidea/actions/fota_mail.rb', line 123

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

.run(options) ⇒ Object



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

def self.run(options)
  Actions.verify_gem!('premailer')
  require 'premailer'
  inline_images(options)
  mailgunit(options)
  UI.success "Mail sent!"
end