mirror of
https://github.com/discourse/discourse.git
synced 2025-04-03 05:39:41 +08:00
Combine docker:lint and docker:test into one command
This commit is contained in:
parent
6e7488178f
commit
ed6e1c3825
@ -2,6 +2,8 @@
|
|||||||
# running it anywhere else will likely fail
|
# running it anywhere else will likely fail
|
||||||
#
|
#
|
||||||
# Environment Variables (specific to this rake task)
|
# Environment Variables (specific to this rake task)
|
||||||
|
# => SKIP_LINT set to 1 to skip linting (eslint and rubocop)
|
||||||
|
# => SKIP_TESTS set to 1 to skip all tests
|
||||||
# => SKIP_CORE set to 1 to skip core tests (rspec and qunit)
|
# => SKIP_CORE set to 1 to skip core tests (rspec and qunit)
|
||||||
# => SKIP_PLUGINS set to 1 to skip plugin tests (rspec and qunit)
|
# => SKIP_PLUGINS set to 1 to skip plugin tests (rspec and qunit)
|
||||||
# => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests
|
# => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests
|
||||||
@ -14,8 +16,6 @@
|
|||||||
# Other useful environment variables (not specific to this rake task)
|
# Other useful environment variables (not specific to this rake task)
|
||||||
# => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
|
# => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
|
||||||
# this can also be set to a branch, e.g. "origin/tests-passed"
|
# this can also be set to a branch, e.g. "origin/tests-passed"
|
||||||
# => SKIP_LINT if using the discourse_test docker image, this will skip the docker:test task, and only run the docker:lint task
|
|
||||||
# => LINT_ONLY if using the discourse_test docker image, this will skip the docker:lint task, and only run the docker:test task
|
|
||||||
#
|
#
|
||||||
# Example usage:
|
# Example usage:
|
||||||
# Run all core and plugin tests:
|
# Run all core and plugin tests:
|
||||||
@ -33,97 +33,95 @@ def run_or_fail(command)
|
|||||||
$?.exitstatus == 0
|
$?.exitstatus == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Run JS and Ruby linters'
|
|
||||||
task 'docker:lint' do
|
|
||||||
success = true
|
|
||||||
|
|
||||||
if ENV["SINGLE_PLUGIN"]
|
|
||||||
success &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
|
|
||||||
success &&= run_or_fail("eslint --ext .es6 plugins/#{ENV['SINGLE_PLUGIN']}")
|
|
||||||
else
|
|
||||||
success &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
|
|
||||||
success &&= run_or_fail("eslint app/assets/javascripts test/javascripts") unless ENV["SKIP_CORE"]
|
|
||||||
success &&= run_or_fail("eslint --ext .es6 app/assets/javascripts test/javascripts plugins") unless ENV["SKIP_PLUGINS"]
|
|
||||||
end
|
|
||||||
|
|
||||||
exit 1 if !success
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Run all tests (JS and code in a standalone environment)'
|
desc 'Run all tests (JS and code in a standalone environment)'
|
||||||
task 'docker:test' do
|
task 'docker:test' do
|
||||||
begin
|
begin
|
||||||
|
@good = true
|
||||||
puts "Cleaning up old test tmp data in tmp/test_data"
|
unless ENV['SKIP_LINT']
|
||||||
`rm -fr tmp/test_data && mkdir -p tmp/test_data/redis && mkdir tmp/test_data/pg`
|
puts "Running linters"
|
||||||
|
if ENV["SINGLE_PLUGIN"]
|
||||||
puts "Starting background redis"
|
@good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
|
||||||
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
|
@good &&= run_or_fail("eslint --ext .es6 plugins/#{ENV['SINGLE_PLUGIN']}")
|
||||||
|
else
|
||||||
@postgres_bin = "/usr/lib/postgresql/9.5/bin/"
|
@good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
|
||||||
`#{@postgres_bin}initdb -D tmp/test_data/pg`
|
@good &&= run_or_fail("eslint app/assets/javascripts test/javascripts") unless ENV["SKIP_CORE"]
|
||||||
|
@good &&= run_or_fail("eslint --ext .es6 app/assets/javascripts test/javascripts plugins") unless ENV["SKIP_PLUGINS"]
|
||||||
# speed up db, never do this in production mmmmk
|
end
|
||||||
`echo fsync = off >> tmp/test_data/pg/postgresql.conf`
|
|
||||||
`echo full_page_writes = off >> tmp/test_data/pg/postgresql.conf`
|
|
||||||
`echo shared_buffers = 500MB >> tmp/test_data/pg/postgresql.conf`
|
|
||||||
|
|
||||||
puts "Starting postgres"
|
|
||||||
@pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
|
|
||||||
|
|
||||||
ENV["RAILS_ENV"] = "test"
|
|
||||||
|
|
||||||
@good = run_or_fail("bundle exec rake db:create db:migrate")
|
|
||||||
|
|
||||||
if ENV["INSTALL_OFFICIAL_PLUGINS"]
|
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:install_all_official")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
unless ENV["JS_ONLY"]
|
unless ENV['SKIP_TESTS']
|
||||||
|
puts "Cleaning up old test tmp data in tmp/test_data"
|
||||||
|
`rm -fr tmp/test_data && mkdir -p tmp/test_data/redis && mkdir tmp/test_data/pg`
|
||||||
|
|
||||||
unless ENV["SKIP_CORE"]
|
puts "Starting background redis"
|
||||||
params = []
|
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
|
||||||
if ENV["BISECT"]
|
|
||||||
params << "--bisect"
|
@postgres_bin = "/usr/lib/postgresql/9.5/bin/"
|
||||||
end
|
`#{@postgres_bin}initdb -D tmp/test_data/pg`
|
||||||
if ENV["RSPEC_SEED"]
|
|
||||||
params << "--seed #{ENV["RSPEC_SEED"]}"
|
# speed up db, never do this in production mmmmk
|
||||||
end
|
`echo fsync = off >> tmp/test_data/pg/postgresql.conf`
|
||||||
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
`echo full_page_writes = off >> tmp/test_data/pg/postgresql.conf`
|
||||||
|
`echo shared_buffers = 500MB >> tmp/test_data/pg/postgresql.conf`
|
||||||
|
|
||||||
|
puts "Starting postgres"
|
||||||
|
@pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
|
||||||
|
|
||||||
|
ENV["RAILS_ENV"] = "test"
|
||||||
|
|
||||||
|
@good &&= run_or_fail("bundle exec rake db:create db:migrate")
|
||||||
|
|
||||||
|
if ENV["INSTALL_OFFICIAL_PLUGINS"]
|
||||||
|
@good &&= run_or_fail("bundle exec rake plugin:install_all_official")
|
||||||
end
|
end
|
||||||
|
|
||||||
unless ENV["SKIP_PLUGINS"]
|
unless ENV["JS_ONLY"]
|
||||||
if ENV["SINGLE_PLUGIN"]
|
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
unless ENV["SKIP_CORE"]
|
||||||
else
|
params = []
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:spec")
|
if ENV["BISECT"]
|
||||||
|
params << "--bisect"
|
||||||
|
end
|
||||||
|
if ENV["RSPEC_SEED"]
|
||||||
|
params << "--seed #{ENV["RSPEC_SEED"]}"
|
||||||
|
end
|
||||||
|
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
unless ENV["SKIP_PLUGINS"]
|
||||||
|
if ENV["SINGLE_PLUGIN"]
|
||||||
unless ENV["RUBY_ONLY"]
|
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
||||||
unless ENV["SKIP_CORE"]
|
else
|
||||||
@good &&= run_or_fail("bundle exec rake qunit:test['600000']")
|
@good &&= run_or_fail("bundle exec rake plugin:spec")
|
||||||
@good &&= run_or_fail("bundle exec rake qunit:test['600000','/wizard/qunit']")
|
end
|
||||||
end
|
|
||||||
|
|
||||||
unless ENV["SKIP_PLUGINS"]
|
|
||||||
if ENV["SINGLE_PLUGIN"]
|
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','600000']")
|
|
||||||
else
|
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:qunit['*','600000']")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless ENV["RUBY_ONLY"]
|
||||||
|
unless ENV["SKIP_CORE"]
|
||||||
|
@good &&= run_or_fail("bundle exec rake qunit:test['600000']")
|
||||||
|
@good &&= run_or_fail("bundle exec rake qunit:test['600000','/wizard/qunit']")
|
||||||
|
end
|
||||||
|
|
||||||
|
unless ENV["SKIP_PLUGINS"]
|
||||||
|
if ENV["SINGLE_PLUGIN"]
|
||||||
|
@good &&= run_or_fail("bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','600000']")
|
||||||
|
else
|
||||||
|
@good &&= run_or_fail("bundle exec rake plugin:qunit['*','600000']")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
puts "Terminating"
|
puts "Terminating"
|
||||||
|
|
||||||
Process.kill("TERM", @redis_pid)
|
Process.kill("TERM", @redis_pid) if @redis_pid
|
||||||
Process.kill("TERM", @pg_pid)
|
Process.kill("TERM", @pg_pid) if @pg_pid
|
||||||
Process.wait @redis_pid
|
Process.wait @redis_pid if @redis_pid
|
||||||
Process.wait @pg_pid
|
Process.wait @pg_pid if @pg_pid
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@good
|
if !@good
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
# Available environment variables:
|
# Available environment variables:
|
||||||
# => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
|
# => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
|
||||||
# this can also be set to a branch, e.g. "origin/tests-passed"
|
# this can also be set to a branch, e.g. "origin/tests-passed"
|
||||||
# => SKIP_LINT if using the discourse_test docker image, this will skip the docker:test task, and only run the docker:lint task
|
# See lib/tasks/docker.rake for more information
|
||||||
# => LINT_ONLY if using the discourse_test docker image, this will skip the docker:lint task, and only run the docker:test task
|
|
||||||
#
|
|
||||||
# See lib/tasks/docker.rake for other available environment variables
|
|
||||||
|
|
||||||
def run_or_fail(command)
|
def run_or_fail(command)
|
||||||
pid = Process.spawn(command)
|
pid = Process.spawn(command)
|
||||||
@ -21,5 +18,4 @@ unless ENV['NO_UPDATE']
|
|||||||
run_or_fail("bundle")
|
run_or_fail("bundle")
|
||||||
end
|
end
|
||||||
|
|
||||||
run_or_fail("bundle exec rake docker:lint") if !ENV["SKIP_LINT"]
|
run_or_fail("bundle exec rake docker:test")
|
||||||
run_or_fail("bundle exec rake docker:test") if !ENV["LINT_ONLY"]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user