From d1acf03750f5345058ef7ca7edc46a95c4d7a7c4 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Tue, 24 Sep 2019 10:57:23 -0400 Subject: [PATCH] chore: Prepare v0.4.0 release Signed-off-by: Ben Johnson --- Makefile | 4 ++ scripts/release-commit.rb | 10 ++- scripts/release-rollback.rb | 120 ++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100755 scripts/release-rollback.rb diff --git a/Makefile b/Makefile index 2516e72150518e..073315b2cb9915 100644 --- a/Makefile +++ b/Makefile @@ -91,6 +91,10 @@ release-meta: ## Prepares the release metadata @bundle install --gemfile=scripts/Gemfile > /dev/null @scripts/release-meta.rb +release-rollback: + @bundle install --gemfile=scripts/Gemfile > /dev/null + @scripts/release-rollback.rb + release-rpm: ## Release .rpm via Package Cloud @scripts/release-rpm.sh diff --git a/scripts/release-commit.rb b/scripts/release-commit.rb index 4d47391ba203c1..12f9cbbdacddde 100755 --- a/scripts/release-commit.rb +++ b/scripts/release-commit.rb @@ -75,9 +75,9 @@ def release_exists?(release) commands = <<~EOF - git add docs/* + git add . -A git commit -sam 'chore: Prepare v#{release.version} release' - git push origin master + git push origin master --force git tag -a v#{release.version} -m "v#{release.version}" git push origin v#{release.version} git branch v#{branch_name} @@ -86,12 +86,18 @@ def release_exists?(release) commands.chomp! + status = `git status --short`.chomp! + words = <<~EOF We'll be releasing v#{release.version} with the following commands: #{commands.indent(2)} + Your current `git status` is: + + #{status.indent(2)} + Proceed to execute the above commands? EOF diff --git a/scripts/release-rollback.rb b/scripts/release-rollback.rb new file mode 100755 index 00000000000000..b244607797485c --- /dev/null +++ b/scripts/release-rollback.rb @@ -0,0 +1,120 @@ +#!/usr/bin/env ruby + +# release-rollback.sh +# +# SUMMARY +# +# Rolls back a fresh release. This should only be used in situations +# where the release process failed. + +# +# Setup +# + +# Changes into the scripts directory so that we can load the Bundler +# dependencies. Unfortunately, Bundler does not provide a way load a Gemfile +# outside of the cwd. +Dir.chdir "scripts" + +# +# Requires +# + +require "rubygems" +require "bundler" +Bundler.require(:default) + +require_relative "util" + +# +# Includes +# + +include Printer + +# +# Constants +# + +ROOT_DIR = Pathname.new("#{Dir.pwd}/..").cleanpath + +DOCS_ROOT = File.join(ROOT_DIR, "docs") +META_ROOT = File.join(ROOT_DIR, ".meta") + +# +# Commit +# + +metadata = + begin + Metadata.load(META_ROOT, DOCS_ROOT) + rescue Exception => e + error!(e.message) + end + +release = metadata.latest_release +version = release.version + +# +# Rollback +# + +input = get("Do you want to rollback #{version}?") + +if input == "n" + error!("You can only rollback the latest release") +end + +branch_commands = + if release.version.patch == 0 + commands = + <<~EOF + git branch -d v#{version.major}.#{version.minor} + git push origin --delete v#{version.major}.#{version.minor} + EOF + + commands.chomp + else + "" + end + +commands = + <<~EOF + git tag -d v#{version} + git push --delete origin v#{version} + #{branch_commands} + git reset HEAD~ + EOF + +commands.chomp! + +words = + <<~EOF + We'll be rolling back v#{version} with the following commands: + + #{commands.indent(2)} + + Proceed to execute the above commands? + EOF + +if get(words, ["y", "n"]) == "n" + error!("Ok, I've aborted. Please re-run this command when you're ready.") +end + +commands.chomp.split("\n").each do |command| + system(command) + + if !$?.success? + error!( + <<~EOF + Command failed! + + #{command} + + Produced the following error: + + #{$?.inspect} + EOF + ) + end + end \ No newline at end of file