diff --git a/scripts/gitlab_component_helpers.sh b/scripts/gitlab_component_helpers.sh index 2e816330eb6874bc1458f865063fa3dd6d7b2a90..8b31f79d5c588b7c3f45770c90e759dcb0ffa178 100644 --- a/scripts/gitlab_component_helpers.sh +++ b/scripts/gitlab_component_helpers.sh @@ -118,7 +118,7 @@ function check_fixtures_download() { if [[ -z "${CI_MERGE_REQUEST_IID:-}" ]]; then return 1 else - if tooling/bin/find_only_js_changes && ! fixtures_archive_doesnt_exist; then + if tooling/bin/find_only_allowed_files_changes && ! fixtures_archive_doesnt_exist; then return 0 else return 1 diff --git a/spec/tooling/lib/tooling/find_changes_spec.rb b/spec/tooling/lib/tooling/find_changes_spec.rb index 37e590858cffc3ac38245cef4623d6f636584c28..43c3da5699da33de98357f50e28a7b2bdc8498c8 100644 --- a/spec/tooling/lib/tooling/find_changes_spec.rb +++ b/spec/tooling/lib/tooling/find_changes_spec.rb @@ -182,8 +182,8 @@ end end - describe '#only_js_files_changed' do - subject { instance.only_js_files_changed } + describe '#only_allowed_files_changed' do + subject { instance.only_allowed_files_changed } context 'when fetching changes from changed files' do let(:from) { :changed_files } @@ -200,8 +200,16 @@ end end - context 'when changed files contain not only *.js changes' do - let(:changed_files_file_content) { 'a.js b.rb' } + context 'when changed files contain both *.vue and *.js changes' do + let(:changed_files_file_content) { 'a.js b.vue' } + + it 'returns true' do + expect(subject).to be true + end + end + + context 'when changed files contain not allowed changes' do + let(:changed_files_file_content) { 'a.js b.vue c.rb' } it 'returns false' do expect(subject).to be false diff --git a/tooling/bin/find_only_allowed_files_changes b/tooling/bin/find_only_allowed_files_changes new file mode 100755 index 0000000000000000000000000000000000000000..c40048c66facab90bc66a9d30555333671216358 --- /dev/null +++ b/tooling/bin/find_only_allowed_files_changes @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require_relative '../lib/tooling/find_changes' + +if Tooling::FindChanges.new(from: :api).only_allowed_files_changed + puts "Only files with extensions #{ALLOWED_FILE_TYPES.join(', ')} were changed" + exit 0 +else + puts "Changes were made to files with extensions other than #{ALLOWED_FILE_TYPES.join(', ')}" + exit 1 +end diff --git a/tooling/bin/find_only_js_changes b/tooling/bin/find_only_js_changes deleted file mode 100755 index a69ee64fe141c626b08990c3336d123ea97e5863..0000000000000000000000000000000000000000 --- a/tooling/bin/find_only_js_changes +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require_relative '../lib/tooling/find_changes' - -if Tooling::FindChanges.new(from: :api).only_js_files_changed - puts "Only JS files were changed" - exit 0 -else - puts "Changes were made to files other than JS files" - exit 1 -end diff --git a/tooling/lib/tooling/find_changes.rb b/tooling/lib/tooling/find_changes.rb index 25381e1a894467170e351019b337dba250434c34..c498c83d24b8a96dc58379eb9b033a1d2b06d642 100755 --- a/tooling/lib/tooling/find_changes.rb +++ b/tooling/lib/tooling/find_changes.rb @@ -8,6 +8,8 @@ module Tooling class FindChanges include Helpers::PredictiveTestsHelper + ALLOWED_FILE_TYPES = ['.js', '.vue', '.md', '.scss'].freeze + def initialize( from:, changed_files_pathname: nil, @@ -41,8 +43,8 @@ def execute end end - def only_js_files_changed - file_changes.any? && file_changes.all? { |file| file.end_with?('.js') } + def only_allowed_files_changed + file_changes.any? && file_changes.all? { |file| ALLOWED_FILE_TYPES.include?(File.extname(file)) } end private