Skip to content

Commit

Permalink
Add release:create_github_release task
Browse files Browse the repository at this point in the history
Leverages the `gh` CLI to create a release. This uses the same command that we specified in the README for releasing, but programmatically determines the version to specify and automatically crafts the proper release notes (linking to the CHANGELOG and the diff view).
  • Loading branch information
darronschall committed May 28, 2024
1 parent 545fa32 commit 38bc660
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tasks/release.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require "date"
require "rake"
require "twirp/protoc_plugin/core_ext/string/to_anchor"

desc "Gets the latest GitHub release version, e.g: v1.1.1"
task "release:latest_github_release" do
Expand All @@ -9,3 +11,38 @@ task "release:latest_github_release" do
# but we go through the `gh` because we want the latest _GitHub_ release.
$stdout << `gh release view --json tagName --jq '.tagName'`
end

desc "Creates a GitHub release for v#{Bundler::GemHelper.gemspec.version}"
task "release:create_github_release" do
github_release = `bundle exec rake release:latest_github_release`.chomp
version = Bundler::GemHelper.gemspec.version.to_s

notes = <<~NOTES
See [CHANGELOG.md](#{changelog_link(version)}) for release details.
Full changes: #{compare_link(github_release, version)}
NOTES

`gh release create v#{version} --verify-tag --latest --notes "#{notes}"`
end

def repo_base_url
"https://github.com/collectiveidea/protoc-gen-twirp_ruby"
end

def changelog_link(version)
"#{repo_base_url}/blob/main/CHANGELOG.md##{changelog_heading(version).to_anchor}"
end

# @param version [String] the version, e.g. "1.2.0"
def changelog_heading(version)
# Assume the heading in the CHANGELOG.md is always a consistent
# format: "[1.1.1] - 2024-05-22"
"[#{version}] - #{DateTime.now.strftime("%Y-%m-%d")}"
end

# @param previous_tag [String] the previous version tag, e.g. "v1.1.1"
# @param current_version [String] the current version, e.g. "1.2.0"
def compare_link(previous_tag, current_version)
"#{repo_base_url}/compare/#{previous_tag}...v#{current_version}"
end

0 comments on commit 38bc660

Please sign in to comment.