Skip to content

Logs commands executed and print Done when finished #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/docs_compressor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
require 'fileutils'
require 'shellwords'
require 'logging'
require 'running'

# Compresses HTML, JavaScript, and CSS under the given directory, recursively.
#
# We do this to leverage gzip_static in nginx.
class DocsCompressor
include Logging
include Running

EXTENSIONS = %w(.js .html .css)

Expand Down Expand Up @@ -40,7 +42,7 @@ def compress_file(file)
orig = Shellwords.shellescape(file)
dest = Shellwords.shellescape(gzname(file))

system %(gzip -c -9 #{orig} > #{dest})
log_and_system %(gzip -c -9 #{orig} > #{dest})
end

def compress_file?(file)
Expand Down
8 changes: 7 additions & 1 deletion lib/generators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ def env_as_assigns(env)
def run(command, env={})
command = "rvm #{ruby_version} do #{command} >/dev/null"
log "#{env_as_assigns(env)} #{command}"
system(env, command)

if system(env, command)
true
else
log "\"#{command}\" failed to execute"
abort
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be included in the Running module with env_as_assigns there too.

end

# Runs `bundle exec rake` with the appropriate Bundler and Ruby versions.
Expand Down
12 changes: 7 additions & 5 deletions lib/git_manager.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'logging'
require 'running'

# Lightweight wrapper over Git, shells out everything.
class GitManager
include Logging
include Running

attr_reader :basedir

Expand All @@ -18,7 +20,7 @@ def update_master
Dir.chdir(basedir) do
unless Dir.exist?('master')
log "cloning master into #{basedir}/master"
system "git clone -q #{remote_rails_url} master"
log_and_system "git clone -q #{remote_rails_url} master"
end

Dir.chdir('master') do
Expand All @@ -28,19 +30,19 @@ def update_master
# git pull from succeeding. Starting with Bundler 1.10, if Gemfile.lock
# does not change BUNDLED WITH is left as is, even if versions differ,
# but since docs generation is automated better play safe.
system 'git checkout Gemfile.lock'
system 'git pull -q'
log_and_system 'git checkout Gemfile.lock'
log_and_system 'git pull -q'
end
end
end

def checkout(tag)
Dir.chdir(basedir) do
log "checking out tag #{tag}"
system "git clone -q #{remote_rails_url} #{tag}"
log_and_system "git clone -q #{remote_rails_url} #{tag}"

Dir.chdir(tag) do
system "git checkout -q #{tag}"
log_and_system "git checkout -q #{tag}"
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/running.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Running
include Logging

def log_and_system(*args)
log(args.map(&:to_s).join(' '))
system(*args).tap { log "Done" }
end
end