summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-08-29 18:34:31 +0000
committerThe Bundler Bot <bot@bundler.io>2017-08-29 18:34:31 +0000
commit808b9c90e5e0f365223638e2aa3c225693bdc4c9 (patch)
treea18b8128c11b785411fdb8a9b8013c289b065cd4
parent2bf5fc5caa48ccaea8d34841c19ed31a0e045b71 (diff)
parent8e8b8142c98254d42c710f06627624fe0126b104 (diff)
downloadbundler-808b9c90e5e0f365223638e2aa3c225693bdc4c9.tar.gz
Auto merge of #5977 - bundler:seg-github-release, r=indirect
[Rakefile] Add a task to generate GitHub releases ### What was the end-user problem that led to this PR? The problem was we spend all this time writing up an awesome changelog, yet don't have proper GitHub releases. Closes https://github.com/bundler/bundler/issues/4904. ### What was your diagnosis of the problem? My diagnosis was we needed to automate creating new GH releases, and tie that into the existing `rake release` process. I've already taken the liberty of backfilling existing releases, see https://github.com/bundler/bundler/releases/tag/v1.14.5 for an example
-rw-r--r--task/release.rake81
1 files changed, 80 insertions, 1 deletions
diff --git a/task/release.rake b/task/release.rake
index 401842ba47..de543b84d7 100644
--- a/task/release.rake
+++ b/task/release.rake
@@ -4,9 +4,48 @@ require "bundler/gem_tasks"
task :build => ["build_metadata", "man:build", "generate_files"] do
Rake::Task["build_metadata:clean"].tap(&:reenable).real_invoke
end
-task :release => ["man:require", "man:build", "build_metadata"]
+task :release => ["man:require", "man:build", "release:verify_github", "build_metadata"]
namespace :release do
+ def gh_api_post(opts)
+ gem "netrc", "~> 0.11.0"
+ require "netrc"
+ require "net/http"
+ require "json"
+ _username, token = Netrc.read["api.github.com"]
+
+ host = opts.fetch(:host) { "https://api.github.com/" }
+ path = opts.fetch(:path)
+ uri = URI.join(host, path)
+ uri.query = [uri.query, "access_token=#{token}"].compact.join("&")
+ headers = {
+ "Content-Type" => "application/json",
+ "Accept" => "application/vnd.github.v3+json",
+ "Authorization" => "token #{token}",
+ }.merge(opts.fetch(:headers, {}))
+ body = opts.fetch(:body) { nil }
+
+ response = if body
+ Net::HTTP.post(uri, body.to_json, headers)
+ else
+ Net::HTTP.get_response(uri)
+ end
+
+ if response.code.to_i >= 400
+ raise "#{uri}\n#{response.inspect}\n#{begin
+ JSON.parse(response.body)
+ rescue
+ response.body
+ end}"
+ end
+ JSON.parse(response.body)
+ end
+
+ task :verify_github do
+ require "pp"
+ gh_api_post :path => "/user"
+ end
+
def confirm(prompt = "")
loop do
print(prompt)
@@ -39,6 +78,46 @@ namespace :release do
parsed_response
end
+ def release_notes(version)
+ title_token = "## "
+ current_verison_title = "#{title_token}#{version}"
+ current_minor_title = "#{title_token}#{version.segments[0, 2].join(".")}"
+ text = File.open("CHANGELOG.md", "r:UTF-8", &:read)
+ lines = text.split("\n")
+
+ current_version_index = lines.find_index {|line| line.strip =~ /^#{current_verison_title}($|\b)/ }
+ unless current_version_index
+ raise "Update the changelog for the last version (#{version})"
+ end
+ current_version_index += 1
+ previous_version_lines = lines[current_version_index.succ...-1]
+ previous_version_index = current_version_index + (
+ previous_version_lines.find_index {|line| line.start_with?(title_token) && !line.start_with?(current_minor_title) } ||
+ lines.count
+ )
+
+ relevant = lines[current_version_index..previous_version_index]
+
+ relevant.join("\n").strip
+ end
+
+ task :github, :version do |_t, args|
+ version = Gem::Version.new(args.version)
+ tag = "v#{version}"
+
+ gh_api_post :path => "/repos/bundler/bundler/releases",
+ :body => {
+ :tag_name => tag,
+ :name => tag,
+ :body => release_notes(version),
+ :prerelease => version.prerelease?,
+ }
+ end
+
+ task :release do |args|
+ Rake::Task["release:github"].invoke(args.version)
+ end
+
desc "Make a patch release with the PRs from master in the patch milestone"
task :patch, :version do |_t, args|
version = args.version