2020-12-27 11:35:30 -05:00
|
|
|
# This script is based on commands from the wiki:
|
|
|
|
# https://github.com/ruby/spec/wiki/Merging-specs-from-JRuby-and-other-sources
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
IMPLS = {
|
|
|
|
truffleruby: {
|
2018-02-27 15:21:01 -05:00
|
|
|
git: "https://github.com/oracle/truffleruby.git",
|
2017-05-14 10:09:29 -04:00
|
|
|
from_commit: "f10ab6988d",
|
|
|
|
},
|
|
|
|
jruby: {
|
|
|
|
git: "https://github.com/jruby/jruby.git",
|
|
|
|
from_commit: "f10ab6988d",
|
|
|
|
},
|
|
|
|
rbx: {
|
|
|
|
git: "https://github.com/rubinius/rubinius.git",
|
|
|
|
},
|
|
|
|
mri: {
|
|
|
|
git: "https://github.com/ruby/ruby.git",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-06-29 10:35:09 -04:00
|
|
|
MSPEC = ARGV.delete('--mspec')
|
|
|
|
|
2022-01-10 10:29:53 -05:00
|
|
|
CHECK_LAST_MERGE = !MSPEC && ENV['CHECK_LAST_MERGE'] != 'false'
|
2020-05-02 10:03:12 -04:00
|
|
|
TEST_MASTER = ENV['TEST_MASTER'] != 'false'
|
2019-04-27 12:53:20 -04:00
|
|
|
|
2017-09-14 11:56:09 -04:00
|
|
|
MSPEC_REPO = File.expand_path("../../..", __FILE__)
|
|
|
|
raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git")
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
# Assuming the rubyspec repo is a sibling of the mspec repo
|
2017-09-14 11:56:09 -04:00
|
|
|
RUBYSPEC_REPO = File.expand_path("../rubyspec", MSPEC_REPO)
|
2017-05-14 10:09:29 -04:00
|
|
|
raise RUBYSPEC_REPO unless Dir.exist?(RUBYSPEC_REPO)
|
|
|
|
|
2017-06-29 10:35:09 -04:00
|
|
|
SOURCE_REPO = MSPEC ? MSPEC_REPO : RUBYSPEC_REPO
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
NOW = Time.now
|
|
|
|
|
2017-09-14 11:56:09 -04:00
|
|
|
BRIGHT_RED = "\e[31;1m"
|
2017-06-15 08:48:26 -04:00
|
|
|
BRIGHT_YELLOW = "\e[33;1m"
|
|
|
|
RESET = "\e[0m"
|
|
|
|
|
2020-06-27 09:51:35 -04:00
|
|
|
# git filter-branch --subdirectory-filter works fine for our use case
|
|
|
|
ENV['FILTER_BRANCH_SQUELCH_WARNING'] = '1'
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
class RubyImplementation
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def initialize(name, data)
|
|
|
|
@name = name.to_s
|
|
|
|
@data = data
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_url
|
|
|
|
@data[:git]
|
|
|
|
end
|
|
|
|
|
|
|
|
def repo_name
|
|
|
|
File.basename(git_url, ".git")
|
|
|
|
end
|
|
|
|
|
2021-10-20 15:41:45 -04:00
|
|
|
def repo_path
|
|
|
|
"#{__dir__}/#{repo_name}"
|
|
|
|
end
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
def repo_org
|
|
|
|
File.basename(File.dirname(git_url))
|
|
|
|
end
|
|
|
|
|
|
|
|
def from_commit
|
|
|
|
from = @data[:from_commit]
|
|
|
|
"#{from}..." if from
|
|
|
|
end
|
|
|
|
|
2017-05-27 17:54:38 -04:00
|
|
|
def last_merge_message
|
2018-03-26 16:48:01 -04:00
|
|
|
message = @data[:merge_message] || "Update to ruby/spec@"
|
2017-06-29 10:35:09 -04:00
|
|
|
message.gsub!("ruby/spec", "ruby/mspec") if MSPEC
|
|
|
|
message
|
2017-05-27 17:54:38 -04:00
|
|
|
end
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
def prefix
|
2017-09-28 05:19:19 -04:00
|
|
|
MSPEC ? "spec/mspec" : "spec/ruby"
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def rebased_branch
|
|
|
|
"#{@name}-rebased"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sh(*args)
|
|
|
|
puts args.join(' ')
|
|
|
|
system(*args)
|
|
|
|
raise unless $?.success?
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch?(name)
|
|
|
|
branches = `git branch`.sub('*', '').lines.map(&:strip)
|
|
|
|
branches.include?(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_repo(impl)
|
|
|
|
unless File.directory? impl.repo_name
|
|
|
|
sh "git", "clone", impl.git_url
|
|
|
|
end
|
|
|
|
|
|
|
|
Dir.chdir(impl.repo_name) do
|
|
|
|
puts Dir.pwd
|
|
|
|
|
2019-12-27 10:46:05 -05:00
|
|
|
sh "git", "checkout", "master"
|
2017-05-14 10:09:29 -04:00
|
|
|
sh "git", "pull"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_commits(impl)
|
|
|
|
Dir.chdir(impl.repo_name) do
|
|
|
|
date = NOW.strftime("%F")
|
2017-06-29 10:35:09 -04:00
|
|
|
branch = "#{MSPEC ? :mspec : :specs}-#{date}"
|
2017-05-14 10:09:29 -04:00
|
|
|
|
|
|
|
unless branch?(branch)
|
|
|
|
sh "git", "checkout", "-b", branch
|
|
|
|
sh "git", "filter-branch", "-f", "--subdirectory-filter", impl.prefix, *impl.from_commit
|
2017-06-29 10:35:09 -04:00
|
|
|
sh "git", "push", "-f", SOURCE_REPO, "#{branch}:#{impl.name}"
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebase_commits(impl)
|
2017-06-29 10:35:09 -04:00
|
|
|
Dir.chdir(SOURCE_REPO) do
|
2017-05-14 10:09:29 -04:00
|
|
|
sh "git", "checkout", "master"
|
|
|
|
sh "git", "pull"
|
|
|
|
|
|
|
|
rebased = impl.rebased_branch
|
|
|
|
if branch?(rebased)
|
2017-09-14 11:56:09 -04:00
|
|
|
last_commit = Time.at(Integer(`git log -n 1 --format='%ct' #{rebased}`))
|
|
|
|
days_since_last_commit = (NOW-last_commit) / 86400
|
|
|
|
if days_since_last_commit > 7
|
|
|
|
abort "#{BRIGHT_RED}#{rebased} exists but last commit is old (#{last_commit}), delete the branch if it was merged#{RESET}"
|
|
|
|
else
|
|
|
|
puts "#{BRIGHT_YELLOW}#{rebased} already exists, last commit on #{last_commit}, assuming it correct#{RESET}"
|
|
|
|
sh "git", "checkout", rebased
|
|
|
|
end
|
2017-05-14 10:09:29 -04:00
|
|
|
else
|
|
|
|
sh "git", "checkout", impl.name
|
|
|
|
|
|
|
|
if ENV["LAST_MERGE"]
|
|
|
|
last_merge = `git log -n 1 --format='%H %ct' #{ENV["LAST_MERGE"]}`
|
|
|
|
else
|
2017-06-15 08:48:26 -04:00
|
|
|
last_merge = `git log --grep='^#{impl.last_merge_message}' -n 1 --format='%H %ct'`
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
2020-03-07 02:41:19 -05:00
|
|
|
last_merge, commit_timestamp = last_merge.split(' ')
|
2017-05-14 10:09:29 -04:00
|
|
|
|
|
|
|
raise "Could not find last merge" unless last_merge
|
|
|
|
puts "Last merge is #{last_merge}"
|
|
|
|
|
|
|
|
commit_date = Time.at(Integer(commit_timestamp))
|
|
|
|
days_since_last_merge = (NOW-commit_date) / 86400
|
2019-04-27 12:53:20 -04:00
|
|
|
if CHECK_LAST_MERGE and days_since_last_merge > 60
|
2017-09-14 11:56:09 -04:00
|
|
|
raise "#{days_since_last_merge.floor} days since last merge, probably wrong commit"
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
|
2021-10-20 15:41:45 -04:00
|
|
|
puts "Checking if the last merge is consistent with upstream files"
|
|
|
|
rubyspec_commit = `git log -n 1 --format='%s' #{last_merge}`.chomp.split('@', 2)[-1]
|
|
|
|
sh "git", "checkout", last_merge
|
|
|
|
sh "git", "diff", "--exit-code", rubyspec_commit, "--", ":!.github"
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
puts "Rebasing..."
|
|
|
|
sh "git", "branch", "-D", rebased if branch?(rebased)
|
|
|
|
sh "git", "checkout", "-b", rebased, impl.name
|
|
|
|
sh "git", "rebase", "--onto", "master", last_merge
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-30 06:39:18 -04:00
|
|
|
def new_commits?(impl)
|
|
|
|
Dir.chdir(SOURCE_REPO) do
|
|
|
|
diff = `git diff master #{impl.rebased_branch}`
|
|
|
|
!diff.empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
def test_new_specs
|
|
|
|
require "yaml"
|
2017-06-29 10:35:09 -04:00
|
|
|
Dir.chdir(SOURCE_REPO) do
|
2020-01-28 14:47:46 -05:00
|
|
|
workflow = YAML.load_file(".github/workflows/ci.yml")
|
2020-02-28 13:07:14 -05:00
|
|
|
job_name = MSPEC ? "test" : "specs"
|
|
|
|
versions = workflow.dig("jobs", job_name, "strategy", "matrix", "ruby")
|
2018-12-28 19:22:31 -05:00
|
|
|
versions = versions.grep(/^\d+\./) # Test on MRI
|
2018-06-27 07:37:19 -04:00
|
|
|
min_version, max_version = versions.minmax
|
|
|
|
|
2020-12-27 11:35:30 -05:00
|
|
|
test_command = MSPEC ? "bundle install && bundle exec rspec" : "../mspec/bin/mspec -j"
|
2018-06-27 07:37:19 -04:00
|
|
|
|
|
|
|
run_test = -> version {
|
|
|
|
command = "chruby #{version} && #{test_command}"
|
|
|
|
sh ENV["SHELL"], "-c", command
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test[min_version]
|
|
|
|
run_test[max_version]
|
2020-07-27 15:41:03 -04:00
|
|
|
run_test["ruby-master"] if TEST_MASTER
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_commits(impl)
|
|
|
|
puts
|
2017-06-29 10:35:09 -04:00
|
|
|
Dir.chdir(SOURCE_REPO) do
|
2017-05-14 10:09:29 -04:00
|
|
|
puts "Manually check commit messages:"
|
2017-05-27 17:54:38 -04:00
|
|
|
print "Press enter >"
|
|
|
|
STDIN.gets
|
2019-05-30 16:11:22 -04:00
|
|
|
system "git", "log", "master..."
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def fast_forward_master(impl)
|
2017-06-29 10:35:09 -04:00
|
|
|
Dir.chdir(SOURCE_REPO) do
|
2017-05-14 10:09:29 -04:00
|
|
|
sh "git", "checkout", "master"
|
2020-09-30 06:39:18 -04:00
|
|
|
sh "git", "merge", "--ff-only", impl.rebased_branch
|
|
|
|
sh "git", "branch", "--delete", impl.rebased_branch
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_ci
|
|
|
|
puts
|
|
|
|
puts <<-EOS
|
|
|
|
Push to master, and check that the CI passes:
|
2017-06-29 10:35:09 -04:00
|
|
|
https://github.com/ruby/#{:m if MSPEC}spec/commits/master
|
2017-05-27 17:54:38 -04:00
|
|
|
|
2017-05-14 10:09:29 -04:00
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
def main(impls)
|
|
|
|
impls.each_pair do |impl, data|
|
|
|
|
impl = RubyImplementation.new(impl, data)
|
|
|
|
update_repo(impl)
|
|
|
|
filter_commits(impl)
|
|
|
|
rebase_commits(impl)
|
2020-09-30 06:39:18 -04:00
|
|
|
if new_commits?(impl)
|
|
|
|
test_new_specs
|
|
|
|
verify_commits(impl)
|
|
|
|
fast_forward_master(impl)
|
|
|
|
check_ci
|
|
|
|
else
|
|
|
|
STDERR.puts "#{BRIGHT_YELLOW}No new commits#{RESET}"
|
|
|
|
fast_forward_master(impl)
|
|
|
|
end
|
2017-05-14 10:09:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if ARGV == ["all"]
|
|
|
|
impls = IMPLS
|
|
|
|
else
|
|
|
|
args = ARGV.map { |arg| arg.to_sym }
|
|
|
|
raise ARGV.to_s unless (args - IMPLS.keys).empty?
|
|
|
|
impls = IMPLS.select { |impl| args.include?(impl) }
|
|
|
|
end
|
|
|
|
|
|
|
|
main(impls)
|