class ActiveSupport::ContinuousIntegration
Предоставляет DSL для объявления рабочего процесса непрерывной интеграции, который можно запускать локально или в облаке. Для каждого шага измеряется время выполнения и сообщается об успехе или ошибке; результаты объединяются в общий отчет, в котором указывается общее время выполнения и статус всего запуска.
Пример:
ActiveSupport::ContinuousIntegration.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Gem audit", "bin/bundler-audit"
step "Tests: Rails", "bin/rails test test:system"
if success?
step "Signoff: Ready for merge and deploy", "gh signoff"
else
failure "Skipping signoff; CI failed.", "Fix the issues and try again."
end
end
Начиная с Rails 8.1 для готовой к использованию CI создаются файлы `bin/ci` и `config/ci.rb`.
Константы
- COLORS
Атрибуты
Методы класса
# File activesupport/lib/active_support/continuous_integration.rb, line 64 def initialize @results = [] end
# File activesupport/lib/active_support/continuous_integration.rb, line 55
def self.run(title = "Continuous Integration", subtitle = "Running tests, style checks, and security audits", &block)
new.tap do |ci|
ENV["CI"] = "true"
ci.heading title, subtitle, padding: false
ci.report(title, &block)
abort unless ci.success?
end
end Выполняет запуск CI. Запускает каждый шаг, показывает результаты и время выполнения и завершает работу с ненулевым кодом возврата, если есть ошибки.
Можно передать заголовок, подзаголовок и блок, объявляющий шаги для выполнения.
Устанавливает переменную среды CI в значение «true», чтобы включить условное поведение приложения, например предварительную загрузку и отключение журналирования.
Пример:
ActiveSupport::ContinuousIntegration.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Gem audit", "bin/bundler-audit"
step "Tests: Rails", "bin/rails test test:system"
if success?
step "Signoff: Ready for merge and deploy", "gh signoff"
else
failure "Skipping signoff; CI failed.", "Fix the issues and try again."
end
end
Методы экземпляра
# File activesupport/lib/active_support/continuous_integration.rb, line 111 def echo(text, type:) puts colorize(text, type) end
Выводит текст в терминал цветом, соответствующим его типу.
Примеры:
echo "This is going to be green!", type: :success echo "This is going to be red!", type: :error
Полный список вариантов см. в разделе ActiveSupport::ContinuousIntegration::COLORS.
# File activesupport/lib/active_support/continuous_integration.rb, line 86 def failure(title, subtitle = nil) heading title, subtitle, type: :error end
Выводит заголовок ошибки с названием и необязательным подзаголовком, сообщая о неудачном запуске.
# File activesupport/lib/active_support/continuous_integration.rb, line 98
def heading(heading, subtitle = nil, type: :banner, padding: true)
echo "#{padding ? "\n\n" : ""}#{heading}", type: type
echo "#{subtitle}#{padding ? "\n" : ""}", type: :subtitle if subtitle
end Выводит цветной заголовок и необязательный подзаголовок.
Примеры:
heading "Smoke Testing", "End-to-end tests verifying key functionality", padding: false heading "Skipping video encoding tests", "Install FFmpeg to run these tests", type: :error
Полный список вариантов см. в разделе ActiveSupport::ContinuousIntegration::COLORS.
# File activesupport/lib/active_support/continuous_integration.rb, line 75
def step(title, *command)
heading title, command.join(" "), type: :title
report(title) { results << system(*command) }
end Объявляет шаг с заголовком и командой. Команду можно передать одной строкой или несколькими строками, которые будут переданы в `system` как отдельные аргументы (что обеспечивает корректное экранирование путей и т. п.).
Примеры:
step "Setup", "bin/setup" step "Single test", "bin/rails", "test", "--name", "test_that_is_one"
# File activesupport/lib/active_support/continuous_integration.rb, line 81 def success? results.all? end
Возвращает true, если все шаги выполнены успешно.
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.