Skip to content

Commit

Permalink
Move the release draft updater to bin/release
Browse files Browse the repository at this point in the history
Make the release draft generator idempotent by relying on GitHub's
generator we can list all involved PRs and fetch the updated title every
time without needing a PR merge event.
  • Loading branch information
elia committed Oct 25, 2023
1 parent 4b81d37 commit 0a3d22b
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 868 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/update_release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ jobs:
bundler-cache: true
- name: "Save Release Draft"
run: |
cd dev_tools/ && bin/update-release-draft \
${{ github.token }} \
${{ github.repository }} \
bin/release/update-release-draft \
--update \
--branch ${{ github.ref_name }} \
${{ steps.pipeline_context.outputs.current_diff_source_tag }} \
${{ steps.pipeline_context.outputs.candidate_tag }} \
${{ github.ref_name }} \
${{ github.event.number }}
4 changes: 0 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ Lint/ShadowingOuterLocalVariable:
Exclude:
- "core/app/models/spree/order_inventory.rb"
- "core/lib/generators/solidus/install/install_generator.rb"
- "dev_tools/lib/solidus/release_drafter.rb"
- "dev_tools/lib/solidus/release_drafter/client.rb"

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -276,14 +274,12 @@ Lint/UnusedBlockArgument:
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- "dev_tools/spec/lib/solidus/release_drafter_spec.rb"

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- "dev_tools/lib/solidus/release_drafter.rb"

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand Down
66 changes: 66 additions & 0 deletions bin/release/update-release-draft
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '_helpers'
require 'optparse'
require 'yaml'

branch = 'main'
update = false

opts = OptionParser.new
opts.banner = "Usage: #{$0} [options] <previous_tag_name> <candidate_tag_name>"
opts.on("-b", "--branch BRANCH", "GitHub branch") { branch = _1 }
opts.on("-u", "--update", "Update the release draft instead of creating a new one") { update = true }
opts.on("-h", "--help", "Prints this help") { puts opts; exit }
opts.parse!

previous_tag_name = ARGV.shift or abort(opts.to_s)
candidate_tag_name = ARGV.shift or abort(opts.to_s)

# Let GH generate a list of PRs between the previous tag and the current
# one. The generated notes are not good for us because we want PRs to
# appear multiple times.
pull_numbers = OCTOKIT.post("/repos/solidusio/solidus/releases/generate-notes", {
tag_name: candidate_tag_name,
target_commitish: branch,
previous_tag_name: previous_tag_name,
}).body.scan(%r{(?:#|pull/)(\d+)$}).flatten.uniq

# Group PRs by label
pulls_by_label = Hash.new { |h, k| h[k] = [] }
pull_numbers.map { |n| Thread.new{ OCTOKIT.pull_request('solidusio/solidus', n) } }.map(&:value).each do |pull|
pull.labels.each { pulls_by_label[_1.name] << pull }
end

warn "~~> Generating release notes draft for solidusio/solidus@#{branch}, from #{previous_tag_name} to #{candidate_tag_name}..."
notes = "<!-- Please, don't edit manually. The content is automatically generated. -->"
release_config = YAML.load_file("#{ROOT}/.github/release.yml", symbolize_names: true)
release_config.dig(:changelog, :categories).each do |category|
pull_requests = pulls_by_label.values_at(*category[:labels]).flatten.compact.uniq

next if pull_requests.empty? # Skip empty categories

notes += "\n\n## #{category[:title]}\n"
pull_requests.each do |pull_request|
notes += "\n* #{pull_request[:title]} by @#{pull_request[:user][:login]} in #{pull_request[:html_url]}"
end
end
notes += "\n\n**Full Changelog**: https://github.com/solidusio/solidus/compare/#{previous_tag_name}...#{candidate_tag_name}\n"

if update
release =
OCTOKIT.releases('solidusio/solidus').find {
_1.name == candidate_tag_name
} || OCTOKIT.create_release(
'solidusio/solidus',
candidate_tag_name,
body: notes,
target_commitish: branch,
draft: true,
)

OCTOKIT.update_release(release.url, body: notes)
else
puts notes
end
48 changes: 0 additions & 48 deletions dev_tools/bin/update-release-draft

This file was deleted.

82 changes: 0 additions & 82 deletions dev_tools/lib/solidus/release_drafter.rb

This file was deleted.

140 changes: 0 additions & 140 deletions dev_tools/lib/solidus/release_drafter/builder.rb

This file was deleted.

Loading

0 comments on commit 0a3d22b

Please sign in to comment.