Created
June 28, 2016 01:14
-
-
Save jakeonrails/aab3322719721e9c7b5c680546f767d1 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: | |
# $ ruby code-challenge.rb <github.com repo> | |
repo = ARGV[0] | |
# Clear previous challenge | |
puts "Removing previous directories" | |
`rm -rf coding-challenge-source` | |
`rm -rf coding-challenge` | |
# Clone the candidate's repo | |
puts "Cloning candidate's challenge repo" | |
`git clone #{repo} coding-challenge-source` | |
# Source the Ruby version of the candidate's Rails app | |
puts "Getting Ruby version" | |
ruby_version = `cat coding-challenge-source/Gemfile | egrep -o "^ruby ['\\"]([0-9.]+)['\\"]" | egrep -o "[0-9.]+"` | |
# Ensure that Ruby version is installed locally w/ RVM | |
puts "Installing Ruby version: #{ruby_version}" | |
`rvm install #{ruby_version}` | |
`gem install bundler` | |
# Install the gems for the candidate's Rails app | |
puts "Bundling source app" | |
rails_version = `cd coding-challenge-source && bundle` | |
# Source the Rails version the candidate has chosen | |
puts "Getting Rails version" | |
rails_version = `cd coding-challenge-source && rails -v`[/[0-9.]+/] | |
# Use that version of Rails to create a new, blank slate Rails application with | |
# defaults. The -T flag has been used to not install the default Rails test | |
# framework. This way the candidate's decision to use RSpec or the default | |
# framework is obvious. It is also made obvious, if the candidate has chosen | |
# RSpec, whether they are aware of and/or used the -T flag to avoid adding the | |
# unnecessary default test framework. | |
puts "Creating new Rails #{rails_version} app (rails _#{rails_version}_ new coding-challenge -T)" | |
`rails _#{rails_version}_ new coding-challenge -T` | |
# Commit the newly generated Rails app. Now we can do a diff between two commits | |
# to see all the code that the candidate contributed. | |
puts "Adding initial commit after 'rails new'" | |
`cd coding-challenge && git init . && git add . && git commit -m 'Initial commit'` | |
# Move the candidate's code into the project directory, recursively overwriting | |
# any files generated by the `rails new` command a few steps back. | |
puts "Copying files from candidate's challenge into new Rails app" | |
`cp -r coding-challenge-source/* coding-challenge` | |
# Add a commit to allow `git log` to show the difference between the default | |
# `rails new` output and the candidate's contribution. | |
username = repo[/github.com\/(.+)?\//, 1] | |
puts "Adding and committing candidate's code" | |
`cd coding-challenge && git add . && git commit -m '#{username} code submission'` | |
# Clean up the temporary folder created earlier. | |
puts "Removing temporary directory" | |
`rm -rf coding-challenge-source` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment