Class: Fastlane::Actions::EnsureGitBranchAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/ensure_git_branch.rb

Overview

Raises an exception and stop the lane execution if the repo is not on a specific branch

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



46
47
48
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 46

def self.author
  ['dbachrach', 'Liquidsoul']
end

.available_optionsObject



33
34
35
36
37
38
39
40
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 33

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :branch,
                                 env_name: "FL_ENSURE_GIT_BRANCH_NAME",
                                 description: "The branch that should be checked for. String that can be either the full name of the branch or a regex e.g. `^feature\/.*$` to match",
                                 default_value: 'master')
  ]
end

.categoryObject



59
60
61
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 59

def self.category
  :source_control
end

.descriptionObject



22
23
24
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 22

def self.description
  "Raises an exception if not on a specific git branch"
end

.detailsObject



26
27
28
29
30
31
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 26

def self.details
  [
    "This action will check if your git repo is checked out to a specific branch.",
    "You may only want to make releases from a specific branch, so `ensure_git_branch` will stop a lane if it was accidentally executed on an incorrect branch."
  ].join("\n")
end

.example_codeObject



50
51
52
53
54
55
56
57
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 50

def self.example_code
  [
    "ensure_git_branch # defaults to `master` branch",
    "ensure_git_branch(
      branch: 'develop'
    )"
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



63
64
65
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 63

def self.is_supported?(platform)
  true
end

.outputObject



42
43
44
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 42

def self.output
  []
end

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'fastlane/lib/fastlane/actions/ensure_git_branch.rb', line 8

def self.run(params)
  branch = params[:branch]
  branch_expr = /#{branch}/
  if Actions.git_branch =~ branch_expr
    UI.success("Git branch matches `#{branch}`, all good! 💪")
  else
    UI.user_error!("Git is not on a branch matching `#{branch}`. Current branch is `#{Actions.git_branch}`! Please ensure the repo is checked out to the correct branch.")
  end
end