Class: Fastlane::Actions::ConfigureUpdateAction

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

Class Method Summary collapse

Class Method Details

.absolute_secret_store_pathObject



118
119
120
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 118

def self.absolute_secret_store_path
  Fastlane::Helper::FilesystemHelper.secret_store_dir
end

.authorsObject



126
127
128
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 126

def self.authors
  ['Automattic']
end

.checkout_branch(branch_name) ⇒ Object

Switch to the given branch, but don’t ensure that it’s up-to-date – that’s for another step



109
110
111
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 109

def self.checkout_branch(branch_name)
  sh("cd '#{absolute_secret_store_path}' && git checkout '#{branch_name}'")
end

.configure_file_commits_behind_repoObject



97
98
99
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 97

def self.configure_file_commits_behind_repo
  Fastlane::Helper::ConfigureHelper.configure_file_commits_behind_repo
end

.configure_file_is_behind_repoObject



93
94
95
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 93

def self.configure_file_is_behind_repo
  Fastlane::Helper::ConfigureHelper.configure_file_is_behind_local
end

.current_branchObject



69
70
71
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 69

def self.current_branch
  Fastlane::Helper::ConfigureHelper.repo_branch_name
end

.current_hashObject



73
74
75
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 73

def self.current_hash
  Fastlane::Helper::ConfigureHelper.repo_commit_hash
end

.descriptionObject



122
123
124
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 122

def self.description
  'Ensure that the local secrets repository is up to date.'
end

.detailsObject



130
131
132
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 130

def self.details
  'Ensure that the local secrets repository is up to date, and lets you test alternative branches.'
end

.get_branchesObject



101
102
103
104
105
106
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 101

def self.get_branches
  branches = sh("cd #{absolute_secret_store_path} && git branch -r")
  branches.split("\n")
          .map { |s| s.strip!.split('/')[1] }
          .reject { |s| s.include? 'HEAD' }
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 134

def self.is_supported?(platform)
  true
end

.prompt_to_switch_branchesObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 47

def self.prompt_to_switch_branches
  branch_name_to_display = current_branch.nil? ? current_hash : current_branch
  if UI.confirm("The current branch is `#{branch_name_to_display}`. Would you like to switch branches?")
    new_branch = UI.select("Select the branch you'd like to switch to: ", get_branches)
    checkout_branch(new_branch)
    update_configure_file
  else
    UI.user_error!('The local secrets store is in a deatched HEAD state.  Please check out a branch and try again.') if current_branch.nil?
  end
end

.prompt_to_update_configure_file_to_most_recent_hashObject



65
66
67
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 65

def self.prompt_to_update_configure_file_to_most_recent_hash
  update_configure_file if UI.confirm("The `.configure` file is #{configure_file_commits_behind_repo} commit hash(es) behind the repo. Would you like to update it?")
end

.prompt_to_update_to_most_recent_versionObject



58
59
60
61
62
63
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 58

def self.prompt_to_update_to_most_recent_version
  if UI.confirm("The current branch is #{repo_commits_behind_remote} commit(s) behind. Would you like to update it?")
    update_branch
    update_configure_file
  end
end

.repo_commits_behind_remoteObject



85
86
87
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 85

def self.repo_commits_behind_remote
  Fastlane::Helper::ConfigureHelper.repo_commits_behind_remote
end

.repo_is_ahead_of_remoteObject



81
82
83
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 81

def self.repo_is_ahead_of_remote
  Fastlane::Helper::ConfigureHelper.repo_is_ahead_of_remote
end

.repo_is_behind_remoteObject



89
90
91
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 89

def self.repo_is_behind_remote
  Fastlane::Helper::ConfigureHelper.repo_is_behind_remote
end

.run(params = {}) ⇒ Object



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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 10

def self.run(params = {})
  prompt_to_switch_branches

  if repo_is_ahead_of_remote
    UI.user_error!("The local secrets store has changes that the remote repository doesn't.\
      Please fix this issue before continuing")
  end

  prompt_to_update_to_most_recent_version if repo_is_behind_remote

  if configure_file_is_behind_repo
    prompt_to_update_configure_file_to_most_recent_hash
  else
    # Update configure file even if already update to date
    # This ensures the file format is up to date
    update_configure_file
  end

  # If there is no encryption key for the project, generate one
  if Fastlane::Helper::ConfigureHelper.project_encryption_key.nil?
    # If the user chose not to update the repo but there is no encryption key, throw an error
    UI.user_error!('The local secrets behind the remote but it is missing a keys.json entry for this project. Please update it to the latest commit.') if repo_is_behind_remote
    Fastlane::Helper::ConfigureHelper.update_project_encryption_key
    # Update the configure file to the new hash
    update_configure_file
  end

  Fastlane::Helper::ConfigureHelper.files_to_copy.each do |file_reference|
    file_reference.update
  end

  UI.success "Configuration Secrets are up to date – don't forget to commit your changes to `.configure`."

  # Apply the changes that are now in the .configure file
  other_action.configure_apply
end

.update_branchObject

Ensure that the local secrets respository is up to date



114
115
116
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 114

def self.update_branch
  sh("cd '#{absolute_secret_store_path}' && git pull")
end

.update_configure_fileObject



77
78
79
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_update_action.rb', line 77

def self.update_configure_file
  Fastlane::Helper::ConfigureHelper.update_configure_file_from_repository
end