Class: Fastlane::Actions::ConfigureValidateAction

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

Class Method Summary collapse

Class Method Details

.absolute_project_path(relative_path) ⇒ Object



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

def self.absolute_project_path(relative_path)
  Fastlane::Helper::FilesystemHelper.absolute_project_path(relative_path)
end

.absolute_secret_store_path(relative_path) ⇒ Object



107
108
109
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 107

def self.absolute_secret_store_path(relative_path)
  Fastlane::Helper::FilesystemHelper.absolute_secret_store_path(relative_path)
end

.authorsObject



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

def self.authors
  ['Automattic']
end

.descriptionObject



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

def self.description
  'Ensure that the configuration is valid'
end

.detailsObject



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

def self.details
  'Ensure that the configuration is valid'
end

.file_hash(absolute_path) ⇒ Object



111
112
113
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 111

def self.file_hash(absolute_path)
  Fastlane::Helper::FilesystemHelper.file_hash(absolute_path)
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.is_supported?(platform)
  true
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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 10

def self.run(params = {})
  # Start by ensuring that we've set up the project for configuration
  validate_that_configure_file_exists

  # Check that the secrets repo is locally clean _before_ downloading the latest version,
  # otherwise, the error messaging isn't as helpful.
  validate_that_secrets_repo_is_clean

  # Update the repository to get the latest version of the configuration secrets
  # – that's how we'll know if we're behind in subsequent validations
  ConfigureDownloadAction.run

  validate_that_branches_match

  validate_that_hashes_match

  validate_that_no_dependent_files_have_changed

  validate_that_all_copied_files_match

  UI.success 'Configuration is valid'
end

.validate_that_all_copied_files_matchObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 87

def self.validate_that_all_copied_files_match
  Fastlane::Helper::ConfigureHelper.files_to_copy.each do |x|
    source = absolute_secret_store_path(x.file)
    destination = absolute_project_path(x.destination)

    source_hash = file_hash(source)
    destination_hash = file_hash(destination)

    UI.user_error!("`#{x.destination} doesn't match the file in the secrets repository (#{x.file}) – unable to continue") unless source_hash == destination_hash
  end
end

.validate_that_branches_matchObject

Validate that the branch specified in .configure matches the branch checked out in ~/.mobile-secrets.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 39

def self.validate_that_branches_match
  repo_branch_name = Fastlane::Helper::ConfigureHelper.repo_branch_name
  file_branch_name = Fastlane::Helper::ConfigureHelper.configure_file_branch_name

  return if repo_branch_name == file_branch_name

  UI.user_error!([
    'The branch specified in `.configure` is not the currently checked out branch in the secrets repository.',
    "To fix this issue, switch back to the `#{file_branch_name}` branch in the mobile secrets repository.",
  ].join("\n"))
end

.validate_that_configure_file_existsObject



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

def self.validate_that_configure_file_exists
  UI.user_error!("Couldn't find `.configure` file. Please set up this project for `configure` by running `bundle exec fastlane run configure_setup`") unless Fastlane::Helper::ConfigureHelper.configuration_path_exists
end

.validate_that_hashes_matchObject

Validate that the pinned hash specified in .configure matches the current hash of ~/.mobile-secrets



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 53

def self.validate_that_hashes_match
  repo_hash = Fastlane::Helper::ConfigureHelper.repo_commit_hash
  file_hash = Fastlane::Helper::ConfigureHelper.configure_file_commit_hash

  return if repo_hash == file_hash

  UI.user_error!([
    'The pinned_hash specified in `.configure` is not the currently checked out hash in the secrets repository.',
    "To fix this issue, check out the `#{file_hash}` hash in the mobile secrets repository.",
  ].join("\n"))
end

.validate_that_no_dependent_files_have_changedObject

Validate that based on the commit hash in the .configure file, no files have changed that affect this project.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 67

def self.validate_that_no_dependent_files_have_changed
  repo_hash = Fastlane::Helper::ConfigureHelper.repo_commit_hash
  file_hash = Fastlane::Helper::ConfigureHelper.configure_file_commit_hash

  changed_files = Fastlane::Helper::ConfigureHelper.files_changed_between(file_hash, repo_hash)
  dependencies = Fastlane::Helper::ConfigureHelper.file_dependencies
  new_files = Fastlane::Helper::ConfigureHelper.new_files_in(changed_files)

  changed_dependencies = changed_files & dependencies # calculate array intersection

  UI.user_error!("The following files are out of date. Please run `bundle exec fastlane run configure_update` before continuing:\n\n#{changed_dependencies}") unless changed_dependencies.empty?

  UI.user_error!("The following files are in the secrets repository, but aren't available for your project. Please run `bundle exec fastlane run configure_update` before continuing:\n\n#{new_files}") unless new_files.empty?
end

.validate_that_secrets_repo_is_cleanObject

Validate that the secrets repo doesn’t have any local changes



83
84
85
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_validate_action.rb', line 83

def self.validate_that_secrets_repo_is_clean
  UI.user_error!('The secrets repository has uncommitted changes. Please commit or discard them before continuing.') unless Fastlane::Helper::ConfigureHelper.repo_has_changes
end