diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /tooling | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'tooling')
-rwxr-xr-x | tooling/bin/find_foss_tests | 12 | ||||
-rw-r--r-- | tooling/lib/tooling/images.rb | 56 |
2 files changed, 60 insertions, 8 deletions
diff --git a/tooling/bin/find_foss_tests b/tooling/bin/find_foss_tests index c694210ad40..9cd8a616ad0 100755 --- a/tooling/bin/find_foss_tests +++ b/tooling/bin/find_foss_tests @@ -1,10 +1,8 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require_relative '../../lib/gitlab/popen' -require_relative '../lib/tooling/test_file_finder' - require 'gitlab' +require 'test_file_finder' gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '') @@ -21,9 +19,7 @@ mr_iid = ENV.fetch('CI_MERGE_REQUEST_IID') mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid) changed_files = mr_changes.changes.map { |change| change['new_path'] } -tests_to_run = changed_files.flat_map do |file| - test_files = Tooling::TestFileFinder.new(file, foss_test_only: true).test_files - test_files.select { |f| File.exist?(f) } -end +mapping = TestFileFinder::Mapping.load('tests.yml') +test_files = TestFileFinder::FileFinder.new(paths: changed_files, mapping: mapping).test_files -File.write(output_file, tests_to_run.uniq.join(' ')) +File.write(output_file, test_files.uniq.join(' ')) diff --git a/tooling/lib/tooling/images.rb b/tooling/lib/tooling/images.rb new file mode 100644 index 00000000000..d0c464b983c --- /dev/null +++ b/tooling/lib/tooling/images.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module Tooling + module Image + # Determine the tolerance till when we run pngquant in a loop + TOLERANCE = 10000 + + def self.check_executables + unless system('pngquant --version', out: File::NULL) + warn( + 'Error: pngquant executable was not detected in the system.', + 'Download pngquant at https://pngquant.org/ and place the executable in /usr/local/bin' + ) + abort + end + + unless system('gm version', out: File::NULL) + warn( + 'Error: gm executable was not detected in the system.', + 'Please install imagemagick: brew install imagemagick or sudo apt install imagemagick' + ) + abort + end + end + + def self.compress_image(file, keep_original = false) + check_executables + + compressed_file = "#{file}.compressed" + FileUtils.copy(file, compressed_file) + + pngquant_file = PngQuantizator::Image.new(compressed_file) + + # Run the image repeatedly through pngquant until + # the change in file size is within TOLERANCE + # or the loop count is above 1000 + 1000.times do + before = File.size(compressed_file) + pngquant_file.quantize! + after = File.size(compressed_file) + break if before - after <= TOLERANCE + end + + savings = File.size(file) - File.size(compressed_file) + is_uncompressed = savings > TOLERANCE + + if is_uncompressed && !keep_original + FileUtils.copy(compressed_file, file) + end + + FileUtils.remove(compressed_file) + + [is_uncompressed, savings] + end + end +end |