From 4891997e6ea72c58fa158895f00cc9129fcd7e15 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 24 Feb 2026 12:56:39 +0100 Subject: [PATCH 1/5] Add `exclude` parameter to `find_previous_tag` action --- CHANGELOG.md | 2 +- .../actions/common/find_previous_tag.rb | 10 +++++- spec/find_previous_tag_spec.rb | 32 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e88e62b..8d2d4d1ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -_None_ +- 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] ### Bug Fixes diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb index bd627d494..e1648f7fa 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb @@ -8,6 +8,7 @@ module Actions class FindPreviousTagAction < Action def self.run(params) tag_pattern = params[:pattern] + exclude_pattern = params[:exclude] # Make sure we have all the latest tags fetched locally Actions.sh('git', 'fetch', '--tags', '--force') { nil } @@ -17,6 +18,7 @@ def self.run(params) # 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', exclude_pattern] unless exclude_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 @@ -38,7 +40,8 @@ def self.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-*')` + e.g. `find_previous_tag(pattern: '12.3.*.*')`, `find_previous_tag(pattern: '12.3-rc-*')`, + `find_previous_tag(pattern: 'v*', exclude: '*beta*')` DETAILS end @@ -49,6 +52,11 @@ def self.available_options optional: true, default_value: nil, type: String), + FastlaneCore::ConfigItem.new(key: :exclude, + description: 'An _fnmatch_-style pattern of tags to exclude from the search (maps to `git describe --exclude`)', + optional: true, + default_value: nil, + type: String), ] end diff --git a/spec/find_previous_tag_spec.rb b/spec/find_previous_tag_spec.rb index 909b1cafb..500b52346 100644 --- a/spec/find_previous_tag_spec.rb +++ b/spec/find_previous_tag_spec.rb @@ -65,6 +65,38 @@ def stub_main_command(expected_command, stdout:, success: true) expect(tag).to eq('12.2') end + it 'excludes tags matching the exclude pattern' do + # Arrange + stub_current_commit_tag(nil) + stub_main_command( + %w[git describe --tags --abbrev=0 --match v* --exclude *beta*], + stdout: 'v1.7.3' + ) + # Act + tag = run_described_fastlane_action( + pattern: 'v*', + exclude: '*beta*' + ) + # Assert + expect(tag).to eq('v1.7.3') + end + + it 'excludes both the exclude pattern and the current commit tag' do + # Arrange + stub_current_commit_tag('v1.8.0') + stub_main_command( + %w[git describe --tags --abbrev=0 --match v* --exclude *beta* --exclude v1.8.0], + stdout: 'v1.7.3' + ) + # Act + tag = run_described_fastlane_action( + pattern: 'v*', + exclude: '*beta*' + ) + # Assert + expect(tag).to eq('v1.7.3') + end + it 'returns nil if no previous commit could be found' do # Arrange stub_current_commit_tag(nil) From 79e12ace0b3e73436c738ee210ef1be1b5561402 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 24 Feb 2026 13:06:18 +0100 Subject: [PATCH 2/5] Update PR reference in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2d4d1ca..1f6dff4b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ _None_ ### New Features -- 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] +- 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 [#696] ### Bug Fixes From 4208ed79c78617ebc1e41fc4e1d01c4789fe480a Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 24 Feb 2026 13:52:36 +0100 Subject: [PATCH 3/5] Support multiple exclude patterns via array --- .../actions/common/find_previous_tag.rb | 12 +++++++----- spec/find_previous_tag_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb index e1648f7fa..05fdc9942 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb @@ -8,7 +8,7 @@ module Actions class FindPreviousTagAction < Action def self.run(params) tag_pattern = params[:pattern] - exclude_pattern = params[:exclude] + exclude_patterns = Array(params[:exclude]) # Make sure we have all the latest tags fetched locally Actions.sh('git', 'fetch', '--tags', '--force') { nil } @@ -18,7 +18,7 @@ def self.run(params) # 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', exclude_pattern] unless exclude_pattern.nil? + exclude_patterns.each { |p| git_cmd += ['--exclude', p] } 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 @@ -41,7 +41,8 @@ def self.details 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-*')`, - `find_previous_tag(pattern: 'v*', exclude: '*beta*')` + `find_previous_tag(pattern: 'v*', exclude: '*beta*')`, + `find_previous_tag(pattern: 'v*', exclude: ['*alpha*', '*beta*'])` DETAILS end @@ -53,10 +54,11 @@ def self.available_options default_value: nil, type: String), FastlaneCore::ConfigItem.new(key: :exclude, - description: 'An _fnmatch_-style pattern of tags to exclude from the search (maps to `git describe --exclude`)', + description: 'One or more _fnmatch_-style patterns of tags to exclude from the search (maps to `git describe --exclude`). ' \ + 'Can be a single string or an array of strings', optional: true, default_value: nil, - type: String), + is_string: false), ] end diff --git a/spec/find_previous_tag_spec.rb b/spec/find_previous_tag_spec.rb index 500b52346..e25b6fe58 100644 --- a/spec/find_previous_tag_spec.rb +++ b/spec/find_previous_tag_spec.rb @@ -97,6 +97,22 @@ def stub_main_command(expected_command, stdout:, success: true) expect(tag).to eq('v1.7.3') end + it 'excludes tags matching multiple exclude patterns' do + # Arrange + stub_current_commit_tag(nil) + stub_main_command( + %w[git describe --tags --abbrev=0 --match v* --exclude *alpha* --exclude *beta*], + stdout: 'v1.7.3' + ) + # Act + tag = run_described_fastlane_action( + pattern: 'v*', + exclude: %w[*alpha* *beta*] + ) + # Assert + expect(tag).to eq('v1.7.3') + end + it 'returns nil if no previous commit could be found' do # Arrange stub_current_commit_tag(nil) From d09c29d6e660919c3acce557cba86ad8ec4d0771 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 24 Feb 2026 14:28:51 +0100 Subject: [PATCH 4/5] Use type: Array for exclude parameter instead of deprecated is_string --- .../actions/common/find_previous_tag.rb | 9 ++++----- spec/find_previous_tag_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb index 05fdc9942..dad0a771f 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/find_previous_tag.rb @@ -8,7 +8,7 @@ module Actions class FindPreviousTagAction < Action def self.run(params) tag_pattern = params[:pattern] - exclude_patterns = Array(params[:exclude]) + exclude_patterns = params[:exclude] || [] # Make sure we have all the latest tags fetched locally Actions.sh('git', 'fetch', '--tags', '--force') { nil } @@ -41,7 +41,7 @@ def self.details 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-*')`, - `find_previous_tag(pattern: 'v*', exclude: '*beta*')`, + `find_previous_tag(pattern: 'v*', exclude: ['*beta*'])`, `find_previous_tag(pattern: 'v*', exclude: ['*alpha*', '*beta*'])` DETAILS end @@ -54,11 +54,10 @@ def self.available_options default_value: nil, type: String), FastlaneCore::ConfigItem.new(key: :exclude, - description: 'One or more _fnmatch_-style patterns of tags to exclude from the search (maps to `git describe --exclude`). ' \ - 'Can be a single string or an array of strings', + description: 'An array of _fnmatch_-style patterns of tags to exclude from the search (maps to `git describe --exclude`)', optional: true, default_value: nil, - is_string: false), + type: Array), ] end diff --git a/spec/find_previous_tag_spec.rb b/spec/find_previous_tag_spec.rb index e25b6fe58..6dd18fb2b 100644 --- a/spec/find_previous_tag_spec.rb +++ b/spec/find_previous_tag_spec.rb @@ -75,7 +75,7 @@ def stub_main_command(expected_command, stdout:, success: true) # Act tag = run_described_fastlane_action( pattern: 'v*', - exclude: '*beta*' + exclude: ['*beta*'] ) # Assert expect(tag).to eq('v1.7.3') @@ -91,7 +91,7 @@ def stub_main_command(expected_command, stdout:, success: true) # Act tag = run_described_fastlane_action( pattern: 'v*', - exclude: '*beta*' + exclude: ['*beta*'] ) # Assert expect(tag).to eq('v1.7.3') From 4121687e17373727785961ee14e797da0bbbd014 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 24 Feb 2026 14:32:08 +0100 Subject: [PATCH 5/5] Add test for single string auto-conversion to array --- spec/find_previous_tag_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/find_previous_tag_spec.rb b/spec/find_previous_tag_spec.rb index 6dd18fb2b..3ccd0d4c6 100644 --- a/spec/find_previous_tag_spec.rb +++ b/spec/find_previous_tag_spec.rb @@ -97,6 +97,22 @@ def stub_main_command(expected_command, stdout:, success: true) expect(tag).to eq('v1.7.3') end + it 'auto-converts a single exclude string into an array' do + # Arrange + stub_current_commit_tag(nil) + stub_main_command( + %w[git describe --tags --abbrev=0 --match v* --exclude *beta*], + stdout: 'v1.7.3' + ) + # Act — Fastlane's ConfigItem auto-converts a String to Array when type is Array + tag = run_described_fastlane_action( + pattern: 'v*', + exclude: '*beta*' + ) + # Assert + expect(tag).to eq('v1.7.3') + end + it 'excludes tags matching multiple exclude patterns' do # Arrange stub_current_commit_tag(nil)