Skip to content

Commit

Permalink
Add rake tasks for GitHub releases and release note
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jul 5, 2023
1 parent d458875 commit a1f6151
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,115 @@ namespace :test do
sh "ruby", "bin/output_test.rb"
end
end

Rake::Task[:release].enhance do
Rake::Task[:"release:note"].invoke
Rake::Task[:"release:github"].invoke
end

namespace :release do
desc "Ensure release note"
task :note do
version = Gem::Version.new(Steep::VERSION)
major, minor, patch, pre = Steep::VERSION.split(".", 4)
major = major.to_i
minor = minor.to_i
patch = patch.to_i

wiki_url = "https://github.com/soutaro/steep/wiki/Release-Note-#{major}.#{minor}"

puts "🧐 Checking if Release note page already exists..."

unless `curl --silent -o/dev/null --head #{wiki_url} -w '%{http_code}'` == "200"
pre_flag = version.prerelease? ? " --pre" : ""
pre_requirement = version.prerelease? ? ", '~> #{major}.#{minor}.#{patch}.#{pre}'" : ""

puts "----"

puts <<~PREFIX if patch
**The latest version of Steep #{major}.#{minor} is `#{pre}`.**
PREFIX

puts <<~TEMPLATE
Some of the highlights in Steep #{major}.#{minor} are:
* New feature 1 (URL)
* New feature 2 (URL)
* New feature 3 (URL)
You can install it with `$ gem install steep#{pre_flag}` or using Bundler.
```rb
gem 'steep', require: false#{pre_requirement}
```
See the [CHANGELOG](https://github.com/soutaro/steep/blob/master/CHANGELOG.md) for the details.
## New feature 1
## New feature 2
## New feature 3
## Diagnostics updates
## Updating Steep
TEMPLATE
puts "----"
puts

puts " ⏩️ Create the release note with the template: #{wiki_url}"
else
if patch == 0 || version.prerelease?
puts " ⏩️ Open the release note and update it at: #{wiki_url}"
else
puts " ✅ Release note is ready!"
end
end
puts
end

desc "Create GitHub release automatically"
task :github do
version = Gem::Version.new(Steep::VERSION)
major, minor, patch, *_ = Steep::VERSION.split(".")
major = major.to_i
minor = minor.to_i
patch = patch.to_i

puts "✏️ Making a draft release on GitHub..."

content = File.read(File.join(__dir__, "CHANGELOG.md"))
changelog = content.scan(/^## \d.*?(?=^## \d)/m)[0]
changelog = changelog.sub(/^.*\n^.*\n/, "").rstrip

notes = <<NOTES
[Release note](https://github.com/soutaro/steep/wiki/Release-Note-#{major}.#{minor})
#{changelog}
NOTES

command = [
"gh",
"release",
"create",
"--draft",
"v#{Steep::VERSION}",
"--title=#{Steep::VERSION}",
"--notes=#{notes}"
]

if version.prerelease?
command << "--prerelease"
end

require "open3"
output, status = Open3.capture2(*command)
if status.success?
puts " ⏩️ Done! Open #{output.chomp} and publish the release!"
puts
end
end
end

0 comments on commit a1f6151

Please sign in to comment.