Skip to content

Commit 4891997

Browse files
committed
Add exclude parameter to find_previous_tag action
1 parent 0fbf3f0 commit 4891997

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _None_
1010

1111
### New Features
1212

13-
_None_
13+
- Added optional `exclude` parameter to `find_previous_tag` action, mapping to git's `--exclude` flag. This allows skipping beta/pre-release tags when searching for the previous stable release tag [#PR]
1414

1515
### Bug Fixes
1616

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

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

1213
# Make sure we have all the latest tags fetched locally
1314
Actions.sh('git', 'fetch', '--tags', '--force') { nil }
@@ -17,6 +18,7 @@ def self.run(params)
1718
# Finally find the previous tag matching the provided pattern, and that is not the current commit
1819
git_cmd = %w[git describe --tags --abbrev=0]
1920
git_cmd += ['--match', tag_pattern] unless tag_pattern.nil?
21+
git_cmd += ['--exclude', exclude_pattern] unless exclude_pattern.nil?
2022
git_cmd += ['--exclude', current_commit_tag] unless current_commit_tag.empty?
2123
Actions.sh(*git_cmd) { |exit_status, stdout, _| exit_status.success? ? stdout.chomp : nil }
2224
end
@@ -38,7 +40,8 @@ def self.details
3840
Uses `git describe --tags --abbrev=0 --match … --exclude …` to find the previous git tag
3941
reachable from the current commit and that matches a specific naming pattern
4042
41-
e.g. `find_previous_tag(pattern: '12.3.*.*')`, `find_previous_tag(pattern: '12.3-rc-*')`
43+
e.g. `find_previous_tag(pattern: '12.3.*.*')`, `find_previous_tag(pattern: '12.3-rc-*')`,
44+
`find_previous_tag(pattern: 'v*', exclude: '*beta*')`
4245
DETAILS
4346
end
4447

@@ -49,6 +52,11 @@ def self.available_options
4952
optional: true,
5053
default_value: nil,
5154
type: String),
55+
FastlaneCore::ConfigItem.new(key: :exclude,
56+
description: 'An _fnmatch_-style pattern of tags to exclude from the search (maps to `git describe --exclude`)',
57+
optional: true,
58+
default_value: nil,
59+
type: String),
5260
]
5361
end
5462

spec/find_previous_tag_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,38 @@ def stub_main_command(expected_command, stdout:, success: true)
6565
expect(tag).to eq('12.2')
6666
end
6767

68+
it 'excludes tags matching the exclude pattern' do
69+
# Arrange
70+
stub_current_commit_tag(nil)
71+
stub_main_command(
72+
%w[git describe --tags --abbrev=0 --match v* --exclude *beta*],
73+
stdout: 'v1.7.3'
74+
)
75+
# Act
76+
tag = run_described_fastlane_action(
77+
pattern: 'v*',
78+
exclude: '*beta*'
79+
)
80+
# Assert
81+
expect(tag).to eq('v1.7.3')
82+
end
83+
84+
it 'excludes both the exclude pattern and the current commit tag' do
85+
# Arrange
86+
stub_current_commit_tag('v1.8.0')
87+
stub_main_command(
88+
%w[git describe --tags --abbrev=0 --match v* --exclude *beta* --exclude v1.8.0],
89+
stdout: 'v1.7.3'
90+
)
91+
# Act
92+
tag = run_described_fastlane_action(
93+
pattern: 'v*',
94+
exclude: '*beta*'
95+
)
96+
# Assert
97+
expect(tag).to eq('v1.7.3')
98+
end
99+
68100
it 'returns nil if no previous commit could be found' do
69101
# Arrange
70102
stub_current_commit_tag(nil)

0 commit comments

Comments
 (0)