Class: Fastlane::Actions::AndroidCodefreezePrechecksAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb

Constant Summary collapse

VERSION_RELEASE =
'release'.freeze
VERSION_ALPHA =
'alpha'.freeze

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



99
100
101
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 99

def self.authors
  ['Automattic']
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 66

def self.available_options
  # Define all options your action supports.
  [
    FastlaneCore::ConfigItem.new(key: :skip_confirm,
                                 env_name: 'FL_ANDROID_CODEFREEZE_PRECHECKS_SKIPCONFIRM',
                                 description: 'Skips confirmation before code freeze',
                                 type: Boolean,
                                 default_value: false), # the default value if the user didn't provide one
    FastlaneCore::ConfigItem.new(key: :default_branch,
                                 env_name: 'FL_RELEASE_TOOLKIT_DEFAULT_BRANCH',
                                 description: 'Default branch of the repository',
                                 type: String,
                                 default_value: Fastlane::Helper::GitHelper::DEFAULT_GIT_BRANCH),
    FastlaneCore::ConfigItem.new(key: :build_gradle_path,
                                 description: 'Path to the build.gradle file',
                                 type: String,
                                 optional: true,
                                 conflicting_options: [:version_properties_path]),
    FastlaneCore::ConfigItem.new(key: :version_properties_path,
                                 description: 'Path to the version.properties file',
                                 type: String,
                                 optional: true,
                                 conflicting_options: [:build_gradle_path]),
  ]
end

.descriptionObject



58
59
60
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 58

def self.description
  'Runs some prechecks before code freeze'
end

.detailsObject



62
63
64
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 62

def self.details
  'Updates the default branch, checks the app version and ensure the branch is clean'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 103

def self.is_supported?(platform)
  platform == :android
end

.outputObject



92
93
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 92

def self.output
end

.return_valueObject



95
96
97
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 95

def self.return_value
  'Version of the app before code freeze'
end

.run(params) ⇒ Object



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
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_codefreeze_prechecks.rb', line 7

def self.run(params)
  # fastlane will take care of reading in the parameter and fetching the environment variable:
  UI.message "Skip confirm on code freeze: #{params[:skip_confirm]}"

  require_relative '../../helper/android/android_version_helper'
  require_relative '../../helper/android/android_git_helper'

  build_gradle_path = params[:build_gradle_path]
  version_properties_path = params[:version_properties_path]

  # Checkout default branch and update
  default_branch = params[:default_branch]
  Fastlane::Helper::GitHelper.checkout_and_pull(default_branch)

  # Create versions
  current_version = Fastlane::Helper::Android::VersionHelper.get_release_version(
    build_gradle_path: build_gradle_path,
    version_properties_path: version_properties_path
  )
  current_alpha_version = Fastlane::Helper::Android::VersionHelper.get_alpha_version(
    build_gradle_path: build_gradle_path,
    version_properties_path: version_properties_path
  )
  next_version = Fastlane::Helper::Android::VersionHelper.calc_next_release_version(current_version, current_alpha_version)
  next_alpha_version = current_alpha_version.nil? ? nil : Fastlane::Helper::Android::VersionHelper.calc_next_alpha_version(next_version, current_alpha_version)

  no_alpha_version_message = "No alpha version configured. If you wish to configure an alpha version please update version.properties to include an alpha key for this app\n"
  # Ask user confirmation
  unless params[:skip_confirm]
    confirm_message = "Building a new release branch starting from #{default_branch}.\nCurrent version is #{current_version[Fastlane::Helper::Android::VersionHelper::VERSION_NAME]} (#{current_version[Fastlane::Helper::Android::VersionHelper::VERSION_CODE]}).\n"
    confirm_message += current_alpha_version.nil? ? no_alpha_version_message : "Current Alpha version is #{current_alpha_version[Fastlane::Helper::Android::VersionHelper::VERSION_NAME]} (#{current_alpha_version[Fastlane::Helper::Android::VersionHelper::VERSION_CODE]}).\n"
    confirm_message += "After code freeze the new version will be: #{next_version[Fastlane::Helper::Android::VersionHelper::VERSION_NAME]} (#{next_version[Fastlane::Helper::Android::VersionHelper::VERSION_CODE]}).\n"
    confirm_message += current_alpha_version.nil? ? '' : "After code freeze the new Alpha will be: #{next_alpha_version[Fastlane::Helper::Android::VersionHelper::VERSION_NAME]} (#{next_alpha_version[Fastlane::Helper::Android::VersionHelper::VERSION_CODE]}).\n"
    confirm_message += 'Do you want to continue?'
    UI.user_error!('Aborted by user request') unless UI.confirm(confirm_message)
  end

  # Check local repo status
  other_action.ensure_git_status_clean

  # Return the current version
  Fastlane::Helper::Android::VersionHelper.get_public_version(
    build_gradle_path: build_gradle_path,
    version_properties_path: version_properties_path
  )
end