class ConfigureSemaphore
Attributes
environment[RW]
project_name[RW]
Public Class Methods
new()
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 9 def initialize @project_name = File.basename(Dir.getwd) end
Public Instance Methods
call()
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/renuo/cli/app/configure_semaphore.rb, line 14 def call return unless semaphore_cli_installed? FileUtils.mkdir_p(%w[.semaphore .semaphore/bin]) write_or_warn(".semaphore/semaphore.yml", render("templates/semaphore/semaphore.yml.erb")) %w[main develop].each do |environment| @environment = environment write_or_warn(".semaphore/#{environment}-deploy.yml", render("templates/semaphore/semaphore-deploy.yml.erb")) end write_or_warn(".semaphore/bin/cache_restore", render("templates/semaphore/bin/cache_restore.erb")) write_or_warn(".semaphore/bin/cache_store", render("templates/semaphore/bin/cache_store.erb")) create_semaphore_notification create_semaphore_secrets create_semaphore_deployment_targets end
Private Instance Methods
create_semaphore_deployment_targets()
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 53 def create_semaphore_deployment_targets system("sem create dt main -p #{project_name}") system("sem create dt develop -p #{project_name}") end
create_semaphore_notification()
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 41 def create_semaphore_notification system("sem create notifications #{project_name} " \ "--projects #{project_name} " \ '--branches "main,develop" ' \ "--slack-channels \"#project-#{project_name}\" " \ '--slack-endpoint "https://hooks.slack.com/services/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"') end
create_semaphore_secrets()
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 49 def create_semaphore_secrets system("sem create secret -p #{project_name} #{project_name}") end
render(template_file)
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 58 def render(template_file) file_path = File.join(File.dirname(__FILE__), template_file) semaphore_template = File.read(file_path) renderer = ERB.new(semaphore_template) renderer.result(binding) end
semaphore_cli_installed?()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/renuo/cli/app/configure_semaphore.rb, line 35 def semaphore_cli_installed? semaphore_cli_installed = `sem context | grep '*'`.strip == "* renuo_semaphoreci_com" warn("You need to install and configure Semaphore CLI to run this command.") unless semaphore_cli_installed semaphore_cli_installed end
write_or_warn(file_path, content)
click to toggle source
# File lib/renuo/cli/app/configure_semaphore.rb, line 65 def write_or_warn(file_path, content) if File.exist?(file_path) warn("#{file_path} exists already. I will not overwrite it.") else File.write(file_path, content) say("#{file_path} added.") end end