main-branch/create_github_release

View on GitHub
exe/create-github-release

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'create_github_release'

# Call method up to max_attempts times until it returns a non-nil value
#
# @param method [Proc] the method to call
# @param max_attempts [Integer] the maximum number of attempts to make
# @param sleep_time [Float] the number of seconds to sleep between attempts
#
# @return [Object] the result of the method call or nil
#
# @api public
#
def wait_for_non_nil(method, max_attempts: 10, sleep_time: 0.5)
  result = nil

  max_attempts.times do |n|
    sleep sleep_time unless n.zero?

    break if (result = method.call)
  end

  result
end

options = CreateGithubRelease::CommandLine::Parser.new.parse!(ARGV).options
pp options if options.verbose

project = CreateGithubRelease::Project.new(options)

CreateGithubRelease::ReleaseAssertions.new(project).make_assertions
puts unless options.quiet
CreateGithubRelease::ReleaseTasks.new(project).run

puts <<~MESSAGE unless project.quiet

  SUCCESS: created release '#{project.next_release_tag}'

  Next steps:

  * Review the release notes:

      #{project.release_url}

  * Get someone to review and approve the release pull request:

      #{wait_for_non_nil(-> { project.release_pr_url }, max_attempts: 10, sleep_time: 0.5)}

  * Merge the pull request manually from the command line with the following
    commands:

      git checkout #{project.default_branch}
      git merge --ff-only #{project.release_branch}
      git push

  * Wait for the CI build to pass on the default branch and then release the
    gem with the following command:

      rake release:rubygem_push

MESSAGE