diff --git a/lib/buildkite/config/rake_command.rb b/lib/buildkite/config/rake_command.rb index c21cc69a..617d2217 100644 --- a/lib/buildkite/config/rake_command.rb +++ b/lib/buildkite/config/rake_command.rb @@ -39,9 +39,8 @@ def prepare end dsl do - def rake(dir, options = {}) + def rake(dir, task: "test", label: nil, service: "default", pre_steps: nil, env: nil, retry_on: nil, soft_fail: nil, parallelism: nil) build_context = context.extensions.find(BuildContext) - task = options[:task] || "test" if task.start_with?("mysql2:") || (build_context.rails_version >= Gem::Version.new("7.1.0.alpha") && task.start_with?("trilogy:")) task = "db:mysql:rebuild #{task}" @@ -50,7 +49,7 @@ def rake(dir, options = {}) end command do - label to_label(build_context.ruby, dir, task, options[:label]) + label to_label(build_context.ruby, dir, task, label) depends_on "docker-image-#{build_context.ruby.image_key}" command "rake #{task}" @@ -71,32 +70,32 @@ def rake(dir, options = {}) plugin :docker_compose, { "env" => %w[PRE_STEPS RACK], - "run" => options[:service] || "default", - "pull" => options[:service] || "default", + "run" => service, + "pull" => service, "config" => ".buildkite/docker-compose.yml", "shell" => ["runner", dir], } - env build_env(build_context, options[:pre_steps], options[:env]) + env build_env(build_context, pre_steps, env) - agents options[:agents] || { queue: build_context.run_queue } + agents queue: build_context.run_queue - artifact_paths options[:artifact_paths] || build_context.artifact_paths + artifact_paths build_context.artifact_paths - if options[:retry_on] - automatic_retry_on(**options[:retry_on]) + if retry_on + automatic_retry_on(**retry_on) else automatic_retry_on(**build_context.automatic_retry_on) end - timeout_in_minutes options[:timeout_in_minutes] || build_context.timeout_in_minutes + timeout_in_minutes build_context.timeout_in_minutes - if options[:soft_fail] || build_context.ruby.soft_fail? + if soft_fail || build_context.ruby.soft_fail? soft_fail true end - if options[:parallelism] - parallelism options[:parallelism] + if parallelism + parallelism parallelism end end end diff --git a/test/buildkite_config/test_rake_command.rb b/test/buildkite_config/test_rake_command.rb index 686ed201..c465cde6 100644 --- a/test/buildkite_config/test_rake_command.rb +++ b/test/buildkite_config/test_rake_command.rb @@ -307,84 +307,6 @@ def test_env_pre_steps assert_equal expected, pipeline.to_h end - def test_agents - pipeline = PipelineFixture.new do - build_context.ruby = Buildkite::Config::RubyConfig.new(version: Gem::Version.new("3.2")) - use Buildkite::Config::RakeCommand - - build_context.stub(:rails_version, Gem::Version.new("7.1")) do - rake "test_agents", agents: { queue: "test_agents" } - end - end - - expected = { "steps" => - [{ "label" => "test_agents (3.2)", - "command" => ["rake test"], - "depends_on" => ["docker-image-3-2"], - "artifact_paths" => ["test-reports/*/*.xml"], - "agents" => { "queue" => "test_agents" }, - "retry" => { "automatic" => [{ "limit" => 2, "exit_status" => -1 }] }, - "env" => { "IMAGE_NAME" => "buildkite-config-base:3-2-local" }, - "timeout_in_minutes" => 30, - "plugins" => - [{ "artifacts#v1.0" => { "download" => ".dockerignore" } }, - { "artifacts#v1.0" => - { "download" => - [".buildkite/.empty", - ".buildkite/docker-compose.yml", - ".buildkite/Dockerfile", - ".buildkite/Dockerfile.beanstalkd", - ".buildkite/mysql-initdb.d", - ".buildkite/runner"], - "compressed" => ".buildkite.tgz" } }, - { "docker-compose#v1.0" => - { "env" => ["PRE_STEPS", "RACK"], - "run" => "default", - "pull" => "default", - "config" => ".buildkite/docker-compose.yml", - "shell" => ["runner", "test_agents"] } }] }] } - assert_equal expected, pipeline.to_h - end - - def test_artifact_paths - pipeline = PipelineFixture.new do - build_context.ruby = Buildkite::Config::RubyConfig.new(version: Gem::Version.new("3.2")) - use Buildkite::Config::RakeCommand - - build_context.stub(:rails_version, Gem::Version.new("7.1")) do - rake "test_artifact_paths", artifact_paths: ["test_artifact_paths"] - end - end - - expected = { "steps" => - [{ "label" => "test_artifact_paths (3.2)", - "command" => ["rake test"], - "depends_on" => ["docker-image-3-2"], - "artifact_paths" => ["test_artifact_paths"], - "agents" => { "queue" => "default" }, - "retry" => { "automatic" => [{ "limit" => 2, "exit_status" => -1 }] }, - "env" => { "IMAGE_NAME" => "buildkite-config-base:3-2-local" }, - "timeout_in_minutes" => 30, - "plugins" => - [{ "artifacts#v1.0" => { "download" => ".dockerignore" } }, - { "artifacts#v1.0" => - { "download" => - [".buildkite/.empty", - ".buildkite/docker-compose.yml", - ".buildkite/Dockerfile", - ".buildkite/Dockerfile.beanstalkd", - ".buildkite/mysql-initdb.d", - ".buildkite/runner"], - "compressed" => ".buildkite.tgz" } }, - { "docker-compose#v1.0" => - { "env" => ["PRE_STEPS", "RACK"], - "run" => "default", - "pull" => "default", - "config" => ".buildkite/docker-compose.yml", - "shell" => ["runner", "test_artifact_paths"] } }] }] } - assert_equal expected, pipeline.to_h - end - def test_automatic_retry_on pipeline = PipelineFixture.new do build_context.ruby = Buildkite::Config::RubyConfig.new(version: Gem::Version.new("3.2")) @@ -424,45 +346,6 @@ def test_automatic_retry_on assert_equal expected, pipeline.to_h end - def test_timeout_in_minutes - pipeline = PipelineFixture.new do - build_context.ruby = Buildkite::Config::RubyConfig.new(version: Gem::Version.new("3.2")) - use Buildkite::Config::RakeCommand - - build_context.stub(:rails_version, Gem::Version.new("7.1")) do - rake "test_timeout_in_minutes", timeout_in_minutes: 10 - end - end - - expected = { "steps" => - [{ "label" => "test_timeout_in_minutes (3.2)", - "command" => ["rake test"], - "depends_on" => ["docker-image-3-2"], - "artifact_paths" => ["test-reports/*/*.xml"], - "agents" => { "queue" => "default" }, - "retry" => { "automatic" => [{ "limit" => 2, "exit_status" => -1 }] }, - "env" => { "IMAGE_NAME" => "buildkite-config-base:3-2-local" }, - "timeout_in_minutes" => 10, - "plugins" => - [{ "artifacts#v1.0" => { "download" => ".dockerignore" } }, - { "artifacts#v1.0" => - { "download" => - [".buildkite/.empty", - ".buildkite/docker-compose.yml", - ".buildkite/Dockerfile", - ".buildkite/Dockerfile.beanstalkd", - ".buildkite/mysql-initdb.d", - ".buildkite/runner"], - "compressed" => ".buildkite.tgz" } }, - { "docker-compose#v1.0" => - { "env" => ["PRE_STEPS", "RACK"], - "run" => "default", - "pull" => "default", - "config" => ".buildkite/docker-compose.yml", - "shell" => ["runner", "test_timeout_in_minutes"] } }] }] } - assert_equal expected, pipeline.to_h - end - def test_soft_fail pipeline = PipelineFixture.new do build_context.ruby = Buildkite::Config::RubyConfig.new(version: Gem::Version.new("3.2"))