Class: Fastlane::Actions::AddGitTagAction

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

Overview

Adds a git tag to the current commit

Constant Summary

Constants inherited from Fastlane::Action

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

Class Method Summary collapse

Methods inherited from Fastlane::Action

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

Class Method Details

.authorsObject



129
130
131
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 129

def self.authors
  ["lmirosevic", "maschall"]
end

.available_optionsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :tag,
                                 env_name: "FL_GIT_TAG_TAG",
                                 description: "Define your own tag text. This will replace all other parameters",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :grouping,
                                 env_name: "FL_GIT_TAG_GROUPING",
                                 description: "Is used to keep your tags organised under one 'folder'",
                                 default_value: 'builds'),
    FastlaneCore::ConfigItem.new(key: :includes_lane,
                                 env_name: "FL_GIT_TAG_INCLUDES_LANE",
                                 description: "Whether the current lane should be included in the tag and message composition, e.g. '<grouping>/<lane>/<prefix><build_number><postfix>'",
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :prefix,
                                 env_name: "FL_GIT_TAG_PREFIX",
                                 description: "Anything you want to put in front of the version number (e.g. 'v')",
                                 default_value: ''),
    FastlaneCore::ConfigItem.new(key: :postfix,
                                 env_name: "FL_GIT_TAG_POSTFIX",
                                 description: "Anything you want to put at the end of the version number (e.g. '-RC1')",
                                 default_value: ''),
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 env_name: "FL_GIT_TAG_BUILD_NUMBER",
                                 description: "The build number. Defaults to the result of increment_build_number if you\'re using it",
                                 default_value: Actions.lane_context[Actions::SharedValues::BUILD_NUMBER],
                                 default_value_dynamic: true,
                                 skip_type_validation: true, # skipping validation because we both allow integer and string
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :message,
                                 env_name: "FL_GIT_TAG_MESSAGE",
                                 description: "The tag message. Defaults to the tag's name",
                                 default_value_dynamic: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :commit,
                                 env_name: "FL_GIT_TAG_COMMIT",
                                 description: "The commit or object where the tag will be set. Defaults to the current HEAD",
                                 default_value_dynamic: true,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :force,
                                 env_name: "FL_GIT_TAG_FORCE",
                                 description: "Force adding the tag",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :sign,
                                 env_name: "FL_GIT_TAG_SIGN",
                                 description: "Make a GPG-signed tag, using the default e-mail address's key",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false)
  ]
end

.categoryObject



125
126
127
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 125

def self.category
  :source_control
end

.descriptionObject



33
34
35
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 33

def self.description
  "This will add an annotated git tag to the current branch"
end

.detailsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 37

def self.details
  list = <<-LIST.markdown_list
    `grouping` is just to keep your tags organised under one 'folder', defaults to 'builds'
    `lane` is the name of the current fastlane lane, if chosen to be included via 'includes_lane' option, which defaults to 'true'
    `prefix` is anything you want to stick in front of the version number, e.g. 'v'
    `postfix` is anything you want to stick at the end of the version number, e.g. '-RC1'
    `build_number` is the build number, which defaults to the value emitted by the `increment_build_number` action
  LIST

  [
    "This will automatically tag your build with the following format: `<grouping>/<lane>/<prefix><build_number><postfix>`, where:".markdown_preserve_newlines,
    list,
    "For example, for build 1234 in the 'appstore' lane, it will tag the commit with `builds/appstore/1234`."
  ].join("\n")
end

.example_codeObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 108

def self.example_code
  [
    'add_git_tag # simple tag with default values',
    'add_git_tag(
      grouping: "fastlane-builds",
      includes_lane: true,
      prefix: "v",
      postfix: "-RC1",
      build_number: 123
    )',
    '# Alternatively, you can specify your own tag. Note that if you do specify a tag, all other arguments are ignored.
    add_git_tag(
      tag: "my_custom_tag"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



133
134
135
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 133

def self.is_supported?(platform)
  true
end

.run(options) ⇒ Object



5
6
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
# File 'fastlane/lib/fastlane/actions/add_git_tag.rb', line 5

def self.run(options)
  # lane name in lane_context could be nil because you can just call $fastlane add_git_tag which has no context
  lane_name = Actions.lane_context[Actions::SharedValues::LANE_NAME].to_s.delete(' ') # no spaces allowed

  if options[:tag]
    tag = options[:tag]
  elsif options[:build_number]
    tag_components = [options[:grouping]]
    tag_components << lane_name if options[:includes_lane]
    tag_components << "#{options[:prefix]}#{options[:build_number]}#{options[:postfix]}"
    tag = tag_components.join('/')
  else
    UI.user_error!("No value found for 'tag' or 'build_number'. At least one of them must be provided. Note that if you do specify a tag, all other arguments are ignored.")
  end
  message = options[:message] || "#{tag} (fastlane)"

  cmd = ['git tag']

  cmd << ["-am #{message.shellescape}"]
  cmd << '--force' if options[:force]
  cmd << '-s' if options[:sign]
  cmd << tag.shellescape
  cmd << options[:commit].to_s if options[:commit]

  UI.message("Adding git tag '#{tag}' 🎯.")
  Actions.sh(cmd.join(' '))
end