From 284cb22fe8ef60ab8d5b1554d2e991e3cb7ee25b Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Wed, 4 Oct 2023 20:36:32 +0900 Subject: [PATCH] Run with `--jobs=2` automatically on CI --- lib/steep/cli.rb | 22 ++++++++++++++++++++++ sig/steep/cli.rbs | 2 ++ test/cli_test.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/lib/steep/cli.rb b/lib/steep/cli.rb index c0f0248b7..7cce1a737 100644 --- a/lib/steep/cli.rb +++ b/lib/steep/cli.rb @@ -84,6 +84,20 @@ def handle_jobs_option(option, opts) end end + def setup_jobs_for_ci(jobs_option) + if ENV["CI"] + unless jobs_option.jobs_count + if jobs_option.default_jobs_count > 2 + stderr.puts Rainbow("CI environment is detected but no `--jobs` option is given.").yellow + stderr.puts " Using `2` instead of `#{jobs_option.default_jobs_count}` (based on # of processors) to avoid hitting memory limit." + stderr.puts " Specify `--jobs` option to increase the number of jobs." + + jobs_option.jobs_count = 2 + end + end + end + end + def process_init Drivers::Init.new(stdout: stdout, stderr: stderr).tap do |command| OptionParser.new do |opts| @@ -116,6 +130,8 @@ def process_check handle_logging_options opts end.parse!(argv) + setup_jobs_for_ci(check.jobs_option) + check.command_line_patterns.push *argv end.run end @@ -139,6 +155,8 @@ def process_checkfile handle_logging_options opts end.parse!(argv) + setup_jobs_for_ci(check.jobs_option) + check.command_line_args.push *argv end.run end @@ -154,6 +172,8 @@ def process_stats handle_logging_options opts end.parse!(argv) + setup_jobs_for_ci(check.jobs_option) + check.command_line_patterns.push *argv end.run end @@ -199,6 +219,8 @@ def process_watch handle_logging_options opts end.parse!(argv) + setup_jobs_for_ci(command.jobs_option) + dirs = argv.map {|dir| Pathname(dir) } command.dirs.push(*dirs) end.run diff --git a/sig/steep/cli.rbs b/sig/steep/cli.rbs index 3833e704b..5c5598be8 100644 --- a/sig/steep/cli.rbs +++ b/sig/steep/cli.rbs @@ -24,6 +24,8 @@ module Steep def handle_jobs_option: (Drivers::Utils::JobsOption jobs_option, OptionParser opts) -> void + def setup_jobs_for_ci: (Drivers::Utils::JobsOption) -> void + def process_init: () -> Integer def process_check: () -> Integer diff --git a/test/cli_test.rb b/test/cli_test.rb index 1fe12ad8e..9cc053e88 100644 --- a/test/cli_test.rb +++ b/test/cli_test.rb @@ -641,4 +641,34 @@ def test_binstub_force end end end + + def test_ci_jobs_setup_message + in_tmpdir do + (current_dir + "Steepfile").write(<<~RUBY) + target :app do + check "foo.rb" + end + RUBY + + (current_dir + "foo.rb").write(<<~RUBY) + 1 + 2 + RUBY + + push_env({ "CI" => "true" }) do + ["check", "checkfile", "stats"].each do |command| + _, stderr, status = sh3(*steep, command, "foo.rb") + + assert_predicate status, :success? + assert_match /CI environment is detected but no `--jobs` option is given./, stderr + end + + ["check", "checkfile", "stats"].each do |command| + _, stderr, status = sh3(*steep, command, "--jobs=1", "foo.rb") + + assert_predicate status, :success? + refute_match /CI environment is detected but no `--jobs` option is given./, stderr + end + end + end + end end