2018-04-17 12:50:16 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'optparse'
|
|
|
|
require 'open3'
|
|
|
|
require 'rainbow/refinement'
|
|
|
|
using Rainbow
|
|
|
|
|
|
|
|
BRANCH_PREFIX = 'security'.freeze
|
|
|
|
REMOTE = 'dev'.freeze
|
|
|
|
|
|
|
|
options = { version: nil, branch: nil, sha: nil }
|
|
|
|
|
|
|
|
parser = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: #{$0} [options]"
|
|
|
|
opts.on('-v', '--version 10.0', 'Version') do |version|
|
|
|
|
options[:version] = version&.tr('.', '-')
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-b', '--branch security-fix-branch', 'Original branch name') do |branch|
|
|
|
|
options[:branch] = branch
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-s', '--sha abcd', 'SHA to cherry pick') do |sha|
|
|
|
|
options[:sha] = sha
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on('-h', '--help', 'Displays Help') do
|
|
|
|
puts opts
|
|
|
|
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
parser.parse!
|
|
|
|
|
|
|
|
abort("Missing options. Use #{$0} --help to see the list of options available".red) if options.values.include?(nil)
|
|
|
|
abort("Wrong version format #{options[:version].bold}".red) unless options[:version] =~ /\A\d*\-\d*\Z/
|
|
|
|
|
|
|
|
branch = [BRANCH_PREFIX, options[:branch], options[:version]].join('-').freeze
|
2018-05-14 03:46:04 -04:00
|
|
|
stable_branch = "#{BRANCH_PREFIX}-#{options[:version]}".freeze
|
2018-04-17 12:50:16 -04:00
|
|
|
|
2018-05-14 03:57:53 -04:00
|
|
|
command = "git fetch #{REMOTE} #{stable_branch} && git checkout #{stable_branch} && git pull #{REMOTE} #{stable_branch} && git checkout -B #{branch} && git cherry-pick #{options[:sha]} && git push #{REMOTE} #{branch}"
|
2018-04-17 12:50:16 -04:00
|
|
|
|
|
|
|
_stdin, stdout, stderr = Open3.popen3(command)
|
|
|
|
|
|
|
|
puts stdout.read&.green
|
|
|
|
puts stderr.read&.red
|