Class: Fastlane::Actions::NordalpAppPublishAction

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

Overview

Fastlane Plugin action class

Class Method Summary collapse

Class Method Details

.authorsObject



61
62
63
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 61

def self.authors
  ['ov3rk1ll']
end

.available_optionsObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 74

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :token,
                                 env_name: 'NORDALP_APP_PUBLISH_TOKEN',
                                 description: 'Access token for CMS',
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :url,
                                 env_name: 'NORDALP_APP_PUBLISH_URL',
                                 description: 'URL for CMS flow',
                                 optional: true,
                                 default_value: 'https://cms.nordalp.de/flows/trigger/d6c99c78-63cf-4701-a297-aeee079ad8da',
                                 type: String)
  ]
end

.descriptionObject

rubocop:enable Require/MissingRequireStatement



57
58
59
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 57

def self.description
  'Publish an app update to Nordalp website'
end

.detailsObject



69
70
71
72
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 69

def self.details
  # Optional:

  ''
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 90

def self.is_supported?(platform)
  [:android].include?(platform)
end

.return_valueObject



65
66
67
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 65

def self.return_value
  # Optional

end

.run(params) ⇒ Object

rubocop:disable Require/MissingRequireStatement



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
# File 'lib/fastlane/plugin/nordalp_app_publish/actions/nordalp_app_publish_action.rb', line 12

def self.run(params)
  UI.message("Upload to #{params[:url]} using #{params[:token]}")
  changelog = Helper::NordalpAppPublishHelper.read_first_changelog_entry('CHANGELOG.md')
  UI.message("Changelog for #{changelog[:version]} @ #{changelog[:date]}")

  jsons = lane_context[SharedValues::GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS]
  links = lane_context[:S3_ALL_FILE_URL]
  if jsons.length == links.length
    # Markdown renderer to convert changelog to HTML

    markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true)

    jsons.each_with_index do |element, index|
      # Read app data from json-output file

      json_string = File.read(element)
      data_hash = JSON.parse(json_string)
      application_id = data_hash['applicationId']
      version_code = data_hash['elements'][0]['versionCode']
      version_name = data_hash['elements'][0]['versionName']

      # Send data to CMS

      # The CMS will discard any submissions with an application_id that does not yet have a record

      post_data = {
        changelog: {
          version: changelog[:version],
          date: changelog[:date],
          # The Changelog expects the 

          text: markdown
                  .render(changelog[:text])
                  .gsub('<h3>', '<h5>')
                  .gsub('</h3>', '</h5>')
        },
        application_id: application_id,
        link: links[index],
        version_code: version_code,
        version_name: version_name
      }
      result = Helper::NordalpAppPublishHelper.post_app(params[:url], params[:token], post_data)
      UI.message("Sent #{application_id} with result #{result}")
    end
  else
    UI.message('Number of items not equal in json and link arrays!')
  end
end