Module: Kettle::Jem::Tasks::TemplateTask

Defined in:
lib/kettle/jem/tasks/template_task.rb

Class Method Summary collapse

Class Method Details

.default_thread_worker_countObject



80
81
82
# File 'lib/kettle/jem/tasks/template_task.rb', line 80

def default_thread_worker_count
  [1, Etc.nprocessors / 2].max
end

.env_run_options(env) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kettle/jem/tasks/template_task.rb', line 52

def env_run_options(env)
  {
    accept: truthy?(env["accept"]) || truthy?(env["force"]),
    force: truthy?(env["force"]),
    interactive: falsey?(env["force"]),
    failure_mode: env["FAILURE_MODE"] || env["failure_mode"],
    allowed: env["allowed"],
    hook_templates: env["hook_templates"],
    git_drivers: env["git_drivers"] || env["KETTLE_JEM_GIT_DRIVERS"],
    only: env["only"],
    include: env["include"],
    template_profile: env["KETTLE_JEM_TEMPLATE_PROFILE"],
    dry_run: truthy?(env["KETTLE_JEM_DRY_RUN"]),
    skip_commit: truthy?(env["KETTLE_JEM_SKIP_COMMIT"]),
    skip_drift_check: truthy?(env["KETTLE_JEM_SKIP_DRIFT_CHECK"]),
    skip_rubocop_gradual: truthy?(env["KETTLE_JEM_SKIP_RUBOCOP_GRADUAL"]),
    skip_binstubs: truthy?(env["KETTLE_JEM_SKIP_BINSTUBS"]),
    skip_appraisal_generate: truthy?(env["KETTLE_JEM_SKIP_APPRAISAL_GENERATE"]),
    skip_lock_normalization: truthy?(env["KETTLE_JEM_SKIP_LOCK_NORMALIZATION"]),
    skip_changelog: truthy?(env["KETTLE_JEM_SKIP_CHANGELOG"]),
    checksums: env["KETTLE_JEM_CHECKSUMS"],
    accept_config: truthy?(env["KETTLE_JEM_ACCEPT_CONFIG"]),
    bootstrap_mode: truthy?(env["KETTLE_JEM_BOOTSTRAP_MODE"]),
    quiet: truthy?(env["KETTLE_JEM_QUIET"]),
    verbose: truthy?(env["KETTLE_JEM_VERBOSE"])
  }.compact
end

.falsey?(value) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/kettle/jem/tasks/template_task.rb', line 113

def falsey?(value)
  Kettle::Jem::DecisionPolicy.falsey?(value)
end

.monorepo_root_profile?(project_root, env, run_options) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
# File 'lib/kettle/jem/tasks/template_task.rb', line 117

def monorepo_root_profile?(project_root, env, run_options)
  profile = (run_options || {})[:template_profile] || (run_options || {})["template_profile"] || (env || {})["KETTLE_JEM_TEMPLATE_PROFILE"]
  profile = Kettle::Jem.kettle_jem_config(project_root).dig("templates", "profile") if profile.to_s.empty?
  Kettle::Jem.normalize_template_profile(profile) == Kettle::Jem::MONOREPO_ROOT_TEMPLATE_PROFILE
end

.run(project_root: Dir.pwd, env: ENV, run_options: nil, command_runner: Kettle::Jem::Tasks::InstallTask.method(:run_system_command)) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kettle/jem/tasks/template_task.rb', line 11

def run(project_root: Dir.pwd, env: ENV, run_options: nil, command_runner: Kettle::Jem::Tasks::InstallTask.method(:run_system_command))
  effective_run_options = templating_run_options(env, run_options)
  report = if Dir.glob(File.join(project_root.to_s, "*.gemspec")).empty? && !monorepo_root_profile?(project_root, env, effective_run_options)
    {
      mode: "apply",
      changed_files: [],
      diagnostics: [],
      recipe_reports: []
    }
  else
    Kettle::Jem.apply_project(project_root, env: env, run_options: effective_run_options)
  end
  setup_env = Kettle::Jem::Tasks::InstallTask.setup_command_env(project_root, env)
  hook_step = Kettle::Jem::Tasks::InstallTask.hook_templates_step(project_root, effective_run_options)
  git_drivers_step = Kettle::Jem::Tasks::InstallTask.git_drivers_step(project_root, effective_run_options)
  lock_step = Kettle::Jem::Tasks::InstallTask.normalize_lockfile_step(project_root, env: setup_env, run_options: effective_run_options)
  template_steps = Kettle::Jem::Tasks::InstallTask.execute_orchestration_steps(
    [hook_step, git_drivers_step, lock_step],
    project_root: project_root,
    env: setup_env,
    run_options: effective_run_options,
    command_runner: command_runner,
    event_phase: "template"
  )
  final_report = report.merge(mode: "template", template_steps: template_steps)
  Kettle::Jem.emit_summary_event(Kettle::Jem.event_stream_from_options(effective_run_options), final_report)
  final_report
end

.templating_run_options(env, run_options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kettle/jem/tasks/template_task.rb', line 40

def templating_run_options(env, run_options)
  options = env_run_options(env || {}).merge(run_options || {})
  return options if worker_or_strategy_option_provided?(env || {}, options)

  workers = default_thread_worker_count
  options.merge(
    recipe_planning_strategy: "classified",
    recipe_planning_thread_workers: workers,
    file_work_thread_workers: workers
  )
end

.truthy?(value) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/kettle/jem/tasks/template_task.rb', line 109

def truthy?(value)
  Kettle::Jem::DecisionPolicy.truthy?(value)
end

.worker_or_strategy_option_provided?(env, run_options) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/kettle/jem/tasks/template_task.rb', line 84

def worker_or_strategy_option_provided?(env, run_options)
  option_keys = %i[
    ractor_workers
    recipe_planning_workers
    thread_workers
    recipe_planning_thread_workers
    ractor_file_workers
    file_work_workers
    thread_file_workers
    file_work_thread_workers
    recipe_planning_strategy
  ]
  string_option_keys = option_keys.map(&:to_s)
  env_keys = %w[
    KETTLE_JEM_RACTOR_WORKERS
    KETTLE_JEM_THREAD_WORKERS
    KETTLE_JEM_RACTOR_FILE_WORKERS
    KETTLE_JEM_THREAD_FILE_WORKERS
    KETTLE_JEM_RECIPE_PLANNING_STRATEGY
  ]
  option_keys.any? { |key| run_options.key?(key) } ||
    string_option_keys.any? { |key| run_options.key?(key) } ||
    env_keys.any? { |key| env.key?(key) && !env[key].to_s.strip.empty? }
end