DEV: Add annotate rake tasks, and enforce via GitHub actions

`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.
This commit is contained in:
David Taylor
2021-07-06 09:47:16 +01:00
parent b3d3ad250b
commit 8c370c3fe3
4 changed files with 84 additions and 2 deletions

View File

@ -99,6 +99,28 @@ class TemporaryDb
`#{pg_ctl_path} -D '#{PG_TEMP_PATH}' stop`
end
def with_env(&block)
old_host = ENV["PGHOST"]
old_user = ENV["PGUSER"]
old_port = ENV["PGPORT"]
old_dev_db = ENV["DISCOURSE_DEV_DB"]
old_rails_db = ENV["RAILS_DB"]
ENV["PGHOST"] = "localhost"
ENV["PGUSER"] = "discourse"
ENV["PGPORT"] = pg_port.to_s
ENV["DISCOURSE_DEV_DB"] = "discourse"
ENV["RAILS_DB"] = "discourse"
yield
ensure
ENV["PGHOST"] = old_host
ENV["PGUSER"] = old_user
ENV["PGPORT"] = old_port
ENV["DISCOURSE_DEV_DB"] = old_dev_db
ENV["RAILS_DB"] = old_rails_db
end
def remove
raise "Error: the database must be stopped before it can be removed" if @started
FileUtils.rm_rf PG_TEMP_PATH