debian-mirror-gitlab/scripts/docs_screenshots.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2020-11-24 15:15:51 +05:30
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'png_quantizator'
require 'open3'
require 'parallel'
2021-12-11 22:18:48 +05:30
require_relative '../tooling/lib/tooling/image'
2020-11-24 15:15:51 +05:30
generator = ARGV[0]
milestone = ARGV[1]
unless generator
warn('Error: missing generator, please supply one')
abort
end
unless milestone
warn('Error: missing milestone, please supply one')
abort
end
def rename_image(file, milestone)
path = File.dirname(file)
2021-01-03 14:25:43 +05:30
basename = File.basename(file, ".*")
2020-11-24 15:15:51 +05:30
final_name = File.join(path, "#{basename}_v#{milestone}.png")
FileUtils.mv(file, final_name)
end
system('spring', 'rspec', generator)
files = []
Open3.popen3("git diff --name-only -- '*.png'") do |stdin, stdout, stderr, thread|
files.concat stdout.read.chomp.split("\n")
end
Open3.popen3("git status --porcelain -- '*.png'") do |stdin, stdout, stderr, thread|
files.concat stdout.read.chomp.split("?? ")
end
files.reject!(&:empty?)
if files.empty?
puts "No file generated, did you select the right screenshot generator?"
else
puts "Compressing newly generated screenshots"
Parallel.each(files) do |file|
file_path = File.join(Dir.pwd, file.to_s.strip)
was_uncompressed, savings = Tooling::Image.compress_image(file_path)
rename_image(file_path, milestone)
if was_uncompressed
puts "#{file} was reduced by #{savings} bytes."
else
puts "Skipping already compressed file: #{file}."
end
end
end