This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2175 from Shopify/release_2_15_1
Packaging for release v2.15.1
- Loading branch information
Showing
8 changed files
with
259 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require "shopify_cli/sed" | ||
|
||
module ShopifyCLI | ||
class Changelog | ||
CHANGELOG_FILE = File.join(ShopifyCLI::ROOT, "CHANGELOG.md") | ||
|
||
def initialize | ||
load(File.read(CHANGELOG_FILE)) | ||
end | ||
|
||
def update_version!(new_version) | ||
Sed.new.replace_inline( | ||
CHANGELOG_FILE, | ||
"## \\[Unreleased\\]", | ||
"## [Unreleased]\\n\\n## Version #{new_version}" | ||
) | ||
end | ||
|
||
def release_notes(version) | ||
changes[version].map do |change_category, changes| | ||
<<~CHANGES | ||
### #{change_category} | ||
#{changes.map { |change| entry(**change) }.join("\n")} | ||
CHANGES | ||
end.join("\n") | ||
end | ||
|
||
def entry(pr_id:, desc:) | ||
"* [##{pr_id}](https://github.com/Shopify/shopify-cli/pull/#{pr_id}): #{desc}" | ||
end | ||
|
||
private | ||
|
||
def changes | ||
@changes ||= Hash.new do |h, k| | ||
h[k] = Hash.new do |h2, k2| | ||
h2[k2] = [] | ||
end | ||
end | ||
end | ||
|
||
def load(log) | ||
state = :initial | ||
change_category = nil | ||
current_version = nil | ||
@remainder = "" | ||
log.each_line do |line| | ||
case state | ||
when :initial | ||
next unless line.chomp == "\#\# [Unreleased]" | ||
state = :unreleased | ||
current_version = "Unreleased" | ||
when :unreleased, :last_version | ||
if /\A\#\#\# (?<category>\w+)/ =~ line | ||
change_category = category | ||
elsif %r{\A\* \[\#(?<pr_id>\d+)\]\(https://github.com/Shopify/shopify-cli/pull/\d+\): (?<desc>.+)\n} =~ line | ||
changes[current_version][change_category] << { pr_id: pr_id, desc: desc } | ||
elsif /\A\#\# Version (?<version>\d+\.\d+\.\d+)/ =~ line | ||
current_version = version | ||
state = | ||
case state | ||
when :unreleased | ||
:last_version | ||
else | ||
:finished | ||
end | ||
elsif !line.match?(/\s*\n/) | ||
raise "Unrecognized line: #{line.inspect}" | ||
end | ||
when :finished | ||
@remainder << line | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
require "shopify_cli/sed" | ||
require "shopify_cli/changelog" | ||
require "octokit" | ||
|
||
module ShopifyCLI | ||
class Release | ||
def initialize(new_version, github_access_token) | ||
@new_version = new_version | ||
@changelog = ShopifyCLI::Changelog.new | ||
@github = Octokit::Client.new(access_token: github_access_token) | ||
end | ||
|
||
def prepare! | ||
ensure_updated_main | ||
create_release_branch | ||
update_changelog | ||
update_versions_in_files | ||
commit | ||
pr = create_pr | ||
system("open #{pr["html_url"]}") | ||
end | ||
|
||
private | ||
|
||
attr_reader :new_version, :changelog, :github | ||
|
||
def ensure_updated_main | ||
current_branch = %x(git branch --show-current) | ||
unless current_branch == "main" | ||
raise "Must be on the main branch to package a release!" | ||
end | ||
unless system("git pull") | ||
raise "git pull failed, cannot be sure there aren't new commits!" | ||
end | ||
end | ||
|
||
def create_release_branch | ||
puts "Checking out release branch" | ||
unless system("git checkout -b #{release_branch_name}") | ||
puts "Cannot check out release branch!" | ||
end | ||
end | ||
|
||
def update_changelog | ||
if release_notes.empty? | ||
puts "No unreleased CHANGELOG updates found!" | ||
else | ||
puts "Updating CHANGELOG" | ||
changelog.update_version!(new_version) | ||
end | ||
end | ||
|
||
def update_versions_in_files | ||
version_file = File.join(ShopifyCLI::ROOT, "lib/shopify_cli/version.rb") | ||
puts "Updating version.rb" | ||
ShopifyCLI::Sed.new.replace_inline(version_file, ShopifyCLI::VERSION, new_version) | ||
gemfile_lock = File.join(ShopifyCLI::ROOT, "Gemfile.lock") | ||
puts "Updating Gemfile.lock" | ||
ShopifyCLI::Sed.new.replace_inline( | ||
gemfile_lock, | ||
"shopify-cli (#{ShopifyCLI::VERSION})", | ||
"shopify-cli (#{new_version})", | ||
) | ||
end | ||
|
||
def commit | ||
puts "Committing" | ||
unless system("git commit -am 'Packaging for release v#{new_version}'") | ||
puts "Commit failed!" | ||
end | ||
unless system("git push -u origin #{release_branch_name}") | ||
puts "Failed to push branch!" | ||
end | ||
end | ||
|
||
def create_pr | ||
github.create_pull_request( | ||
"Shopify/shopify-cli", | ||
"main", | ||
release_branch_name, | ||
"Packaging for release v#{new_version}", | ||
release_notes | ||
).tap { |results| puts "Created PR ##{results["number"]}" } | ||
end | ||
|
||
def release_branch_name | ||
@release_branch_name ||= "release_#{new_version.split(".").join("_")}" | ||
end | ||
|
||
def release_notes | ||
@release_notes ||= changelog.release_notes("Unreleased") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module ShopifyCLI | ||
class Sed | ||
class SedError < StandardError; end | ||
|
||
def replace_inline(filename, pattern, output) | ||
command = | ||
case CLI::Kit::System.os | ||
when :mac | ||
"sed -i ''" | ||
when :linux | ||
"sed -i" | ||
else | ||
raise "Unrecognized system!" | ||
end | ||
success = system("#{command} 's/#{pattern}/#{output}/' #{filename}") | ||
raise SedError unless success | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ShopifyCLI | ||
VERSION = "2.15.0" | ||
VERSION = "2.15.1" | ||
end |