-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
82 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,87 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "fileutils" | ||
require "pry" | ||
require_relative "lib/comparison_config" | ||
require_relative "lib/terminal" | ||
|
||
PROJECT_ROOT_PATH = File.absolute_path(File.join(__dir__, ".")) | ||
BUILD_PATH = File.join(PROJECT_ROOT_PATH, "tmp/builds") | ||
COMPARISONS_REPO_ROOT_PATH = File.join(PROJECT_ROOT_PATH, "tmp/rails-template-variants-comparison") | ||
ALL_BUILDS = Dir.children(BUILD_PATH) | ||
class Main | ||
class << self | ||
def main | ||
reset_comparison_repo | ||
use_vanilla_rails_as_main_branch | ||
|
||
VANILLA_BUILD_NAME = ALL_BUILDS.find { |build_name| build_name.start_with?("vanilla_") } | ||
VANILLA_BUILD_PATH = File.join(BUILD_PATH, VANILLA_BUILD_NAME) | ||
COMPARISON_BUILDS = ALL_BUILDS - [VANILLA_BUILD_NAME] | ||
ComparisonConfig.comparison_builds.each do |build_name| | ||
populate_new_branch_for_build(build_name:) | ||
checkout_main | ||
end | ||
end | ||
|
||
def copy_build(build_name:, branch_name:, build_path:) | ||
system("git checkout -b #{branch_name}") | ||
private | ||
|
||
# the `.` at the end of the cp command is what copies the contents of the dir | ||
# including "hidden" `.` files (the same trick works with shell `cp` command) | ||
# FileUtils.cp_r("#{build_path}/.", COMPARISONS_REPO_ROOT_PATH) | ||
system("rsync -av --exclude='.git' --exclude='node_modules' --exclude='tmp' #{build_path}/ #{COMPARISONS_REPO_ROOT_PATH}/") | ||
def reset_comparison_repo | ||
repo_path = ComparisonConfig.comparison_repo_root_path | ||
|
||
system("git add .") | ||
system("git commit -n -m 'Add #{build_name}'") | ||
end | ||
FileUtils.rm_rf(repo_path) | ||
FileUtils.mkdir_p(repo_path) | ||
|
||
Dir.chdir(repo_path) do | ||
system("git init") | ||
system("git remote add origin [email protected]:ackama/rails-template-variants-comparison.git") | ||
end | ||
end | ||
|
||
def use_vanilla_rails_as_main_branch | ||
Terminal.puts_header("Adding vanilla Rails build to main branch") | ||
copy_build(build_path: ComparisonConfig.vanilla_build_path) | ||
commit_changes(commit_message: "Add #{ComparisonConfig.vanilla_build_name}") | ||
end | ||
|
||
def populate_new_branch_for_build(build_name:) | ||
Terminal.puts_header("Creating branch for #{build_name}") | ||
|
||
def main | ||
FileUtils.rm_rf(COMPARISONS_REPO_ROOT_PATH) | ||
FileUtils.mkdir_p(COMPARISONS_REPO_ROOT_PATH) | ||
rm_rf_except_git_dir | ||
create_new_branch(branch_name: build_name) | ||
|
||
Dir.chdir(COMPARISONS_REPO_ROOT_PATH) do | ||
system("git init") | ||
system("git remote add origin [email protected]:ackama/rails-template-variants-comparison.git") | ||
build_path = File.join(ComparisonConfig.build_path, build_name) | ||
copy_build(build_path:) | ||
|
||
copy_build( | ||
build_name: VANILLA_BUILD_NAME, | ||
branch_name: "main", | ||
build_path: VANILLA_BUILD_PATH | ||
) | ||
commit_changes(commit_message: "Add #{build_name}") | ||
end | ||
|
||
def checkout_main | ||
Dir.chdir(ComparisonConfig.comparison_repo_root_path) do | ||
system("git checkout main") | ||
end | ||
end | ||
|
||
COMPARISON_BUILDS.each do |build_name| | ||
build_path = File.join(BUILD_PATH, build_name) | ||
keepers = [".git", "."] | ||
deletable_files = Dir.glob("{*,.*}").reject { |f| keepers.include?(f) } | ||
# clean out all the files from the previous build (except .git) | ||
def rm_rf_except_git_dir | ||
Dir.chdir(ComparisonConfig.comparison_repo_root_path) do | ||
keepers = [".git", "."] | ||
deletable_files = Dir.glob("{*,.*}").reject { |f| keepers.include?(f) } | ||
|
||
# clean out all the files from the previous build (except .git) | ||
FileUtils.rm_rf(deletable_files) | ||
FileUtils.rm_rf(deletable_files) | ||
end | ||
end | ||
|
||
copy_build( | ||
build_name:, | ||
branch_name: build_name, | ||
build_path: | ||
) | ||
def create_new_branch(branch_name:) | ||
Dir.chdir(ComparisonConfig.comparison_repo_root_path) do | ||
system("git checkout -b #{branch_name}") | ||
end | ||
end | ||
|
||
def commit_changes(commit_message:) | ||
Dir.chdir(ComparisonConfig.comparison_repo_root_path) do | ||
system("git add .") | ||
# skip pre-commit hooks because they're not relevant here | ||
system("git commit --quiet --no-verify -m '#{commit_message}'") | ||
end | ||
end | ||
|
||
# go back to main before we start the next build | ||
system("git checkout main") | ||
def copy_build(build_path:) | ||
system("rsync -qav --exclude='.git' --exclude='node_modules' --exclude='tmp' #{build_path}/ #{ComparisonConfig.comparison_repo_root_path}/") | ||
end | ||
end | ||
end | ||
|
||
main | ||
Main.main |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
#!/usr/bin/env ruby | ||
|
||
PROJECT_ROOT_PATH = File.absolute_path(File.join(__dir__, ".")) | ||
BUILD_PATH = File.join(PROJECT_ROOT_PATH, "tmp/builds") | ||
COMPARISONS_REPO_ROOT_PATH = File.join(PROJECT_ROOT_PATH, "tmp/rails-template-variants-comparison") | ||
ALL_BUILDS = Dir.children(BUILD_PATH) | ||
VANILLA_BUILD_NAME = ALL_BUILDS.find { |build_name| build_name.start_with?("vanilla_") } | ||
COMPARISON_BUILDS = ALL_BUILDS - [VANILLA_BUILD_NAME] | ||
require_relative "lib/comparison_config" | ||
require_relative "lib/terminal" | ||
|
||
def main | ||
Dir.chdir(COMPARISONS_REPO_ROOT_PATH) do | ||
COMPARISON_BUILDS.each do |build_name| | ||
puts build_name | ||
# add --dry-run to test | ||
system("gh pr create --title 'Compare #{build_name} against vanilla Rails' --body 'Compare #{build_name} against vanilla Rails' --base main --head #{build_name}") | ||
class Main | ||
class << self | ||
def main(dry_run:) | ||
Dir.chdir(ComparisonConfig.comparison_repo_root_path) do | ||
ComparisonConfig.comparison_builds.each do |build_name| | ||
Terminal.puts_header("Creating PR for #{build_name}") | ||
cmd = "gh pr create --title 'Compare #{build_name} against vanilla Rails' --body 'Compare #{build_name} against vanilla Rails' --base main --head #{build_name} #{dry_run ? "--dry-run" : ""}" | ||
system(cmd) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
main | ||
Main.main(dry_run: ARGV.include?("--dry-run")) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class ComparisonConfig | ||
PROJECT_ROOT_PATH = File.absolute_path(File.join(__dir__, "../..")) | ||
BUILD_PATH = File.join(PROJECT_ROOT_PATH, "tmp/builds") | ||
|
||
class << self | ||
def build_path | ||
BUILD_PATH | ||
end | ||
|
||
def comparison_repo_root_path | ||
File.join(PROJECT_ROOT_PATH, "tmp/rails-template-variants-comparison") | ||
end | ||
|
||
def vanilla_build_name | ||
all_builds.find { |build_name| build_name.start_with?("vanilla_") } | ||
end | ||
|
||
def vanilla_build_path | ||
File.join(BUILD_PATH, vanilla_build_name) | ||
end | ||
|
||
def comparison_builds | ||
all_builds - [vanilla_build_name] | ||
end | ||
|
||
def all_builds | ||
Dir.children(BUILD_PATH) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Terminal | ||
class << self | ||
def puts_header(title) | ||
puts <<~EO_HEADER | ||
#{title} | ||
#{"=" * title.length} | ||
EO_HEADER | ||
end | ||
end | ||
end |