Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2175 from Shopify/release_2_15_1
Browse files Browse the repository at this point in the history
Packaging for release v2.15.1
  • Loading branch information
amcaplan authored Mar 24, 2022
2 parents 750a19a + 971a4c4 commit 80e9697
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h

## [Unreleased]

## Version 2.15.1

### Added
* [#1934](https://github.com/Shopify/shopify-cli/pull/1934): Block directories in theme assets
* [#1880](https://github.com/Shopify/shopify-cli/pull/1880): Recognize attempts to pass a store name and suggest correction
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ group :development, :test do
gem "rubocop-rake", require: false
gem "iniparse", "~> 1.5"
gem "colorize", "~> 0.8.1"
gem "octokit", "~> 4.0"
end

group :test do
Expand Down
46 changes: 39 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
shopify-cli (2.15.0)
shopify-cli (2.15.1)
bugsnag (~> 6.22)
listen (~> 3.7.0)
theme-check (~> 1.10.1)
Expand All @@ -13,13 +13,13 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
ansi (1.5.0)
ast (2.4.2)
bugsnag (6.23.0)
bugsnag (6.24.2)
concurrent-ruby (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.1.9)
concurrent-ruby (1.1.10)
crack (0.4.5)
rexml
cucumber (7.0.0)
Expand Down Expand Up @@ -55,11 +55,34 @@ GEM
cucumber-messages (~> 17.0, >= 17.0.1)
diff-lcs (1.4.4)
fakefs (1.3.2)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.15.4)
hashdiff (1.0.1)
iniparse (1.5.0)
liquid (5.1.0)
listen (3.7.0)
liquid (5.3.0)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
method_source (1.0.0)
Expand All @@ -77,9 +100,13 @@ GEM
ruby-progressbar
mocha (1.13.0)
multi_test (0.1.2)
multipart-post (2.1.1)
nokogiri (1.13.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.21.0)
parser (3.1.1.0)
ast (~> 2.4.1)
Expand All @@ -94,7 +121,7 @@ GEM
rack (2.2.3)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (2.2.0)
Expand All @@ -117,9 +144,13 @@ GEM
rubocop-shopify (2.0.1)
rubocop (~> 1.11)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
sys-uname (1.2.2)
ffi (~> 1.1)
theme-check (1.10.1)
theme-check (1.10.2)
liquid (>= 5.1.0)
nokogiri (>= 1.12)
parser (~> 3)
Expand All @@ -144,6 +175,7 @@ DEPENDENCIES
minitest-fail-fast
minitest-reporters
mocha
octokit (~> 4.0)
pry-byebug
rack
rake
Expand Down
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,33 @@ end
desc("Builds all distribution packages of the CLI")
task(package: "package:all")

namespace :release do
require "shopify_cli/release"

task :prepare, [:new_version] do |_t, args|
new_version = args[:new_version]
unless new_version
raise <<~NO_NEW_VERSION
New version must be provided, e.g.:
$ GITHUB_ACCESS_TOKEN=abcdef rake "release:prepare[1.2.3]"
NO_NEW_VERSION
end
github_access_token = ENV["GITHUB_ACCESS_TOKEN"]
unless github_access_token
raise <<~NO_GITHUB_ACCESS_TOKEN
GitHub access token must be provided, e.g.:
$ GITHUB_ACCESS_TOKEN=abcdef rake "release:prepare[1.2.3]"
NO_GITHUB_ACCESS_TOKEN
end

ShopifyCLI::Release.new(new_version, github_access_token).prepare!
puts "Completed!"
end
end

namespace :extensions do
task :update do
version = ENV.fetch("VERSION").strip
Expand Down
76 changes: 76 additions & 0 deletions lib/shopify_cli/changelog.rb
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
94 changes: 94 additions & 0 deletions lib/shopify_cli/release.rb
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
19 changes: 19 additions & 0 deletions lib/shopify_cli/sed.rb
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
2 changes: 1 addition & 1 deletion lib/shopify_cli/version.rb
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

0 comments on commit 80e9697

Please sign in to comment.