Module: Ocak::Verification

Included in:
Commands::Hiz, PipelineExecutor
Defined in:
lib/ocak/verification.rb

Overview

Final verification checks (tests + lint) extracted from PipelineRunner.

Instance Method Summary collapse

Instance Method Details

#lint_extensions_for(language) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ocak/verification.rb', line 47

def lint_extensions_for(language)
  case language
  when 'ruby'                    then %w[.rb .rake .gemspec]
  when 'typescript'              then %w[.ts .tsx]
  when 'javascript'              then %w[.js .jsx]
  when 'python'                  then %w[.py]
  when 'rust'                    then %w[.rs]
  when 'go'                      then %w[.go]
  when 'elixir'                  then %w[.ex .exs]
  when 'java'                    then %w[.java]
  else                                %w[.rb .ts .tsx .js .jsx .py .rs .go]
  end
end

#run_final_checks(logger, chdir:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ocak/verification.rb', line 9

def run_final_checks(logger, chdir:)
  failures = []
  output_parts = []

  check_tests(failures, output_parts, chdir: chdir)
  check_lint(failures, output_parts, logger, chdir: chdir)

  if failures.empty?
    logger.info('All checks passed')
    { success: true }
  else
    logger.warn("Checks failed: #{failures.join(', ')}")
    { success: false, failures: failures, output: output_parts.join("\n\n") }
  end
end

#run_scoped_lint(logger, chdir:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ocak/verification.rb', line 25

def run_scoped_lint(logger, chdir:)
  changed_stdout, = Open3.capture3('git', 'diff', '--name-only', 'main', chdir: chdir)
  changed_files = changed_stdout.lines.map(&:strip).reject(&:empty?)

  extensions = lint_extensions_for(@config.language)
  lintable = changed_files.select { |f| extensions.any? { |ext| f.end_with?(ext) } }

  if lintable.empty?
    logger.info('No changed files to lint')
    return nil
  end

  cmd_parts = Shellwords.shellsplit(@config.lint_check_command)
  cmd_parts << '--force-exclusion' if @config.lint_check_command.include?('rubocop')
  cmd_parts.concat(lintable)

  stdout, stderr, status = Open3.capture3(*cmd_parts, chdir: chdir)
  return nil if status.success?

  "=== #{@config.lint_check_command} (#{lintable.size} files) ===\n#{stdout}\n#{stderr}"
end