Class: NextcloudReleaseAgent::ReleaseManager

Inherits:
Object
  • Object
show all
Defined in:
lib/nextcloud_release_agent/cli.rb

Constant Summary collapse

RELEASE_EVENT =
"release".freeze
PUSH_EVENT =
"push".freeze
PASSED_CONCLUSIONS =
%w[success cancelled skipped neutral].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ReleaseManager

Returns a new instance of ReleaseManager.



216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/nextcloud_release_agent/cli.rb', line 216

def initialize(options)
  @options = options
  @logger = Logger.new
  @shell = Shell.new(logger: @logger, dry_run: options[:dry_run])
  @repo_path = Pathname(options[:repo]).expand_path
  @changelog_path = resolve_changelog_path
  @info_xml_path = @repo_path.join("appinfo", "info.xml")
  @markdown_path = resolve_markdown_path
  @changelog = ChangelogFile.new(@changelog_path)
  @origin_remote = options[:remote]
  @release_remote = options[:release_remote]
  @release_remote_exists = remote_exists?(@release_remote)
  @logger.warn("release remote '#{@release_remote}' not found: skipping release remote steps") unless @release_remote_exists
end

Instance Method Details

#format_changelogObject



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/nextcloud_release_agent/cli.rb', line 231

def format_changelog
  @logger.status("normalizing #{relative_path(@changelog_path)}")
  if @options[:dry_run]
    @logger.info("would write normalized #{relative_path(@changelog_path)}")
    @logger.info("would render #{relative_path(@markdown_path)}")
    return
  end
  @changelog.normalize!
  render_markdown_changelog
  @logger.status("wrote #{relative_path(@changelog_path)} and #{relative_path(@markdown_path)}")
end

#monitor(version = nil) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/nextcloud_release_agent/cli.rb', line 282

def monitor(version = nil)
  version ||= latest_version
  commit_sha = git("rev-parse", "HEAD").stdout.strip
  tag_name = "v#{version}"
  @logger.status("monitoring workflow runs for #{tag_name}")

  targets = [[@origin_remote, PUSH_EVENT]]
  targets << [@release_remote, RELEASE_EVENT] if @release_remote_exists

  threads = targets.map do |remote_name, event|
    Thread.new { monitor_repo_runs(remote_name, event, commit_sha, version) }
  end
  threads.each(&:join)
end

#prepareObject



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/nextcloud_release_agent/cli.rb', line 243

def prepare
  with_release_context do |context|
    branch_name = "#{@options[:branch_prefix]}#{context[:version]}"
    create_or_reset_branch(branch_name, context[:default_branch])
    (context)
    commit_paths = [relative_path(@changelog_path), relative_path(@markdown_path), relative_path(@info_xml_path)]
    commit_release(branch_name, context[:version], commit_paths)
    return if @options[:no_push]

    push_branch(branch_name)
    pr = create_pull_request(branch_name, context[:default_branch], context[:version], context[:release_notes])
    @logger.status("prepared release #{context[:version]} on #{branch_name}")
    @logger.info("pull request: #{pr.fetch('url')}")
    { version: context[:version], branch: branch_name, pr: pr }
  end
end

#publish(version = nil, pr: nil) ⇒ Object

Raises:



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/nextcloud_release_agent/cli.rb', line 260

def publish(version = nil, pr: nil)
  version ||= latest_version
  default_branch = ensure_default_branch_name
  pr ||= find_release_pull_request(version)
  raise Error, "could not find release PR for #{version}" if pr.nil?

  ensure_pull_request_merged(pr.fetch("number"), version)
  sync_default_branch(default_branch)
  tag_name = "v#{version}"
  create_and_push_tag(tag_name)
  release_notes = render_release_notes(version)
  create_github_release(@origin_remote, tag_name, version, release_notes)
  create_github_release(@release_remote, tag_name, version, release_notes) if @release_remote_exists
  monitor(version) if @options[:monitor]
  { version: version, pr: pr, tag: tag_name }
end

#runObject



277
278
279
280
# File 'lib/nextcloud_release_agent/cli.rb', line 277

def run
  prepared = prepare
  publish(prepared.fetch(:version), pr: prepared.fetch(:pr))
end