-
-
Save basicfeatures/c36821ae92e117e0d4ac49ecc974cbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# USAGE: Run from Rails root: `bin/regen_start` | |
# | |
# ⚠️ WARNING: Backup your project. Rewrites history and modifies files. | |
# | |
# Suite of scripts to perform a thorough update of a Rails project during a Git rebase. | |
# `regen_start` spawns `regen_actions` which handles gems, JS, and DB migrations. | |
# | |
# gem uninstall rails | |
# gem install --user-install specific_install | |
# gem git_install --user-install https://github.com/rails/rails.git -d activesupport | |
# gem git_install --user-install https://github.com/rails/rails.git -d activemodel | |
# gem git_install --user-install https://github.com/rails/rails.git -d activerecord | |
# gem git_install --user-install https://github.com/rails/rails.git -d activejob | |
# gem git_install --user-install https://github.com/rails/rails.git -d actionview | |
# gem git_install --user-install https://github.com/rails/rails.git -d actionpack | |
# gem git_install --user-install https://github.com/rails/rails.git -d activestorage | |
# gem git_install --user-install https://github.com/rails/rails.git -d actiontext | |
# gem git_install --user-install https://github.com/rails/rails.git -d actioncable | |
# gem git_install --user-install https://github.com/rails/rails.git -d actionmailbox | |
# gem git_install --user-install https://github.com/rails/rails.git -d actionmailer | |
# gem git_install --user-install https://github.com/rails/rails.git -d railties | |
# gem git_install --user-install https://github.com/rails/rails.git | |
# | |
# $ ruby32 -v | |
# ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-openbsd] | |
# $ rails32 -v | |
# Rails 7.1.0.beta1 | |
# | |
# Safety prompt | |
puts "This script is potentially harmful. Continue? [y/N]: " | |
response = gets.chomp | |
unless response.casecmp("y").zero? | |
puts "Aborting." | |
exit | |
end | |
puts "Copying regeneration script to /tmp..." | |
File.write("/tmp/regen_actions.rb", File.read("bin/regen_actions.rb")) | |
puts "Initiating rebase..." | |
puts "Save and exit the editor to continue." | |
sleep(2) | |
system("git rebase -i --root --exec 'ruby /tmp/regen_actions.rb'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# USAGE: Run from Rails root: `bin/regen_start` | |
# | |
def regenerate_rails_app | |
puts "Deleting existing files..." | |
system("rm -rf *") | |
system("git clean -df") | |
puts "Done." | |
puts "Regenerating Rails app skeleton..." | |
if system("rails32 new . --main --database=postgresql --javascript=esbuild --css=sass --asset-pipeline=propshaft --skip-docker") | |
puts "Done." | |
else | |
puts "Failed to regenerate:" | |
system("git status") | |
exit(1) | |
end | |
puts "Adding and committing to Git..." | |
system("git add -A") | |
system("git commit --amend --no-edit") | |
puts "Moving onto next commit." | |
end | |
def refresh_commit | |
puts "Refreshing gems, JS libs, and database migrations..." | |
system("bundle") | |
system("yarn") | |
system("bin/rails db:migrate") | |
puts "Adding and committing to Git..." | |
system("git add -A") | |
system("git commit --amend --no-edit") | |
# Check if there are any more commits left to rebase | |
if File.exist?(".git/rebase-merge/git-rebase-todo") || File.exist?(".git/rebase-apply/git-rebase-todo") | |
puts "Moving onto next commit." | |
else | |
puts "Removing script from /tmp..." | |
File.unlink("/tmp/regen_actions.rb") | |
puts "Congratulations! Your Rails app has been thoroughly updated." | |
end | |
end | |
current_head = `git rev-parse HEAD`.chomp | |
initial_commit = `git rev-list --max-parents=0 HEAD`.chomp | |
if current_head == initial_commit | |
puts "Initial commit (#{ initial_commit }). Running app regeneration..." | |
regenerate_rails_app | |
else | |
puts "Subsequent commit (#{ current_head }). Running misc refresh..." | |
refresh_commit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment