Skip to content

Commit 4208ed7

Browse files
committed
Support multiple exclude patterns via array
1 parent 79e12ac commit 4208ed7

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Actions
88
class FindPreviousTagAction < Action
99
def self.run(params)
1010
tag_pattern = params[:pattern]
11-
exclude_pattern = params[:exclude]
11+
exclude_patterns = Array(params[:exclude])
1212

1313
# Make sure we have all the latest tags fetched locally
1414
Actions.sh('git', 'fetch', '--tags', '--force') { nil }
@@ -18,7 +18,7 @@ def self.run(params)
1818
# Finally find the previous tag matching the provided pattern, and that is not the current commit
1919
git_cmd = %w[git describe --tags --abbrev=0]
2020
git_cmd += ['--match', tag_pattern] unless tag_pattern.nil?
21-
git_cmd += ['--exclude', exclude_pattern] unless exclude_pattern.nil?
21+
exclude_patterns.each { |p| git_cmd += ['--exclude', p] }
2222
git_cmd += ['--exclude', current_commit_tag] unless current_commit_tag.empty?
2323
Actions.sh(*git_cmd) { |exit_status, stdout, _| exit_status.success? ? stdout.chomp : nil }
2424
end
@@ -41,7 +41,8 @@ def self.details
4141
reachable from the current commit and that matches a specific naming pattern
4242
4343
e.g. `find_previous_tag(pattern: '12.3.*.*')`, `find_previous_tag(pattern: '12.3-rc-*')`,
44-
`find_previous_tag(pattern: 'v*', exclude: '*beta*')`
44+
`find_previous_tag(pattern: 'v*', exclude: '*beta*')`,
45+
`find_previous_tag(pattern: 'v*', exclude: ['*alpha*', '*beta*'])`
4546
DETAILS
4647
end
4748

@@ -53,10 +54,11 @@ def self.available_options
5354
default_value: nil,
5455
type: String),
5556
FastlaneCore::ConfigItem.new(key: :exclude,
56-
description: 'An _fnmatch_-style pattern of tags to exclude from the search (maps to `git describe --exclude`)',
57+
description: 'One or more _fnmatch_-style patterns of tags to exclude from the search (maps to `git describe --exclude`). ' \
58+
'Can be a single string or an array of strings',
5759
optional: true,
5860
default_value: nil,
59-
type: String),
61+
is_string: false),
6062
]
6163
end
6264

spec/find_previous_tag_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def stub_main_command(expected_command, stdout:, success: true)
9797
expect(tag).to eq('v1.7.3')
9898
end
9999

100+
it 'excludes tags matching multiple exclude patterns' do
101+
# Arrange
102+
stub_current_commit_tag(nil)
103+
stub_main_command(
104+
%w[git describe --tags --abbrev=0 --match v* --exclude *alpha* --exclude *beta*],
105+
stdout: 'v1.7.3'
106+
)
107+
# Act
108+
tag = run_described_fastlane_action(
109+
pattern: 'v*',
110+
exclude: %w[*alpha* *beta*]
111+
)
112+
# Assert
113+
expect(tag).to eq('v1.7.3')
114+
end
115+
100116
it 'returns nil if no previous commit could be found' do
101117
# Arrange
102118
stub_current_commit_tag(nil)

0 commit comments

Comments
 (0)