Method: PDK::Module::Release#run

Defined in:
lib/pdk/module/release.rb

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pdk/module/release.rb', line 29

def run
  # Pre-release checks
  unless force?
    raise PDK::CLI::ExitWithError, _('The module is not PDK compatible') if requires_pdk_compatibility? && !pdk_compatible?
    raise PDK::CLI::ExitWithError, _('The module is not Forge compatible') if requires_forge_compatibility? && !forge_compatible?
  end

  # Note that these checks are duplicated in the run_publish method, however it's a much better
  # experience to fail early, than going through the whole process, only to error at the end knowing full well
  # it'll fail anyway.
  validate_publish_options!

  run_validations(options) unless skip_validation?

  PDK.logger.info _('Releasing %{module_name} - from version %{module_version}') % {
    module_name:    .data['name'],
    module_version: .data['version'],
  }

  PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?

  # Calculate the new module version
  new_version = specified_version
  if new_version.nil? && !skip_changelog?
    new_version = PDK::Util::ChangelogGenerator.compute_next_version(.data['version'])
  end
  new_version = .data['version'] if new_version.nil?

  if new_version != .data['version']
    PDK.logger.info _('Updating version to %{module_version}') % {
      module_version: new_version,
    }

    # Set the new version in metadata file
    .data['version'] = new_version
    write_module_metadata!

    # Update the changelog with the correct version
    PDK::Util::ChangelogGenerator.generate_changelog unless skip_changelog?

    # Check if the versions match
    latest_version = PDK::Util::ChangelogGenerator.latest_version
    unless latest_version
      raise PDK::CLI::ExitWithError, _('%{new_version} does not match %{latest_version}') % { new_version: new_version, latest_version: latest_version } if new_version != latest_version
    end
  end

  run_documentation(options) unless skip_documentation?

  run_dependency_checker(options) unless skip_dependency?

  if skip_build?
    # Even if we're skipping the build, we still need the name of the tarball
    # Use the specified package path if set
    package_file = specified_package if package_file.nil?
    # Use the default as a last resort
    package_file = default_package_filename if package_file.nil?
  else
    package_file = run_build(options)
  end

  run_publish(options.dup, package_file) unless skip_publish?
end