Skip to content

Commit

Permalink
Run with --jobs=2 automatically on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Oct 4, 2023
1 parent 88a9f2f commit 284cb22
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/steep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sig/steep/cli.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 284cb22

Please sign in to comment.