From ea43f50f6dfe8c01f3cc73a25a23ecbfaa653b84 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 18 Aug 2017 22:03:09 +0100 Subject: [PATCH 1/5] Add documentation for new ENV variables --- lib/tasks/docker.rake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index accc4f350af..7694a25071a 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -14,6 +14,8 @@ # 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 # 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: # Run all core and plugin tests: From 7704e8246b941ae9ab4091c30b2e8aedbbcd4038 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 18 Aug 2017 22:04:35 +0100 Subject: [PATCH 2/5] Allow SINGLE_PLUGIN environment variable to be used --- lib/tasks/docker.rake | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index 7694a25071a..f26d68372a5 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -35,11 +35,18 @@ end desc 'Run JS and Ruby linters' task 'docker:lint' do - success = run_or_fail("bundle exec rubocop --parallel") - success = run_or_fail("eslint app/assets/javascripts test/javascripts") - success = run_or_fail("eslint --ext .es6 app/assets/javascripts test/javascripts plugins") + success = true - exit 1 if !success + 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 unless success end desc 'Run all tests (JS and code in a standalone environment)' From a3f5878ec942592b4f76fbe048bb61f9458af4f0 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 18 Aug 2017 22:12:20 +0100 Subject: [PATCH 3/5] Use `if`, not `unless` --- lib/tasks/docker.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index f26d68372a5..b60e90d1f0b 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -46,7 +46,7 @@ task 'docker:lint' do success &&= run_or_fail("eslint --ext .es6 app/assets/javascripts test/javascripts plugins") unless ENV["SKIP_PLUGINS"] end - exit 1 unless success + exit 1 if !success end desc 'Run all tests (JS and code in a standalone environment)' From 6e7488178fe3589ffa59d58c90b8079712fdf23a Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sat, 19 Aug 2017 11:10:17 +0100 Subject: [PATCH 4/5] Add documentation to docker_test.rb --- script/docker_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/script/docker_test.rb b/script/docker_test.rb index 2d5710bb0ea..ca31564cbf8 100644 --- a/script/docker_test.rb +++ b/script/docker_test.rb @@ -1,3 +1,12 @@ +# This script is run in the discourse_test docker image +# Available environment variables: +# => 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" +# => 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 +# +# See lib/tasks/docker.rake for other available environment variables + def run_or_fail(command) pid = Process.spawn(command) Process.wait(pid) From ed6e1c3825a4865588b599b32aed337c3927fd33 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 22 Aug 2017 13:47:29 +0100 Subject: [PATCH 5/5] Combine docker:lint and docker:test into one command --- lib/tasks/docker.rake | 148 +++++++++++++++++++++--------------------- script/docker_test.rb | 8 +-- 2 files changed, 75 insertions(+), 81 deletions(-) diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index b60e90d1f0b..e506eed2735 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -2,6 +2,8 @@ # running it anywhere else will likely fail # # 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_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 @@ -14,8 +16,6 @@ # 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 # 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: # Run all core and plugin tests: @@ -33,97 +33,95 @@ def run_or_fail(command) $?.exitstatus == 0 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)' task 'docker:test' do begin - - 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` - - puts "Starting background redis" - @redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis') - - @postgres_bin = "/usr/lib/postgresql/9.5/bin/" - `#{@postgres_bin}initdb -D tmp/test_data/pg` - - # speed up db, never do this in production mmmmk - `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") + @good = true + unless ENV['SKIP_LINT'] + puts "Running linters" + if ENV["SINGLE_PLUGIN"] + @good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}") + @good &&= run_or_fail("eslint --ext .es6 plugins/#{ENV['SINGLE_PLUGIN']}") + else + @good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"] + @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"] + 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"] - params = [] - 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) + puts "Starting background redis" + @redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis') + + @postgres_bin = "/usr/lib/postgresql/9.5/bin/" + `#{@postgres_bin}initdb -D tmp/test_data/pg` + + # speed up db, never do this in production mmmmk + `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 - unless ENV["SKIP_PLUGINS"] - if ENV["SINGLE_PLUGIN"] - @good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']") - else - @good &&= run_or_fail("bundle exec rake plugin:spec") + unless ENV["JS_ONLY"] + + unless ENV["SKIP_CORE"] + params = [] + 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 - - 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']") + unless ENV["SKIP_PLUGINS"] + if ENV["SINGLE_PLUGIN"] + @good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']") + else + @good &&= run_or_fail("bundle exec rake plugin:spec") + 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 ensure puts "Terminating" - Process.kill("TERM", @redis_pid) - Process.kill("TERM", @pg_pid) - Process.wait @redis_pid - Process.wait @pg_pid + Process.kill("TERM", @redis_pid) if @redis_pid + Process.kill("TERM", @pg_pid) if @pg_pid + Process.wait @redis_pid if @redis_pid + Process.wait @pg_pid if @pg_pid end if !@good diff --git a/script/docker_test.rb b/script/docker_test.rb index ca31564cbf8..a4b9a6aabe7 100644 --- a/script/docker_test.rb +++ b/script/docker_test.rb @@ -2,10 +2,7 @@ # Available environment variables: # => 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" -# => 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 -# -# See lib/tasks/docker.rake for other available environment variables +# See lib/tasks/docker.rake for more information def run_or_fail(command) pid = Process.spawn(command) @@ -21,5 +18,4 @@ unless ENV['NO_UPDATE'] run_or_fail("bundle") end -run_or_fail("bundle exec rake docker:lint") if !ENV["SKIP_LINT"] -run_or_fail("bundle exec rake docker:test") if !ENV["LINT_ONLY"] +run_or_fail("bundle exec rake docker:test")