Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/tasks
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 16:16:36 +0300
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /lib/tasks
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/gemojione.rake245
-rw-r--r--lib/tasks/gitlab/db.rake45
-rw-r--r--lib/tasks/gitlab/docs/compile_deprecations.rake2
-rw-r--r--lib/tasks/gitlab/gitaly.rake3
-rw-r--r--lib/tasks/gitlab/info.rake4
-rw-r--r--lib/tasks/gitlab/sidekiq.rake7
-rw-r--r--lib/tasks/gitlab/storage.rake2
-rw-r--r--lib/tasks/haml-lint.rake11
-rw-r--r--lib/tasks/tanuki_emoji.rake260
9 files changed, 299 insertions, 280 deletions
diff --git a/lib/tasks/gemojione.rake b/lib/tasks/gemojione.rake
deleted file mode 100644
index a4600a0ed16..00000000000
--- a/lib/tasks/gemojione.rake
+++ /dev/null
@@ -1,245 +0,0 @@
-# frozen_string_literal: true
-
-namespace :gemojione do
- desc 'Generates Emoji SHA256 digests'
-
- task aliases: ['yarn:check', 'environment'] do
- require 'json'
-
- aliases = {}
-
- index_file = File.join(Rails.root, 'fixtures', 'emojis', 'index.json')
- index = Gitlab::Json.parse(File.read(index_file))
-
- index.each_pair do |key, data|
- data['aliases'].each do |a|
- a.tr!(':', '')
-
- aliases[a] = key
- end
- end
-
- out = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json')
- File.open(out, 'w') do |handle|
- handle.write(Gitlab::Json.pretty_generate(aliases, indent: ' ', space: '', space_before: ''))
- end
- end
-
- task digests: ['yarn:check', 'environment'] do
- require 'digest/sha2'
- require 'json'
-
- # We don't have `node_modules` available in built versions of GitLab
- FileUtils.cp_r(Rails.root.join('node_modules', 'emoji-unicode-version', 'emoji-unicode-version-map.json'), File.join(Rails.root, 'fixtures', 'emojis'))
-
- dir = Gemojione.images_path
- resultant_emoji_map = {}
- resultant_emoji_map_new = {}
-
- Gitlab::Emoji.emojis.each do |name, emoji_hash|
- # Ignore aliases
- unless Gitlab::Emoji.emojis_aliases.key?(name)
- fpath = File.join(dir, "#{emoji_hash['unicode']}.png")
- hash_digest = Digest::SHA256.file(fpath).hexdigest
-
- category = emoji_hash['category']
- if name == 'gay_pride_flag'
- category = 'flags'
- end
-
- entry = {
- category: category,
- moji: emoji_hash['moji'],
- description: emoji_hash['description'],
- unicodeVersion: Gitlab::Emoji.emoji_unicode_version(name),
- digest: hash_digest
- }
-
- resultant_emoji_map[name] = entry
-
- # Our new map is only characters to make the json substantially smaller
- new_entry = {
- c: category,
- e: emoji_hash['moji'],
- d: emoji_hash['description'],
- u: Gitlab::Emoji.emoji_unicode_version(name)
- }
-
- resultant_emoji_map_new[name] = new_entry
- end
- end
-
- out = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
- File.open(out, 'w') do |handle|
- handle.write(Gitlab::Json.pretty_generate(resultant_emoji_map))
- end
-
- out_new = File.join(Rails.root, 'public', '-', 'emojis', '1', 'emojis.json')
- File.open(out_new, 'w') do |handle|
- handle.write(Gitlab::Json.pretty_generate(resultant_emoji_map_new))
- end
- end
-
- # This task will generate a standard and Retina sprite of all of the current
- # Gemojione Emojis, with the accompanying SCSS map.
- #
- # It will not appear in `rake -T` output, and the dependent gems are not
- # included in the Gemfile by default, because this task will only be needed
- # occasionally, such as when new Emojis are added to Gemojione.
- task sprite: :environment do
- begin
- require 'sprite_factory'
- require 'rmagick'
- rescue LoadError
- # noop
- end
-
- check_requirements!
-
- SIZE = 20
- RETINA = SIZE * 2
-
- # Update these values to the width and height of the spritesheet when
- # new emoji are added.
- SPRITESHEET_WIDTH = 860
- SPRITESHEET_HEIGHT = 840
-
- # Set up a map to rename image files
- emoji_unicode_string_to_name_map = {}
- Gitlab::Emoji.emojis.each do |name, emoji_hash|
- # Ignore aliases
- unless Gitlab::Emoji.emojis_aliases.key?(name)
- emoji_unicode_string_to_name_map[emoji_hash['unicode']] = name
- end
- end
-
- # Copy the Gemojione assets to the temporary folder for renaming
- emoji_dir = "app/assets/images/emoji"
- FileUtils.rm_rf(emoji_dir)
- FileUtils.mkdir_p(emoji_dir, mode: 0700)
- FileUtils.cp_r(File.join(Gemojione.images_path, '.'), emoji_dir)
- Dir[File.join(emoji_dir, "**/*.png")].each do |png|
- image_path = png
- rename_to_named_emoji_image!(emoji_unicode_string_to_name_map, image_path)
- end
-
- Dir.mktmpdir do |tmpdir|
- FileUtils.cp_r(File.join(emoji_dir, '.'), tmpdir)
-
- Dir.chdir(tmpdir) do
- Dir["**/*.png"].each do |png|
- tmp_image_path = File.join(tmpdir, png)
- resize!(tmp_image_path, SIZE)
- end
- end
-
- style_path = Rails.root.join(*%w(app assets stylesheets framework emoji_sprites.scss))
-
- # Combine the resized assets into a packed sprite and re-generate the SCSS
- SpriteFactory.cssurl = "image-url('$IMAGE')"
- SpriteFactory.run!(tmpdir, {
- output_style: style_path,
- output_image: "app/assets/images/emoji.png",
- selector: '.emoji-',
- style: :scss,
- nocomments: true,
- pngcrush: true,
- layout: :packed
- })
-
- # SpriteFactory's SCSS is a bit too verbose for our purposes here, so
- # let's simplify it
- system(%Q(sed -i '' "s/width: #{SIZE}px; height: #{SIZE}px; background: image-url('emoji.png')/background-position:/" #{style_path}))
- system(%Q(sed -i '' "s/ no-repeat//" #{style_path}))
- system(%Q(sed -i '' "s/ 0px/ 0/g" #{style_path}))
-
- # Append a generic rule that applies to all Emojis
- File.open(style_path, 'a') do |f|
- f.puts
- f.puts <<-CSS.strip_heredoc
- .emoji-icon {
- background-image: image-url('emoji.png');
- background-repeat: no-repeat;
- color: transparent;
- text-indent: -99em;
- height: #{SIZE}px;
- width: #{SIZE}px;
-
- @media only screen and (-webkit-min-device-pixel-ratio: 2),
- only screen and (min--moz-device-pixel-ratio: 2),
- only screen and (-o-min-device-pixel-ratio: 2/1),
- only screen and (min-device-pixel-ratio: 2),
- only screen and (min-resolution: 192dpi),
- only screen and (min-resolution: 2dppx) {
- background-image: image-url('emoji@2x.png');
- background-size: #{SPRITESHEET_WIDTH}px #{SPRITESHEET_HEIGHT}px;
- }
- }
- CSS
- end
- end
-
- # Now do it again but for Retina
- Dir.mktmpdir do |tmpdir|
- # Copy the Gemojione assets to the temporary folder for resizing
- FileUtils.cp_r(File.join(emoji_dir, '.'), tmpdir)
-
- Dir.chdir(tmpdir) do
- Dir["**/*.png"].each do |png|
- tmp_image_path = File.join(tmpdir, png)
- resize!(tmp_image_path, RETINA)
- end
- end
-
- # Combine the resized assets into a packed sprite and re-generate the SCSS
- SpriteFactory.run!(tmpdir, {
- output_image: "app/assets/images/emoji@2x.png",
- style: false,
- nocomments: true,
- pngcrush: true,
- layout: :packed
- })
- end
- end
-
- def check_requirements!
- return if defined?(SpriteFactory) && defined?(Magick)
-
- puts <<-MSG.strip_heredoc
- This task is disabled by default and should only be run when the Gemojione
- gem is updated with new Emojis.
-
- To enable this task, *temporarily* add the following lines to Gemfile and
- re-bundle:
-
- gem 'sprite-factory'
- gem 'rmagick'
- MSG
-
- exit 1
- end
-
- def resize!(image_path, size)
- # Resize the image in-place, save it, and free the object
- image = Magick::Image.read(image_path).first
- image.resize!(size, size)
- image.write(image_path) { self.quality = 100 }
- image.destroy!
- end
-
- EMOJI_IMAGE_PATH_RE = /(.*?)(([0-9a-f]-?)+)\.png$/i.freeze
- def rename_to_named_emoji_image!(emoji_unicode_string_to_name_map, image_path)
- # Rename file from unicode to emoji name
- matches = EMOJI_IMAGE_PATH_RE.match(image_path)
- preceding_path = matches[1]
- unicode_string = matches[2]
- name = emoji_unicode_string_to_name_map[unicode_string]
- if name
- new_png_path = File.join(preceding_path, "#{name}.png")
- FileUtils.mv(image_path, new_png_path)
- new_png_path
- else
- puts "Warning: emoji_unicode_string_to_name_map missing entry for #{unicode_string}. Full path: #{image_path}"
- end
- end
-end
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake
index e2647021914..e83c4cbdb39 100644
--- a/lib/tasks/gitlab/db.rake
+++ b/lib/tasks/gitlab/db.rake
@@ -160,35 +160,44 @@ namespace :gitlab do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end
- desc 'reindex a regular index without downtime to eliminate bloat'
- task :reindex, [:index_name] => :environment do |_, args|
- unless Feature.enabled?(:database_reindexing, type: :ops)
+ desc 'execute reindexing without downtime to eliminate bloat'
+ task reindex: :environment do
+ unless Feature.enabled?(:database_reindexing, type: :ops, default_enabled: :yaml)
puts "This feature (database_reindexing) is currently disabled.".color(:yellow)
exit
end
- indexes = Gitlab::Database::PostgresIndex.reindexing_support
+ Gitlab::Database::EachDatabase.each_database_connection do |connection, connection_name|
+ Gitlab::Database::SharedModel.logger = Logger.new($stdout) if Gitlab::Utils.to_boolean(ENV['LOG_QUERIES_TO_CONSOLE'], default: false)
- if identifier = args[:index_name]
- raise ArgumentError, "Index name is not fully qualified with a schema: #{identifier}" unless identifier =~ /^\w+\.\w+$/
+ # Hack: Before we do actual reindexing work, create async indexes
+ Gitlab::Database::AsyncIndexes.create_pending_indexes! if Feature.enabled?(:database_async_index_creation, type: :ops)
- indexes = indexes.where(identifier: identifier)
-
- raise "Index not found or not supported: #{args[:index_name]}" if indexes.empty?
+ Gitlab::Database::Reindexing.automatic_reindexing
end
+ rescue StandardError => e
+ Gitlab::AppLogger.error(e)
+ raise
+ end
- ActiveRecord::Base.logger = Logger.new($stdout) if Gitlab::Utils.to_boolean(ENV['LOG_QUERIES_TO_CONSOLE'], default: false)
+ desc 'Enqueue an index for reindexing'
+ task :enqueue_reindexing_action, [:index_name, :database] => :environment do |_, args|
+ model = Gitlab::Database.database_base_models[args.fetch(:database, Gitlab::Database::PRIMARY_DATABASE_NAME)]
- # Cleanup leftover temporary indexes from previous, possibly aborted runs (if any)
- Gitlab::Database::Reindexing.cleanup_leftovers!
+ Gitlab::Database::SharedModel.using_connection(model.connection) do
+ queued_action = Gitlab::Database::PostgresIndex.find(args[:index_name]).queued_reindexing_actions.create!
- # Hack: Before we do actual reindexing work, create async indexes
- Gitlab::Database::AsyncIndexes.create_pending_indexes! if Feature.enabled?(:database_async_index_creation, type: :ops)
+ puts "Queued reindexing action: #{queued_action}"
+ puts "There are #{Gitlab::Database::Reindexing::QueuedAction.queued.size} queued actions in total."
+ end
- Gitlab::Database::Reindexing.perform(indexes)
- rescue StandardError => e
- Gitlab::AppLogger.error(e)
- raise
+ unless Feature.enabled?(:database_reindexing, type: :ops, default_enabled: :yaml)
+ puts <<~NOTE.color(:yellow)
+ Note: database_reindexing feature is currently disabled.
+
+ Enable with: Feature.enable(:database_reindexing)
+ NOTE
+ end
end
desc 'Check if there have been user additions to the database'
diff --git a/lib/tasks/gitlab/docs/compile_deprecations.rake b/lib/tasks/gitlab/docs/compile_deprecations.rake
index 0fd43775015..dc9788cb0b2 100644
--- a/lib/tasks/gitlab/docs/compile_deprecations.rake
+++ b/lib/tasks/gitlab/docs/compile_deprecations.rake
@@ -21,7 +21,7 @@ namespace :gitlab do
if doc == contents
puts "Deprecations doc is up to date."
else
- format_output('Deprecations doc is outdated! Please update it by running `bundle exec rake gitlab:docs:compile_deprecations`.')
+ format_output('Deprecations doc is outdated! You (or your technical writer) can update it by running `bin/rake gitlab:docs:compile_deprecations`.')
abort
end
end
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index ef58c9339f1..eabbb8652f1 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -67,7 +67,8 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
env["BUNDLE_DEPLOYMENT"] = 'false'
end
- Gitlab::Popen.popen([make_cmd], nil, env)
+ output, status = Gitlab::Popen.popen([make_cmd, 'all', 'git'], nil, env)
+ raise "Gitaly failed to compile: #{output}" unless status&.zero?
end
end
end
diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake
index 68395d10d24..02764b5d46f 100644
--- a/lib/tasks/gitlab/info.rake
+++ b/lib/tasks/gitlab/info.rake
@@ -68,8 +68,8 @@ namespace :gitlab do
puts "Version:\t#{Gitlab::VERSION}"
puts "Revision:\t#{Gitlab.revision}"
puts "Directory:\t#{Rails.root}"
- puts "DB Adapter:\t#{Gitlab::Database.main.human_adapter_name}"
- puts "DB Version:\t#{Gitlab::Database.main.version}"
+ puts "DB Adapter:\t#{ApplicationRecord.database.human_adapter_name}"
+ puts "DB Version:\t#{ApplicationRecord.database.version}"
puts "URL:\t\t#{Gitlab.config.gitlab.url}"
puts "HTTP Clone URL:\t#{http_clone_url}"
puts "SSH Clone URL:\t#{ssh_clone_url}"
diff --git a/lib/tasks/gitlab/sidekiq.rake b/lib/tasks/gitlab/sidekiq.rake
index 90ed91221ae..2e383065b64 100644
--- a/lib/tasks/gitlab/sidekiq.rake
+++ b/lib/tasks/gitlab/sidekiq.rake
@@ -36,13 +36,17 @@ namespace :gitlab do
# Do not edit it manually!
BANNER
- foss_workers, ee_workers = Gitlab::SidekiqConfig.workers_for_all_queues_yml
+ foss_workers, ee_workers, jh_workers = Gitlab::SidekiqConfig.workers_for_all_queues_yml
write_yaml(Gitlab::SidekiqConfig::FOSS_QUEUE_CONFIG_PATH, banner, foss_workers)
if Gitlab.ee?
write_yaml(Gitlab::SidekiqConfig::EE_QUEUE_CONFIG_PATH, banner, ee_workers)
end
+
+ if Gitlab.jh?
+ write_yaml(Gitlab::SidekiqConfig::JH_QUEUE_CONFIG_PATH, banner, jh_workers)
+ end
end
desc 'GitLab | Sidekiq | Validate that all_queues.yml matches worker definitions'
@@ -57,6 +61,7 @@ namespace :gitlab do
- #{Gitlab::SidekiqConfig::FOSS_QUEUE_CONFIG_PATH}
- #{Gitlab::SidekiqConfig::EE_QUEUE_CONFIG_PATH}
+ #{"- " + Gitlab::SidekiqConfig::JH_QUEUE_CONFIG_PATH if Gitlab.jh?}
MSG
end
diff --git a/lib/tasks/gitlab/storage.rake b/lib/tasks/gitlab/storage.rake
index fb9f9b9fe67..eb5eeed531f 100644
--- a/lib/tasks/gitlab/storage.rake
+++ b/lib/tasks/gitlab/storage.rake
@@ -170,7 +170,7 @@ namespace :gitlab do
inverval = (ENV['MAX_DATABASE_CONNECTION_CHECK_INTERVAL'] || 10).to_f
attempts.to_i.times do
- unless Gitlab::Database.main.exists?
+ unless ApplicationRecord.database.exists?
puts "Waiting until database is ready before continuing...".color(:yellow)
sleep inverval
end
diff --git a/lib/tasks/haml-lint.rake b/lib/tasks/haml-lint.rake
index 270793359e1..71e84d3795f 100644
--- a/lib/tasks/haml-lint.rake
+++ b/lib/tasks/haml-lint.rake
@@ -4,16 +4,5 @@ unless Rails.env.production?
require 'haml_lint/rake_task'
require Rails.root.join('haml_lint/inline_javascript')
- # Workaround for warnings from parser/current
- # Keep it even if it no longer emits any warnings,
- # because we'll still see warnings in console/server anyway,
- # and we don't need to break static-analysis for this.
- task :haml_lint do
- require 'parser'
- def Parser.warn(*args)
- puts(*args) # static-analysis ignores stdout if status is 0
- end
- end
-
HamlLint::RakeTask.new
end
diff --git a/lib/tasks/tanuki_emoji.rake b/lib/tasks/tanuki_emoji.rake
new file mode 100644
index 00000000000..98d3920c07f
--- /dev/null
+++ b/lib/tasks/tanuki_emoji.rake
@@ -0,0 +1,260 @@
+# frozen_string_literal: true
+
+namespace :tanuki_emoji do
+ desc 'Generates Emoji aliases fixtures'
+ task aliases: :environment do
+ aliases = {}
+
+ TanukiEmoji.index.all.each do |emoji|
+ emoji.aliases.each do |emoji_alias|
+ aliases[TanukiEmoji::Character.format_name(emoji_alias)] = emoji.name
+ end
+ end
+
+ aliases_json_file = File.join(Rails.root, 'fixtures', 'emojis', 'aliases.json')
+ File.open(aliases_json_file, 'w') do |handle|
+ handle.write(Gitlab::Json.pretty_generate(aliases, indent: ' ', space: '', space_before: ''))
+ end
+ end
+
+ desc 'Generates Emoji SHA256 digests'
+ task digests: :environment do
+ require 'digest/sha2'
+
+ digest_emoji_map = {}
+ emojis_map = {}
+
+ TanukiEmoji.index.all.each do |emoji|
+ emoji_path = Gitlab::Emoji.emoji_public_absolute_path.join("#{emoji.name}.png")
+
+ digest_entry = {
+ category: emoji.category,
+ moji: emoji.codepoints,
+ description: emoji.description,
+ unicodeVersion: emoji.unicode_version,
+ digest: Digest::SHA256.file(emoji_path).hexdigest
+ }
+
+ digest_emoji_map[emoji.name] = digest_entry
+
+ # Our new map is only characters to make the json substantially smaller
+ emoji_entry = {
+ c: emoji.category,
+ e: emoji.codepoints,
+ d: emoji.description,
+ u: emoji.unicode_version
+ }
+
+ emojis_map[emoji.name] = emoji_entry
+ end
+
+ digests_json = File.join(Rails.root, 'fixtures', 'emojis', 'digests.json')
+ File.open(digests_json, 'w') do |handle|
+ handle.write(Gitlab::Json.pretty_generate(digest_emoji_map))
+ end
+
+ emojis_json = Gitlab::Emoji.emoji_public_absolute_path.join('emojis.json')
+ File.open(emojis_json, 'w') do |handle|
+ handle.write(Gitlab::Json.pretty_generate(emojis_map))
+ end
+ end
+
+ desc 'Import emoji assets from TanukiEmoji to versioned folder'
+ task import: :environment do
+ require 'mini_magick'
+
+ # Setting to the same size as previous gemojione images
+ EMOJI_SIZE = 64
+
+ emoji_dir = Gitlab::Emoji.emoji_public_absolute_path
+
+ puts "Importing emojis into: #{emoji_dir} ..."
+
+ # Re-create the assets folder and copy emojis renaming them to use name instead of unicode hex
+ FileUtils.rm_rf(emoji_dir) if Dir.exist?(emoji_dir)
+ FileUtils.mkdir_p(emoji_dir, mode: 0700)
+
+ TanukiEmoji.index.all.each do |emoji|
+ source = File.join(TanukiEmoji.images_path, emoji.image_name)
+ destination = File.join(emoji_dir, "#{emoji.name}.png")
+
+ FileUtils.cp(source, destination)
+ resize!(destination, EMOJI_SIZE)
+ print emoji.codepoints
+ end
+
+ puts
+ puts 'Done!'
+ end
+
+ # This task will generate a standard and Retina sprite of all of the current
+ # TanukiEmoji Emojis, with the accompanying SCSS map.
+ #
+ # It will not appear in `rake -T` output, and the dependent gems are not
+ # included in the Gemfile by default, because this task will only be needed
+ # occasionally, such as when new Emojis are added to TanukiEmoji.
+ task sprite: :environment do
+ begin
+ require 'sprite_factory'
+ # Sprite-Factory still requires rmagick, but maybe could be migrated to support minimagick
+ # Upstream issue: https://github.com/jakesgordon/sprite-factory/issues/47#issuecomment-929302890
+ require 'rmagick'
+ rescue LoadError
+ # noop
+ end
+
+ check_requirements!
+
+ SIZE = 20
+ RETINA = SIZE * 2
+
+ # Update these values to the width and height of the spritesheet when
+ # new emoji are added.
+ SPRITESHEET_WIDTH = 860
+ SPRITESHEET_HEIGHT = 840
+
+ emoji_dir = Gitlab::Emoji.emoji_public_absolute_path
+
+ puts "Preparing sprites for regular size: #{SIZE}px..."
+
+ Dir.mktmpdir do |tmpdir|
+ FileUtils.cp_r(File.join(emoji_dir, '.'), tmpdir)
+
+ Dir.chdir(tmpdir) do
+ Dir["**/*.png"].each do |png|
+ tmp_image_path = File.join(tmpdir, png)
+ resize!(tmp_image_path, SIZE)
+ print '.'
+ end
+ end
+ puts ' Done!'
+
+ puts "\n"
+
+ style_path = Rails.root.join(*%w(app assets stylesheets emoji_sprites.scss))
+
+ print 'Compiling sprites regular sprites... '
+
+ # Combine the resized assets into a packed sprite and re-generate the SCSS
+ SpriteFactory.cssurl = "image-url('$IMAGE')"
+ SpriteFactory.run!(tmpdir, {
+ output_style: style_path,
+ output_image: "app/assets/images/emoji.png",
+ selector: '.emoji-',
+ style: :scss,
+ nocomments: true,
+ pngcrush: true,
+ layout: :packed
+ })
+
+ # SpriteFactory's SCSS is a bit too verbose for our purposes here, so
+ # let's simplify it
+ system(%Q(sed -i '' "s/width: #{SIZE}px; height: #{SIZE}px; background: image-url('emoji.png')/background-position:/" #{style_path}))
+ system(%Q(sed -i '' "s/ no-repeat//" #{style_path}))
+ system(%Q(sed -i '' "s/ 0px/ 0/g" #{style_path}))
+
+ # Append a generic rule that applies to all Emojis
+ File.open(style_path, 'a') do |f|
+ f.puts
+ f.puts <<-CSS.strip_heredoc
+ .emoji-icon {
+ background-image: image-url('emoji.png');
+ background-repeat: no-repeat;
+ color: transparent;
+ text-indent: -99em;
+ height: #{SIZE}px;
+ width: #{SIZE}px;
+
+ /* stylelint-disable media-feature-name-no-vendor-prefix */
+ @media only screen and (-webkit-min-device-pixel-ratio: 2),
+ only screen and (min--moz-device-pixel-ratio: 2),
+ only screen and (-o-min-device-pixel-ratio: 2/1),
+ only screen and (min-device-pixel-ratio: 2),
+ only screen and (min-resolution: 192dpi),
+ only screen and (min-resolution: 2dppx) {
+ background-image: image-url('emoji@2x.png');
+ background-size: #{SPRITESHEET_WIDTH}px #{SPRITESHEET_HEIGHT}px;
+ }
+ /* stylelint-enable media-feature-name-no-vendor-prefix */
+ }
+ CSS
+ end
+ end
+ puts 'Done!'
+
+ puts "\n"
+
+ puts "Preparing sprites for HiDPI size: #{RETINA}px..."
+
+ # Now do it again but for Retina
+ Dir.mktmpdir do |tmpdir|
+ # Copy the TanukiEmoji assets to the temporary folder for resizing
+ FileUtils.cp_r(File.join(emoji_dir, '.'), tmpdir)
+
+ Dir.chdir(tmpdir) do
+ Dir["**/*.png"].each do |png|
+ tmp_image_path = File.join(tmpdir, png)
+ resize!(tmp_image_path, RETINA)
+ print '.'
+ end
+ end
+ puts ' Done!'
+
+ puts "\n"
+
+ print 'Compiling HiDPI sprites...'
+
+ # Combine the resized assets into a packed sprite and re-generate the SCSS
+ SpriteFactory.run!(tmpdir, {
+ output_image: "app/assets/images/emoji@2x.png",
+ style: false,
+ nocomments: true,
+ pngcrush: true,
+ layout: :packed
+ })
+ end
+
+ puts ' Done!'
+ end
+
+ def check_requirements!
+ unless defined?(Magick)
+ puts <<~MSG
+ This task is disabled by default and should only be run when the TanukiEmoji
+ gem is updated with new Emojis.
+
+ To enable this task, *temporarily* add the following lines to Gemfile and
+ re-bundle:
+
+ gem 'rmagick', '~> 3.2'
+
+ It depends on ImageMagick 6, which can be installed via HomeBrew with:
+
+ brew unlink imagemagick
+ brew install imagemagick@6 && brew link imagemagick@6 --force
+ MSG
+
+ exit 1
+ end
+
+ return if Dir.exist? Gitlab::Emoji.emoji_public_absolute_path
+
+ puts <<~MSG
+ You first need to import the assets for Emoji version: #{Gitlab::Emoji::EMOJI_VERSION}
+
+ Run the following task:
+
+ rake tanuki_emoji:import
+ MSG
+
+ exit 1
+ end
+
+ def resize!(image_path, size)
+ # Resize the image in-place, save it, and free the object
+ image = MiniMagick::Image.open(image_path)
+ image.quality(100)
+ image.resize("#{size}x#{size}")
+ image.write(image_path)
+ end
+end