Skip to content

Commit

Permalink
resolves #349 fix git deployer, cleanup implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Sep 8, 2013
1 parent 266b4f8 commit 2d0fe63
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/awestruct/cli/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(site_config, deploy_config)
@site_config = site_config
@deploy_config = deploy_config
@deploy_config['type'] ||= (is_github? ? :github_pages : :rsync)
$LOG.info "Deploying to #{deploy_type}" if $LOG.info?
$LOG.info "Deploying to #{deploy_type}" if $LOG.info?
end

def deploy_type
Expand All @@ -31,7 +31,7 @@ def run()
end

deployer = deployer_class.new( site_config, deploy_config )
deployer.run(deploy_config)
deployer.run
end

private
Expand Down
23 changes: 16 additions & 7 deletions lib/awestruct/deploy/base_deploy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'awestruct/deployers'
require 'awestruct/compatibility'
Dir[ File.join( File.dirname(__FILE__), '..', 'scm' '*.rb' ) ].each do |f|
Dir[ File.join( File.dirname(__FILE__), '..', 'scm', '*.rb' ) ].each do |f|
begin
require f
rescue LoadError => e
Expand All @@ -18,17 +18,17 @@ def initialize(site_config, deploy_config)
# Add a single front slash at the end of output dir
@site_path = File.join( site_config.output_dir, '/' ).gsub(/^\w:\//, '/')
@gzip = deploy_config['gzip']
@source_dir = deploy_config['source_dir'] || site_config.dir
@ignore_uncommitted = deploy_config['uncommitted']
init_scm(deploy_config['scm'] || 'git')
end

def run(deploy_config)
if deploy_config['uncommitted'] == true
def run
if @ignore_uncommitted == true
compress_site
publish_site
else
scm = deploy_config['scm'] || 'git'
#require "awestruct/scm/#{scm}"
scm_class = Object.const_get('Awestruct').const_get('Scm').const_get(scm.slice(0, 1).capitalize + scm.slice(1..-1))
if scm_class.new.uncommitted_changes?(deploy_config['source_dir'])
if @scm.uncommitted_changes? @source_dir
existing_changes
else
compress_site
Expand Down Expand Up @@ -88,6 +88,15 @@ def is_gzipped(filename)
false
end
end

def init_scm type
begin
clazz = Object.const_get('Awestruct').const_get('Scm').const_get(type.capitalize)
@scm = clazz.new
rescue
$LOG.error( "Could not resolve class for scm type: #{type}" ) if $LOG.error?
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/awestruct/scm/git_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'awestruct/scm/git'
require 'awestruct/deploy/base_deploy'

describe Awestruct::Scm::Git do
specify 'should respond_to :uncommitted_changes?' do
Expand All @@ -26,4 +26,4 @@
expect(subject.uncommitted_changes? '.').to be_true
end
end
end
end
12 changes: 10 additions & 2 deletions spec/deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

require 'spec_helper'
require 'awestruct/cli/deploy'

describe Awestruct::CLI::Deploy do
Expand Down Expand Up @@ -44,11 +44,13 @@

deploy_config = mock
deploy_config.stub(:[]).with('gzip').and_return true
deploy_config.stub(:[]).with('source_dir').and_return '.'
deploy_config.stub(:[]).with('scm').and_return nil
deploy_config.stub(:[]).with('uncommitted').and_return true

deployer = Awestruct::Deploy::Base.new(site_config, deploy_config)
deployer.should_receive(:gzip_site)
deployer.run(deploy_config)
deployer.run
end

it "should only gzip html, css and js files" do
Expand All @@ -62,6 +64,9 @@

deploy_config = mock
deploy_config.stub(:[]).with('gzip').and_return true
deploy_config.stub(:[]).with('source_dir').and_return '.'
deploy_config.stub(:[]).with('scm').and_return nil
deploy_config.stub(:[]).with('uncommitted').and_return nil

deployer = Awestruct::Deploy::Base.new(site_config, deploy_config)
deployer.should_receive(:gzip_file).with("#{site_dir}/yes.html")
Expand All @@ -83,6 +88,9 @@

deploy_config = mock
deploy_config.stub(:[]).with('gzip').and_return true
deploy_config.stub(:[]).with('source_dir').and_return '.'
deploy_config.stub(:[]).with('scm').and_return nil
deploy_config.stub(:[]).with('uncommitted').and_return nil

deployer = Awestruct::Deploy::Base.new(site_config, deploy_config)
deployer.gzip_site(site_dir)
Expand Down
13 changes: 6 additions & 7 deletions spec/github_pages_deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'awestruct/scm/git'
require 'awestruct/deploy/github_pages_deploy'

describe Awestruct::Deploy::GitHubPagesDeploy do
Expand Down Expand Up @@ -29,35 +28,35 @@
it "should warn and noop if no changes have been committed" do
git_scm = mock()
git_scm.stub(:uncommitted_changes?).with('.').and_return true
::Awestruct::Scm::Git.stub(:new).and_return git_scm
@deployer.instance_variable_set('@scm', git_scm)
$LOG.should_receive(:error).with(Awestruct::Deploy::Base::UNCOMMITTED_CHANGES)
@deployer.run(@deploy_config)
@deployer.run
end

it "should save and restore the current branch when publishing" do
git_scm = mock()
git_scm.stub(:uncommitted_changes?).with('.').and_return false
::Awestruct::Scm::Git.stub(:new).and_return git_scm
@deployer.instance_variable_set('@scm', git_scm)
@git.should_receive(:current_branch).and_return( 'bacon' )
@git.stub_chain(:branch, :checkout)
@git.should_receive(:push).with('the-repo', 'the-branch')
@git.should_receive(:checkout).with( 'bacon' )

@deployer.stub(:add_and_commit_site)
@deployer.run(@deploy_config)
@deployer.run
end

it "should save and restore the current detached branch when publishing" do
git_scm = mock()
git_scm.stub(:uncommitted_changes?).with('.').and_return false
::Awestruct::Scm::Git.stub(:new).and_return git_scm
@deployer.instance_variable_set('@scm', git_scm)
@git.should_receive(:current_branch).and_return( '(no branch)' )
@git.should_receive(:revparse).with( 'HEAD' ).and_return( '0123456789' )
@git.stub_chain(:branch, :checkout)
@git.should_receive(:push).with('the-repo', 'the-branch')
@git.should_receive(:checkout).with( '0123456789' )

@deployer.stub(:add_and_commit_site)
@deployer.run(@deploy_config)
@deployer.run
end
end

0 comments on commit 2d0fe63

Please sign in to comment.