Module: PDK::CLI::Release

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

Class Method Summary collapse

Class Method Details

.module_compatibility_checks!(release, opts) ⇒ Object

Checks whether the module is compatible with PDK release process

Parameters:

  • release

    PDK::Module::Release Object representing the release

  • opts

    Options Hash from Cri



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
# File 'lib/pdk/cli/release.rb', line 56

def self.module_compatibility_checks!(release, opts)
  unless release..forge_ready?
    if opts[:force]
      PDK.logger.warn _(
        'This module is missing the following fields in the metadata.json: %{fields}. ' \
        'These missing fields may affect the visibility of the module on the Forge.',
      ) % {
        fields: release..missing_fields.join(', '),
      }
    else
      release..interview_for_forge!
      release.write_module_metadata!
    end
  end

  unless release.pdk_compatible? # rubocop:disable Style/GuardClause Nope!
    if opts[:force]
      PDK.logger.warn _('This module is not compatible with PDK, so PDK can not validate or test this build.')
    else
      PDK.logger.info _('This module is not compatible with PDK, so PDK can not validate or test this build. ' \
                        'Unvalidated modules may have errors when uploading to the Forge. ' \
                        'To make this module PDK compatible and use validate features, cancel the build and run `pdk convert`.')
      unless PDK::CLI::Util.prompt_for_yes(_('Continue build without converting?'))
        PDK.logger.info _('Build cancelled; exiting.')
        PDK::Util.exit_process(1)
      end
    end
  end
end

.prepare_interview(opts) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/pdk/cli/release.rb', line 92

def self.prepare_interview(opts)
  questions = []

  unless opts[:'skip-validation']
    questions << {
      name:     'validation',
      question: _('Do you want to run the module validation ?'),
      type:     :yes,
    }
  end
  unless opts[:'skip-changelog']
    questions << {
      name:     'changelog',
      question: _('Do you want to run the automatic changelog generation ?'),
      type:     :yes,
    }
  end
  unless opts[:version]
    questions << {
      name:     'setversion',
      question: _('Do you want to set the module version ?'),
      type:     :yes,
    }
  end
  unless opts[:'skip-dependency']
    questions << {
      name:     'dependency',
      question: _('Do you want to run the dependency-checker on this module?'),
      type:     :yes,
    }
  end
  unless opts[:'skip-documentation']
    questions << {
      name:     'documentation',
      question: _('Do you want to update the documentation for this module?'),
      type:     :yes,
    }
  end
  unless opts[:'skip-publish']
    questions << {
      name:     'publish',
      question: _('Do you want to publish the module on the Puppet Forge?'),
      type:     :yes,
    }
  end

  prompt = TTY::Prompt.new(help_color: :cyan)
  interview = PDK::CLI::Util::Interview.new(prompt)
  interview.add_questions(questions)
  answers = interview.run

  unless answers.nil?
    opts[:'skip-validation'] = !answers['validation']
    opts[:'skip-changelog'] = !answers['changelog']
    opts[:'skip-dependency'] = !answers['dependency']
    opts[:'skip-documentation'] = !answers['documentation']

    prepare_version_interview(prompt, opts) if answers['setversion']

    prepare_publish_interview(prompt, opts) if answers['publish']
  end
  answers
end

.prepare_publish_interview(prompt, opts) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/pdk/cli/release.rb', line 173

def self.prepare_publish_interview(prompt, opts)
  return if opts[:'forge-token']
  questions = [
    {
      name:             'apikey',
      question:         _('Please set the api key(authorization token) to upload on the Puppet Forge'),
      help:             _('This value is used for authentication on the Puppet Forge to upload your module tarball.'),
      required:         true,
    },
  ]
  interview = PDK::CLI::Util::Interview.new(prompt)
  interview.add_questions(questions)
  api_answer = interview.run
  opts[:'forge-token'] = api_answer['apikey']
end

.prepare_version_interview(prompt, opts) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pdk/cli/release.rb', line 156

def self.prepare_version_interview(prompt, opts)
  questions = [
    {
      name:             'version',
      question:         _('Please set the module version'),
      help:             _('This value is the version that will be used in the changelog generator and building of the module.'),
      required:         true,
      validate_pattern: %r{(\*|\d+(\.\d+){0,2}(\.\*)?)$}i,
      validate_message: _('The version format should be in the format x.y.z where x represents the major version, y the minor version and z the build number.'),
    },
  ]
  interview = PDK::CLI::Util::Interview.new(prompt)
  interview.add_questions(questions)
  ver_answer = interview.run
  opts[:version] = ver_answer['version']
end

.send_analytics(command, opts) ⇒ Object

Send_analytics for the given command and Cri options



87
88
89
90
# File 'lib/pdk/cli/release.rb', line 87

def self.send_analytics(command, opts)
  # Don't pass tokens to analytics
  PDK::CLI::Util.analytics_screen_view(command, opts.reject { |k, _| k == :'forge-token' })
end