mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 12:23:42 +08:00
8c370c3fe3
`bin/rake annotate` is an alias of `bin/annotate --models` `bin/rake annotate:clean` generates annotations by using a temporary, freshly migrated database. This should help us to produce more consistent annotations, even if development databases have been polluted by plugin migrations. A GitHub actions task is also added which generates annotations on a clean database, and raises an error if they differ from the committed annotations.
40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
desc "ensure the asynchronously-created post_search_data index is present"
|
|
task "annotate" => :environment do |task, args|
|
|
raise if !system "bin/annotate --models"
|
|
STDERR.puts "Annotate executed successfully"
|
|
|
|
non_core_plugins = Dir["plugins/*"].filter do |plugin_path|
|
|
`git check-ignore #{plugin_path}`.present?
|
|
end
|
|
if non_core_plugins.length > 0
|
|
STDERR.puts "Warning: you have non-core plugins installed which may affect the annotations"
|
|
STDERR.puts "For core annotations, consider running `bin/rake annotate:clean`"
|
|
end
|
|
end
|
|
|
|
desc "ensure the asynchronously-created post_search_data index is present"
|
|
task "annotate:ensure_all_indexes" => :environment do |task, args|
|
|
# One of the indexes on post_search_data is created by a sidekiq job
|
|
# We need to do some acrobatics to create it on-demand
|
|
SeedData::Topics.with_default_locale.create(include_welcome_topics: true)
|
|
SiteSetting.search_enable_recent_regular_posts_offset_size = 1
|
|
Jobs::CreateRecentPostSearchIndexes.new.execute([])
|
|
end
|
|
|
|
desc "regenerate core model annotations using a temporary database"
|
|
task "annotate:clean" => :environment do |task, args|
|
|
db = TemporaryDb.new
|
|
db.start
|
|
db.with_env do
|
|
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake db:migrate"
|
|
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake annotate:ensure_all_indexes"
|
|
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/annotate --models --model-dir app/models"
|
|
end
|
|
STDERR.puts "Annotate executed successfully"
|
|
ensure
|
|
db&.stop
|
|
db&.remove
|
|
end
|