Class: Fastlane::Actions::FindPreviousTagAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



26
27
28
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 26

def self.authors
  ['Automattic']
end

.available_optionsObject



43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 43

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :pattern,
                                 description: 'The _fnmatch_-style pattern to use when searching for the previous tag',
                                 optional: true,
                                 default_value: nil,
                                 type: String),
  ]
end

.descriptionObject



22
23
24
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 22

def self.description
  'Use `git describe` to find the previous tag matching a specific pattern'
end

.detailsObject



34
35
36
37
38
39
40
41
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 34

def self.details
  <<~DETAILS
    Uses `git describe --tags --abbrev=0 --match … --exclude …` to find the previous git tag
    reachable from the current commit and that matches a specific naming pattern

    e.g. `find_previous_tag(pattern: '12.3.*.*')`, `find_previous_tag(pattern: '12.3-rc-*')`
  DETAILS
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 53

def self.is_supported?(platform)
  true
end

.return_valueObject



30
31
32
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 30

def self.return_value
  'The name of the previous tag matching the pattern, or nil if none was found'
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb', line 7

def self.run(params)
  tag_pattern = params[:pattern]

  # Make sure we have all the latest tags fetched locally
  Actions.sh('git', 'fetch', '--tags', '--force') { nil }
  # Check if the current commit has a tag, so we can exclude it and not risk returning the current commit tag instead of really-previous one
  current_commit_tag = Actions.sh('git describe --tags --exact-match 2>/dev/null || true').chomp

  # Finally find the previous tag matching the provided pattern, and that is not the current commit
  git_cmd = %w[git describe --tags --abbrev=0]
  git_cmd += ['--match', tag_pattern] unless tag_pattern.nil?
  git_cmd += ['--exclude', current_commit_tag] unless current_commit_tag.empty?
  Actions.sh(*git_cmd) { |exit_status, stdout, _| exit_status.success? ? stdout.chomp : nil }
end