Skip to content

Instantly share code, notes, and snippets.

Last active April 26, 2020 13:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save p8/33563f7378376218a9ce078578b6c095 to your computer and use it in GitHub Desktop.
RSpec Mono Repo merge script
#!/usr/bin/env ruby
working_dir = 'working'
Repo =, :url, :branch)
repos = ['rspec', ''),'rspec-core', ''),'rspec-expectations', ''),'rspec-mocks', ''),'rspec-support', '')
# merge everything into the rspec-monorepo-prototype repo for now
mono_repo ='rspec-mono', '')
# Clone the mono repo
mkdir #{working_dir}
cd #{working_dir}
git clone #{mono_repo.url} #{}
# Merge sub repos into the mono repo while keeping the commit history.
# 1bf79d2bf is the initial commit of the mono-repo without the sub repos
# to prevent merge conflicts
%w[3-9-maintenance].each do |branch|
cd #{working_dir}
cd #{}
git checkout 1bf79d2bf
git checkout -b #{branch}
repos.each do |repo|
repo.branch = branch
# Check out the sub repo and move all files to a sub directory
# with the same name as the repo.
# Merge the sub repo into the mono repo while keeping history.
cd #{working_dir}
rm -rf #{}
git clone #{repo.url} #{}
cd #{}
mkdir #{}
git fetch --tags
git checkout -b #{repo.branch} origin/#{repo.branch}
git mv -k * #{}
git mv -k {.[!.]*,..?*} #{}
git commit -m 'Moving #{} into its own subdirectory'
cd ../#{}
git remote add #{} ../#{}
git fetch #{}
git merge --allow-unrelated-histories --ff #{}/#{repo.branch}
# rspec-expectations and rspec-mocks both moved License.txt to
# Resolve this merge conflict by removing License.txt and adding the
# for both sub repos.
cd #{working_dir}
cd #{}
git rm --ignore-unmatch License.txt
git add rspec-expectations/
git add rspec-mocks/
git commit -m 'Fix merge conflict'
# create scripts for CI
run_build = <<~RUN_BUILD
set -e
function run_build_for {
if [ ! -f ./$1/$SPECS_HAVE_RUN_FILE ]; then # don't rerun specs that have already run
if [ -d ./$1 ]; then
echo "Running specs for $1"
pushd ./$1
bundle install --binstubs --standalone --without documentation --path ../bundle
echo ""
echo "WARNING: The ./$1 directory does not exist. Usually the"
echo "travis build cds into that directory and run the specs to"
echo "ensure the specs still pass with your latest changes, but"
echo "we are going to skip that step."
echo ""
run_build_for "rspec-core"
run_build_for "rspec-expectations"
run_build_for "rspec-mocks"
run_build_for "rspec-support"
File.write(File.join(working_dir,, 'run_build'), run_build)
cd #{working_dir}
cd #{}
mkdir -p script
cp rspec-core/script/ script
cp rspec-core/script/ script
cp rspec-core/script/ script
cp rspec-core/script/update_rubygems_and_install_bundler script
touch script/clone_all_rspec_repos
mv run_build script
chmod +x script/clone_all_rspec_repos
chmod +x script/run_build
cp rspec-core/.travis.yml .
cp rspec-core/maintenance-branch .
git add script .travis.yml maintenance-branch
git commit -m 'Add CI scripts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment